Merge pull request #201 from cloudflare/3-stage-build

3 stage build
This commit is contained in:
Łukasz Mierzwa
2017-12-05 09:47:58 -08:00
committed by GitHub
3 changed files with 45 additions and 42 deletions

View File

@@ -20,6 +20,8 @@ jobs:
cache:
directories:
- node_modules
# install defaults to "npm install", which is done via make
install: []
script: make test-js
- stage: Lint Go code
@@ -33,6 +35,8 @@ jobs:
cache:
directories:
- node_modules
# install defaults to "npm install", which is done via make
install: []
script: make lint-js
- stage: Build Docker image

View File

@@ -1,11 +1,15 @@
FROM golang:1.9.2-alpine3.6 as unsee-builder
COPY . /go/src/github.com/cloudflare/unsee
FROM node:8-alpine as nodejs-builder
RUN apk add --update make git
COPY . /unsee
RUN make -C /unsee webpack
FROM golang:1.9.2-alpine3.6 as go-builder
COPY --from=nodejs-builder /unsee /go/src/github.com/cloudflare/unsee
ARG VERSION
RUN apk add --update make git nodejs nodejs-npm
RUN apk add --update make git
RUN CGO_ENABLED=0 make -C /go/src/github.com/cloudflare/unsee VERSION="${VERSION:-dev}" unsee
FROM gcr.io/distroless/base
COPY --from=unsee-builder /go/src/github.com/cloudflare/unsee/unsee /unsee
COPY --from=go-builder /go/src/github.com/cloudflare/unsee/unsee /unsee
EXPOSE 8080
CMD ["/unsee"]

View File

@@ -21,45 +21,60 @@ endif
.DEFAULT_GOAL := $(NAME)
.build/go-bindata:
.build/deps-build-go.ok:
@mkdir -p .build
go get -u github.com/golang/dep/cmd/dep
go get -u github.com/jteeuwen/go-bindata/...
touch $@
.build/go-bindata-assetfs:
@mkdir -p .build
go get -u github.com/elazarl/go-bindata-assetfs/...
touch $@
.build/golint:
.build/deps-lint-go.ok:
@mkdir -p .build
go get -u github.com/golang/lint/golint
touch $@
.build/npm.install: package.json package-lock.json
.build/deps-build-node.ok: package.json package-lock.json
@mkdir -p .build
npm install
touch $@
.build/deps.ok: .build/go-bindata .build/go-bindata-assetfs .build/golint .build/npm.install
.build/artifacts-bindata_assetfs.%:
@mkdir -p .build
rm -f .build/artifacts-bindata_assetfs.*
touch $@
.build/bindata_assetfs.%:
.build/artifacts-webpack.ok: .build/deps-build-node.ok $(ASSET_SOURCES) webpack.config.js
@mkdir -p .build
rm -f .build/bindata_assetfs.*
touch $@
bindata_assetfs.go: .build/deps.ok .build/bindata_assetfs.$(GO_BINDATA_MODE) $(ASSET_SOURCES) webpack.config.js .build/vendor.ok
$(CURDIR)/node_modules/.bin/webpack
touch $@
bindata_assetfs.go: .build/deps-build-go.ok .build/artifacts-bindata_assetfs.$(GO_BINDATA_MODE) .build/vendor.ok .build/artifacts-webpack.ok
go-bindata-assetfs $(GO_BINDATA_FLAGS) -prefix assets -nometadata assets/templates/... assets/static/dist/...
$(NAME): .build/deps.ok .build/vendor.ok bindata_assetfs.go $(SOURCES)
$(NAME): .build/deps-build-go.ok .build/vendor.ok bindata_assetfs.go $(SOURCES)
go build -ldflags "-X main.version=$(VERSION)"
.build/vendor.ok: .build/deps-build-go.ok Gopkg.lock Gopkg.toml
dep ensure
dep prune
touch $@
.PHONY: vendor
vendor: .build/deps-build-go.ok
dep ensure
dep prune
.PHONY: vendor-update
vendor-update: .build/deps-build-go.ok
dep ensure -update
dep prune
.PHONY: webpack
webpack: .build/artifacts-webpack.ok
.PHONY: clean
clean:
rm -fr .build $(NAME)
rm -fr .build bindata_assetfs.go $(NAME)
.PHONY: run
run: $(NAME)
@@ -91,11 +106,11 @@ run-docker: docker-image
$(NAME):$(VERSION)
.PHONY: lint-go
lint-go: .build/golint
lint-go: .build/deps-lint-go.ok
golint ./... | (egrep -v "^vendor/|^bindata_assetfs.go" || true)
.PHONY: lint-js
lint-js: .build/npm.install
lint-js: .build/deps-build-node.ok
$(CURDIR)/node_modules/.bin/eslint --quiet assets/static/*.js
.PHONY: lint
@@ -103,7 +118,7 @@ lint: lint-go lint-js
# Creates mock bindata_assetfs.go with source assets rather than webpack generated ones
.PHONY: mock-assets
mock-assets: .build/go-bindata .build/go-bindata-assetfs
mock-assets: .build/deps-build-go.ok
mkdir -p $(CURDIR)/assets/static/dist/templates
cp $(CURDIR)/assets/static/*.* $(CURDIR)/assets/static/dist/
touch $(CURDIR)/assets/static/dist/templates/loader_unsee.html
@@ -123,23 +138,3 @@ test-js:
.PHONY: test
test: lint test-go test-js
.build/dep.ok:
go get -u github.com/golang/dep/cmd/dep
@mkdir -p .build
touch $@
.build/vendor.ok: Gopkg.lock Gopkg.toml .build/dep.ok
dep ensure
dep prune
touch $@
.PHONY: vendor
vendor: .build/dep.ok
dep ensure
dep prune
.PHONY: vendor-update
vendor-update: .build/dep.ok
dep ensure -update
dep prune