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
This commit is contained in:
Dalton Hubble
2020-10-23 00:23:25 -07:00
parent e0ba049931
commit fad3fe18cb
3 changed files with 20 additions and 12 deletions

View File

@@ -1,2 +1,7 @@
*
!bin/matchbox
bin/
contrib/
docs/
examples/
scripts/
_output/

View File

@@ -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 <dghubble@gmail.com>"
COPY bin/matchbox /matchbox
COPY --from=builder /go/src/bin/matchbox /matchbox
EXPOSE 8080
ENTRYPOINT ["/matchbox"]

View File

@@ -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: