tools: Use the Alpine base to build the go-compile image

Also, convert to use a git tree hash.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-05-30 12:50:45 +01:00
parent 7173529253
commit 0d718fed40
2 changed files with 23 additions and 43 deletions

View File

@ -1,10 +1,16 @@
FROM alpine:3.5 FROM linuxkit/alpine:451603daf499e3a40308dbf5571dcffed2343ffa AS mirror
RUN apk update && apk add --no-cache build-base git go RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
RUN apk add --no-cache --initdb -p /out \
alpine-baselayout \
busybox \
git \
go \
musl-dev
RUN rm -rf /out/etc/apk /out/lib/apk /out/var/cache
FROM scratch
ENV GOPATH=/go PATH=$PATH:/go/bin ENV GOPATH=/go PATH=$PATH:/go/bin
RUN go get -u github.com/golang/lint/golint && \ COPY --from=mirror /out/ /
go get -u github.com/gordonklaus/ineffassign && \ COPY --from=mirror /go/bin/ /go/bin/
go get -u github.com/LK4D4/vndr COPY /compile.sh /compile.sh
COPY . ./
ENTRYPOINT ["/compile.sh"] ENTRYPOINT ["/compile.sh"]

View File

@ -1,41 +1,15 @@
.PHONY: tag push .PHONY: tag push
BASE=alpine:3.5
IMAGE=go-compile
default: push default: push
hash: Dockerfile compile.sh ORG?=linuxkit
DOCKER_CONTENT_TRUST=1 docker pull $(BASE) IMAGE=go-compile
tar cf - $^ | docker build --no-cache -t $(IMAGE):build - DEPS=Dockerfile Makefile compile.sh
docker run --rm --entrypoint=/bin/sh $(IMAGE):build -c "cat $^ /lib/apk/db/installed /go/bin/golint | sha1sum" | sed 's/ .*//' > hash
push: hash HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}')
docker pull linuxkit/$(IMAGE):$(shell cat hash) || \
(docker tag $(IMAGE):build linuxkit/$(IMAGE):$(shell cat hash) && \
docker push linuxkit/$(IMAGE):$(shell cat hash))
docker rmi $(IMAGE):build
rm -f hash
tag: hash tag: $(DEPS)
docker pull linuxkit/$(IMAGE):$(shell cat hash) || \ docker build --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) .
docker tag $(IMAGE):build linuxkit/$(IMAGE):$(shell cat hash)
docker rmi $(IMAGE):build
rm -f hash
signed-tag: hash push: tag
DOCKER_CONTENT_TRUST=1 docker pull linuxkit/$(IMAGE):$(shell cat hash) || \ DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \
(DOCKER_CONTENT_TRUST=1 docker pull $(BASE) && \ DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH)
docker build --no-cache -t $(IMAGE):build . && \
docker tag $(IMAGE):build linuxkit/$(IMAGE):$(shell cat hash))
sign: signed-tag
DOCKER_CONTENT_TRUST=1 docker pull linuxkit/$(IMAGE):$(shell cat hash) || \
DOCKER_CONTENT_TRUST=1 docker push linuxkit/$(IMAGE):$(shell cat hash)
rm -f hash
docker rmi $(IMAGE):build || true
clean:
rm -f hash
.DELETE_ON_ERROR: