Skip to content

Commit d9cebf7

Browse files
committed
Remove docker multi stage build
Signed-off-by: Sylvain Rabot <[email protected]>
1 parent 7bec53a commit d9cebf7

File tree

3 files changed

+12
-39
lines changed

3 files changed

+12
-39
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
dist
21
.go-build-flags
32
.buildx-metadata.json

Dockerfile

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
11
# vi: ft=Dockerfile:
22

3-
ARG GO_VERSION=1.22
4-
5-
FROM --platform=$BUILDPLATFORM golang:$GO_VERSION AS builder
6-
7-
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y build-essential git
8-
9-
WORKDIR $GOPATH/src/sylr.dev/yage
10-
11-
COPY go.mod go.sum ./
12-
13-
RUN go mod download
14-
15-
COPY . .
3+
FROM scratch
164

17-
ARG TARGETPLATFORM
5+
ARG VERSION
186
ARG TARGETOS
197
ARG TARGETARCH
208
ARG TARGETVARIANT
219

22-
# Switch shell to bash
23-
SHELL ["bash", "-c"]
24-
25-
# Run a git command otherwise git describe in the Makefile could report a dirty git dir
26-
RUN git diff --exit-code || true
27-
28-
RUN make build GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT/v/} GO_BUILD_TARGET=dist/${TARGETPLATFORM}/yage
29-
30-
# -----------------------------------------------------------------------------
31-
32-
FROM scratch
33-
34-
ARG TARGETPLATFORM
35-
3610
WORKDIR /usr/local/bin
3711

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

4014
CMD ["/usr/local/bin/yage"]

Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ GO_TOOLS_GOLANGCI_LINT ?= $(shell $(GO) env GOPATH)/bin/golangci-lint
103103
DOCKER_BUILD_IMAGE ?= ghcr.io/sylr/yage
104104
DOCKER_BUILD_VERSION ?= $(GIT_VERSION)
105105
DOCKER_BUILD_GO_VERSION ?= 1.22
106-
DOCKER_BUILD_LABELS = --label org.opencontainers.image.title=yage
107-
DOCKER_BUILD_LABELS += --label org.opencontainers.image.description="age+yaml"
108-
DOCKER_BUILD_LABELS += --label org.opencontainers.image.url="https://github.com/sylr/yage"
109-
DOCKER_BUILD_LABELS += --label org.opencontainers.image.source="https://github.com/sylr/yage"
110-
DOCKER_BUILD_LABELS += --label org.opencontainers.image.revision=$(GIT_REVISION)
111-
DOCKER_BUILD_LABELS += --label org.opencontainers.image.version=$(GIT_VERSION)
112-
DOCKER_BUILD_LABELS += --label org.opencontainers.image.created=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
113-
DOCKER_BUILD_BUILD_ARGS ?= --build-arg=GO_VERSION=$(DOCKER_BUILD_GO_VERSION)
106+
DOCKER_BUILD_LABELS = --annotation org.opencontainers.image.title=yage
107+
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.description="age+yaml"
108+
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.url="https://github.com/sylr/yage"
109+
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.source="https://github.com/sylr/yage"
110+
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.revision=$(GIT_REVISION)
111+
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.version=$(GIT_VERSION)
112+
DOCKER_BUILD_LABELS += --annotation org.opencontainers.image.created=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
113+
DOCKER_BUILD_BUILD_ARGS := --build-arg=VERSION=$(GIT_VERSION)
114114
DOCKER_BUILD_BUILD_ARGS += --metadata-file=.buildx-metadata.json
115115
DOCKER_BUILDX_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
116116

@@ -249,7 +249,7 @@ docker-buildx-build:
249249
$(DOCKER_BUILD_BUILD_ARGS) \
250250
$(DOCKER_BUILD_LABELS)
251251

252-
docker-buildx-push:
252+
docker-buildx-push: crossbuild
253253
@docker buildx build . -f Dockerfile \
254254
-t $(DOCKER_BUILD_IMAGE):$(DOCKER_BUILD_VERSION) \
255255
--platform=$(DOCKER_BUILDX_PLATFORMS) \

0 commit comments

Comments
 (0)