Skip to content

Commit

Permalink
Remove docker multi stage build
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Rabot <[email protected]>
  • Loading branch information
sylr committed Jul 7, 2024
1 parent 7bec53a commit d9cebf7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 39 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
dist
.go-build-flags
.buildx-metadata.json
32 changes: 3 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
# vi: ft=Dockerfile:

ARG GO_VERSION=1.22

FROM --platform=$BUILDPLATFORM golang:$GO_VERSION AS builder

RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y build-essential git

WORKDIR $GOPATH/src/sylr.dev/yage

COPY go.mod go.sum ./

RUN go mod download

COPY . .
FROM scratch

ARG TARGETPLATFORM
ARG VERSION
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT

# Switch shell to bash
SHELL ["bash", "-c"]

# Run a git command otherwise git describe in the Makefile could report a dirty git dir
RUN git diff --exit-code || true

RUN make build GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT/v/} GO_BUILD_TARGET=dist/${TARGETPLATFORM}/yage

# -----------------------------------------------------------------------------

FROM scratch

ARG TARGETPLATFORM

WORKDIR /usr/local/bin

COPY --from=builder "/go/src/sylr.dev/yage/dist/$TARGETPLATFORM/yage" .
COPY dist/yage-${VERSION}-${TARGETOS}-${TARGETARCH}${TARGETVARIANT} yage

CMD ["/usr/local/bin/yage"]
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ GO_TOOLS_GOLANGCI_LINT ?= $(shell $(GO) env GOPATH)/bin/golangci-lint
DOCKER_BUILD_IMAGE ?= ghcr.io/sylr/yage
DOCKER_BUILD_VERSION ?= $(GIT_VERSION)
DOCKER_BUILD_GO_VERSION ?= 1.22
DOCKER_BUILD_LABELS = --label org.opencontainers.image.title=yage
DOCKER_BUILD_LABELS += --label org.opencontainers.image.description="age+yaml"
DOCKER_BUILD_LABELS += --label org.opencontainers.image.url="https://github.com/sylr/yage"
DOCKER_BUILD_LABELS += --label org.opencontainers.image.source="https://github.com/sylr/yage"
DOCKER_BUILD_LABELS += --label org.opencontainers.image.revision=$(GIT_REVISION)
DOCKER_BUILD_LABELS += --label org.opencontainers.image.version=$(GIT_VERSION)
DOCKER_BUILD_LABELS += --label org.opencontainers.image.created=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
DOCKER_BUILD_BUILD_ARGS ?= --build-arg=GO_VERSION=$(DOCKER_BUILD_GO_VERSION)
DOCKER_BUILD_LABELS = --annotation org.opencontainers.image.title=yage
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.description="age+yaml"
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.url="https://github.com/sylr/yage"
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.source="https://github.com/sylr/yage"
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.revision=$(GIT_REVISION)
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.version=$(GIT_VERSION)
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.created=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
DOCKER_BUILD_BUILD_ARGS := --build-arg=VERSION=$(GIT_VERSION)
DOCKER_BUILD_BUILD_ARGS += --metadata-file=.buildx-metadata.json
DOCKER_BUILDX_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6

Expand Down Expand Up @@ -249,7 +249,7 @@ docker-buildx-build:
$(DOCKER_BUILD_BUILD_ARGS) \
$(DOCKER_BUILD_LABELS)

docker-buildx-push:
docker-buildx-push: crossbuild
@docker buildx build . -f Dockerfile \
-t $(DOCKER_BUILD_IMAGE):$(DOCKER_BUILD_VERSION) \
--platform=$(DOCKER_BUILDX_PLATFORMS) \
Expand Down

0 comments on commit d9cebf7

Please sign in to comment.