Skip to content

Commit

Permalink
Correct Makefile docker targets
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelattwood committed Jan 6, 2025
1 parent 6b2fb73 commit c73ef23
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
10 changes: 6 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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}}'
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
60 changes: 33 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cicd/Dockerfile_goreleaser
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ EOT
FROM build

ARG CI
ARG PUSH
ARG GITHUB_TOKEN
ARG TAGS
ARG VERSION

COPY --from=src . /go/src

Expand All @@ -22,7 +25,8 @@ RUN <<EOT
cd /go/src
FLAGS="--clean"
if [ -z ${GITHUB_TOKEN} ]; then
if [ ${CI} != "true" ]; then FLAGS="${FLAGS} --skip-validate --single-target"; fi
if [ ${CI} != "true" ]; then FLAGS="${FLAGS} --skip=validate"; fi
if [ ${PUSH} != "true" ]; then FLAGS="${FLAGS} --single-target"; fi
goreleaser build ${FLAGS}
else
goreleaser release ${FLAGS}
Expand Down
9 changes: 7 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ variable CI {
default = false
}

variable PUSH {
default = false
}

###################
### Functions
###################
Expand All @@ -26,12 +30,12 @@ function "get_tags" {

function "get_platforms_multiarch" {
params = []
result = CI ? ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64"] : []
result = (CI || PUSH) ? ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64"] : []
}

function "get_output" {
params = []
result = CI ? ["type=registry"] : ["type=docker"]
result = (CI || PUSH) ? ["type=registry"] : ["type=docker"]
}

###################
Expand All @@ -56,6 +60,7 @@ target "goreleaser" {
}
args = {
CI = CI
PUSH = PUSH
GITHUB_TOKEN = ""
}
dockerfile = "cicd/Dockerfile_goreleaser"
Expand Down

0 comments on commit c73ef23

Please sign in to comment.