From fad3fe18cba0761d0e5962f8d41881de6b3eb1b4 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Fri, 23 Oct 2020 00:23:25 -0700 Subject: [PATCH] Use multi-stage Dockerfile for image build * Go build the Matchbox binary in the container image in a docker.io/golang builder stage rather building the binary separately --- .dockerignore | 9 +++++++-- Dockerfile | 6 +++++- Makefile | 17 ++++++++--------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.dockerignore b/.dockerignore index 31f721ba..39e52ccb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,7 @@ -* -!bin/matchbox +bin/ +contrib/ +docs/ +examples/ +scripts/ +_output/ + diff --git a/Dockerfile b/Dockerfile index 9e5abe8d..cd12f21a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ +FROM docker.io/golang:1.14.9 AS builder +COPY . src +RUN cd src && make build + FROM docker.io/alpine:3.12 LABEL maintainer="Dalton Hubble " -COPY bin/matchbox /matchbox +COPY --from=builder /go/src/bin/matchbox /matchbox EXPOSE 8080 ENTRYPOINT ["/matchbox"] diff --git a/Makefile b/Makefile index b9305541..00c7f588 100644 --- a/Makefile +++ b/Makefile @@ -36,16 +36,15 @@ fmt: @test -z $$(go fmt ./...) .PHONY: image -image: - @buildah bud -t $(LOCAL_REPO):$(VERSION) . - @buildah tag $(LOCAL_REPO):$(VERSION) $(LOCAL_REPO):latest +image: \ + image-amd64 \ + image-arm64 -.PHONY: push -push: - @buildah tag $(LOCAL_REPO):$(VERSION) $(IMAGE_REPO):$(VERSION) - @buildah tag $(LOCAL_REPO):$(VERSION) $(IMAGE_REPO):latest - @buildah push docker://$(IMAGE_REPO):$(VERSION) - @buildah push docker://$(IMAGE_REPO):latest +image-%: + buildah bud -f Dockerfile \ + -t $(LOCAL_REPO):$(VERSION)-$* \ + --arch $* --override-arch $* \ + --format=docker . .PHONY: update update: