From c73ef231551c44f5e5492d7a0dd43caa8f4f5402 Mon Sep 17 00:00:00 2001 From: Samuel Attwood Date: Mon, 6 Jan 2025 10:58:13 -0500 Subject: [PATCH] Correct Makefile docker targets --- .goreleaser.yml | 10 ++++--- Makefile | 60 +++++++++++++++++++++----------------- cicd/Dockerfile_goreleaser | 6 +++- docker-bake.hcl | 9 ++++-- 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 331a3ade..78198075 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,7 @@ ---- +version: 2 project_name: nack +env: + - VERSION={{ if index .Env "VERSION" }}{{ .Env.VERSION }}{{ else }}{{ .Version }}{{ end }} release: name_template: 'Release {{.Tag}}' @@ -14,7 +16,7 @@ builds: main: ./cmd/jetstream-controller binary: jetstream-controller ldflags: - - -s -w -X main.Version={{.Version}} -X main.GitInfo={{.ShortCommit}} -X main.BuildTime={{.Date}} + - -s -w -X main.Version={{ .Env.VERSION }} -X main.GitInfo={{.ShortCommit}} -X main.BuildTime={{.Date}} tags: - timetzdata env: @@ -33,7 +35,7 @@ builds: main: ./cmd/nats-boot-config binary: nats-boot-config ldflags: - - -s -w -X main.Version={{.Version}} -X main.GitInfo={{.ShortCommit}} -X main.BuildTime={{.Date}} + - -s -w -X main.Version={{ .Env.VERSION }} -X main.GitInfo={{.ShortCommit}} -X main.BuildTime={{.Date}} tags: - timetzdata env: @@ -52,7 +54,7 @@ builds: main: ./cmd/nats-server-config-reloader binary: nats-server-config-reloader ldflags: - - -s -w -X main.Version={{.Version}} -X main.GitInfo={{.ShortCommit}} -X main.BuildTime={{.Date}} + - -s -w -X main.Version={{ .Env.VERSION }} -X main.GitInfo={{.ShortCommit}} -X main.BuildTime={{.Date}} tags: - timetzdata env: diff --git a/Makefile b/Makefile index aceda292..b9b25047 100644 --- a/Makefile +++ b/Makefile @@ -56,9 +56,11 @@ jetstream-controller.docker: $(jetstreamSrc) .PHONY: jetstream-controller-docker jetstream-controller-docker: ifneq ($(ver),) - docker build --tag $(drepo)/jetstream-controller:$(ver) \ - --build-arg VERSION=$(ver) \ - --file docker/jetstream-controller/Dockerfile . + REGISTRY="$(drepo)" \ + TAGS="$(ver)" \ + docker buildx bake --load \ + --set goreleaser.args.VERSION=$(ver) \ + jetstream-controller else # Missing version, try this. # make jetstream-controller-docker ver=1.2.3 @@ -69,12 +71,12 @@ endif jetstream-controller-dockerx: ifneq ($(ver),) # Ensure 'docker buildx ls' shows correct platforms. - docker buildx build \ - --tag $(drepo)/jetstream-controller:$(ver) --tag $(drepo)/jetstream-controller:latest \ - --build-arg VERSION=$(ver) \ - --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \ - --file docker/jetstream-controller/Dockerfile \ - --push . + REGISTRY="$(drepo)" \ + TAGS="$(ver)" \ + PUSH=true \ + docker buildx bake --push \ + --set goreleaser.args.VERSION=$(ver) \ + jetstream-controller else # Missing version, try this. # make jetstream-controller-dockerx ver=1.2.3 @@ -95,9 +97,11 @@ nats-server-config-reloader.docker: $(configReloaderSrc) .PHONY: nats-server-config-reloader-docker nats-server-config-reloader-docker: ifneq ($(ver),) - docker build --tag $(drepo)/nats-server-config-reloader:$(ver) \ - --build-arg VERSION=$(ver) \ - --file docker/nats-server-config-reloader/Dockerfile . + REGISTRY="$(drepo)" \ + TAGS="$(ver)" \ + docker buildx bake --load \ + --set goreleaser.args.VERSION=$(ver) \ + nats-server-config-reloader else # Missing version, try this. # make nats-server-config-reloader-docker ver=1.2.3 @@ -108,12 +112,12 @@ endif nats-server-config-reloader-dockerx: ifneq ($(ver),) # Ensure 'docker buildx ls' shows correct platforms. - docker buildx build \ - --tag $(drepo)/nats-server-config-reloader:$(ver) --tag $(drepo)/nats-server-config-reloader:latest \ - --build-arg VERSION=$(ver) \ - --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \ - --file docker/nats-server-config-reloader/Dockerfile \ - --push . + REGISTRY="$(drepo)" \ + TAGS="$(ver)" \ + PUSH=true \ + docker buildx bake --push \ + --set goreleaser.args.VERSION=$(ver) \ + nats-server-config-reloader else # Missing version, try this. # make nats-server-config-reloader-dockerx ver=1.2.3 @@ -134,9 +138,11 @@ nats-boot-config.docker: $(bootConfigSrc) .PHONY: nats-boot-config-docker nats-boot-config-docker: ifneq ($(ver),) - docker build --tag $(drepo)/nats-boot-config:$(ver) \ - --build-arg VERSION=$(ver) \ - --file docker/nats-boot-config/Dockerfile . + REGISTRY="$(drepo)" \ + TAGS="$(ver)" \ + docker buildx bake --load \ + --set goreleaser.args.VERSION=$(ver) \ + nats-boot-config else # Missing version, try this. # make nats-boot-config-docker ver=1.2.3 @@ -147,12 +153,12 @@ endif nats-boot-config-dockerx: ifneq ($(ver),) # Ensure 'docker buildx ls' shows correct platforms. - docker buildx build \ - --tag $(drepo)/nats-boot-config:$(ver) --tag $(drepo)/nats-boot-config:latest \ - --build-arg VERSION=$(ver) \ - --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \ - --file docker/nats-boot-config/Dockerfile \ - --push . + REGISTRY="$(drepo)" \ + TAGS="$(ver)" \ + PUSH=true \ + docker buildx bake --push \ + --set goreleaser.args.VERSION=$(ver) \ + nats-boot-config else # Missing version, try this. # make nats-boot-config-dockerx ver=1.2.3 diff --git a/cicd/Dockerfile_goreleaser b/cicd/Dockerfile_goreleaser index 903ef295..91a01674 100644 --- a/cicd/Dockerfile_goreleaser +++ b/cicd/Dockerfile_goreleaser @@ -13,7 +13,10 @@ EOT FROM build ARG CI +ARG PUSH ARG GITHUB_TOKEN +ARG TAGS +ARG VERSION COPY --from=src . /go/src @@ -22,7 +25,8 @@ RUN <