diff --git a/.dockerignore b/.dockerignore index 47a21f2..2f3b16c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,2 @@ -dist .go-build-flags .buildx-metadata.json diff --git a/Dockerfile b/Dockerfile index 15a3490..378a9b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index a194736..a91d1df 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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) \