diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2018-02-17 19:24:10 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2018-02-18 23:02:48 -0500 |
| commit | e2fe8b4bd3b4027381c95b59efc9ef2146598097 (patch) | |
| tree | 040f1432247ecf6be933e4d78633eedcf93a1a53 | |
| parent | 2e4e1009e421f2a697fdef569ec2612522cc354f (diff) | |
Various updates to build scripts
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
| -rw-r--r-- | .dockerignore | 4 | ||||
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Dockerfile | 34 | ||||
| -rw-r--r-- | Makefile | 28 | ||||
| -rwxr-xr-x | hooks/build | 3 | ||||
| -rwxr-xr-x | hooks/post_push | 3 |
6 files changed, 48 insertions, 26 deletions
diff --git a/.dockerignore b/.dockerignore index ecd90a63..f745bfb4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,6 @@ Dockerfile .vscode *.md -bin/
\ No newline at end of file +bin/ +*.cid +*.iid @@ -2,3 +2,5 @@ bin report.xml gomplate +*.cid +*.iid @@ -1,36 +1,36 @@ FROM golang:1.10-alpine AS build +RUN apk add --no-cache \ + make \ + git \ + upx + RUN mkdir -p /go/src/github.com/hairyhenderson/gomplate WORKDIR /go/src/github.com/hairyhenderson/gomplate COPY . /go/src/github.com/hairyhenderson/gomplate -RUN apk add --no-cache \ - make \ - git - -RUN make build +RUN make build-x compress-all -FROM debian:jessie AS compress +FROM scratch AS artifacts -RUN apt-get update -qq -RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -yq curl xz-utils ca-certificates -RUN curl -fsSL -o /tmp/upx.tar.xz https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz \ - && tar Jxv -C /tmp --strip-components=1 -f /tmp/upx.tar.xz +COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=build /go/src/github.com/hairyhenderson/gomplate/bin/* /bin/ -COPY --from=build /go/src/github.com/hairyhenderson/gomplate/bin/gomplate /gomplate -RUN /tmp/upx --lzma /gomplate -o /gomplate-slim +CMD [ "/bin/gomplate_linux-amd64" ] FROM scratch AS gomplate ARG BUILD_DATE ARG VCS_REF +ARG OS=linux +ARG ARCH=amd64 LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.vcs-ref=$VCS_REF \ org.label-schema.vcs-url="https://github.com/hairyhenderson/gomplate" -COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -COPY --from=build /go/src/github.com/hairyhenderson/gomplate/bin/gomplate /gomplate +COPY --from=artifacts /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=artifacts /gomplate_${OS}-${ARCH} /gomplate ENTRYPOINT [ "/gomplate" ] @@ -40,13 +40,15 @@ FROM scratch AS gomplate-slim ARG BUILD_DATE ARG VCS_REF +ARG OS=linux +ARG ARCH=amd64 LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.vcs-ref=$VCS_REF \ org.label-schema.vcs-url="https://github.com/hairyhenderson/gomplate" -COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -COPY --from=compress /gomplate-slim /gomplate +COPY --from=artifacts /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=artifacts /gomplate_${OS}-${ARCH}-slim /gomplate ENTRYPOINT [ "/gomplate" ] @@ -6,6 +6,7 @@ PREFIX := . COMMIT ?= `git rev-parse --short HEAD 2>/dev/null` VERSION ?= `git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1) 2>/dev/null | sed 's/v\(.*\)/\1/'` +BUILD_DATE ?= `date -u +"%Y-%m-%dT%H:%M:%SZ"` COMMIT_FLAG := -X `go list ./version`.GitCommit=$(COMMIT) VERSION_FLAG := -X `go list ./version`.Version=$(VERSION) @@ -16,16 +17,9 @@ GOARCH ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/') platforms := linux-amd64 linux-386 linux-arm linux-arm64 darwin-amd64 solaris-amd64 windows-amd64.exe windows-386.exe compressed-platforms := linux-amd64-slim linux-arm-slim linux-arm64-slim darwin-amd64-slim windows-amd64-slim.exe -define gocross-tool - GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 \ - $(GO) build \ - -ldflags "-w -s $(COMMIT_FLAG) $(VERSION_FLAG)" \ - -o $(PREFIX)/bin/$(3)_$(1)-$(2)$(call extension,$(1)) \ - $(PREFIX)/test/integration/$(3)svc; -endef - clean: rm -Rf $(PREFIX)/bin/* + rm -f $(PREFIX)/*.[ci]id rm -f $(PREFIX)/test/integration/gomplate rm -f $(PREFIX)/test/integration/mirror rm -f $(PREFIX)/test/integration/meta @@ -44,6 +38,22 @@ $(PREFIX)/bin/$(PKG_NAME)_%-slim.exe: $(PREFIX)/bin/$(PKG_NAME)_%.exe compress: $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)-slim$(call extension,$(GOOS)) cp $< $(PREFIX)/bin/$(PKG_NAME)-slim$(call extension,$(GOOS)) +%.iid: Dockerfile + @docker build \ + --build-arg BUILD_DATE=$(BUILD_DATE) \ + --build-arg VCS_REF=$(COMMIT) \ + --target $(subst .iid,,$@) \ + --iidfile $@ \ + . + +%.cid: %.iid + @docker create $(shell cat $<) > $@ + +build-release: artifacts.cid + @docker cp $(shell cat $<):/bin/. bin/ + +docker-images: gomplate.iid gomplate-slim.iid + $(PREFIX)/bin/$(PKG_NAME)_%: $(shell find $(PREFIX) -type f -name '*.go' -not -path "$(PREFIX)/test/*") GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- | cut -f1 -d.) CGO_ENABLED=0 \ $(GO) build \ @@ -112,6 +122,6 @@ lint: gometalinter -j $(shell nproc) --vendor --deadline 120s --disable gotype --enable gofmt --enable goimports --enable misspell --enable unused --disable gas endif -.PHONY: gen-changelog clean test build-x compress-all build-release build build-integration-image test-integration-docker gen-docs lint +.PHONY: gen-changelog clean test build-x compress-all build-release build build-integration-image test-integration-docker gen-docs lint clean-images clean-containers docker-images .DELETE_ON_ERROR: .SECONDARY: diff --git a/hooks/build b/hooks/build index 092deb3e..a01a27ff 100755 --- a/hooks/build +++ b/hooks/build @@ -10,6 +10,9 @@ export DOCKER_REPO=${DOCKER_REPO:-hairyhenderson/gomplate} export DOCKER_TAG=${DOCKER_TAG:-latest} export IMAGE_NAME=${IMAGE_NAME:-${DOCKER_REPO}:${DOCKER_TAG}} +docker build --target artifacts \ + -t ${DOCKER_REPO}:artifacts . + echo "======== Building $IMAGE_NAME" docker build --build-arg BUILD_DATE \ --build-arg VCS_REF \ diff --git a/hooks/post_push b/hooks/post_push index b140375d..2a0457b7 100755 --- a/hooks/post_push +++ b/hooks/post_push @@ -4,6 +4,9 @@ set -exuo pipefail export DOCKER_REPO=${DOCKER_REPO:-hairyhenderson/gomplate} export DOCKER_TAG=${DOCKER_TAG:-latest} export IMAGE_NAME=${IMAGE_NAME:-${DOCKER_REPO}:${DOCKER_TAG}} + +docker push ${DOCKER_REPO}:artifacts + if [ "$DOCKER_TAG" == "latest" ]; then export SLIM_TAG="slim" else |
