From 3e6343daa907a2c620446378dd2d3547232af555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 4 Dec 2017 22:02:07 -0800 Subject: [PATCH 1/3] Cleanup make targets a bit Reduce number of targets used internally for building and use less confusing names. Add webpack target that will be needed for node only docker build stage. --- Makefile | 71 ++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index e200ff7c7..2dbab70e8 100644 --- a/Makefile +++ b/Makefile @@ -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 From ffa0caf6ebbe492a3d4593d2292ba46d2a95f454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 4 Dec 2017 22:03:11 -0800 Subject: [PATCH 2/3] Split build into NodeJS and Go parts Go docker image uses old nodejs, split build into 2 stages so we can have better control over used nodejs and Go images --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d893fa5e1..679402480 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] From e11dde89c584a60e63aa18d7a0db95978b87c74f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 4 Dec 2017 22:14:32 -0800 Subject: [PATCH 3/3] Disable default install targets for Travis, this adds 2x ~17s since travis runs npm install and then we run it too --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index d56b63b07..70833d056 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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