From dc1cd32b5f30f283e9234583aa777ab132857325 Mon Sep 17 00:00:00 2001 From: Brian Sayler Date: Mon, 22 Apr 2024 15:29:26 -0600 Subject: [PATCH] fix(#28): publish db migration binary and image for use in K8s Job --- .goreleaser.yaml | 125 +++++++++++++++++++++++++++++++++------------ Dockerfile.migrate | 13 ++--- 2 files changed, 96 insertions(+), 42 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 6048f27..3242754 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,42 +10,93 @@ builds: - arm64 goarm: - "8" + binary: lab-api-teams main: ./cmd/lab-api-teams + - env: [ CGO_ENABLED=0 ] + id: lab-api-teams-migrate + goos: + - linux + goarch: + - amd64 + - arm64 + goarm: + - "8" + binary: migrate + main: ./cmd/migrate dockers: -- goos: linux - goarch: amd64 - use: buildx - dockerfile: Dockerfile - image_templates: - - "docker.io/twdps/{{ .ProjectName }}:{{ .Version }}-linux-amd64" - - "docker.io/twdps/{{ .ProjectName }}:latest-linux-amd64" - build_flag_templates: - - --platform=linux/amd64 - - --label=org.opencontainers.image.title={{ .ProjectName }} - - --label=org.opencontainers.image.description={{ .ProjectName }} - - --label=org.opencontainers.image.url=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} - - --label=org.opencontainers.image.source=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} - - --label=org.opencontainers.image.version={{ .Version }} - - --label=org.opencontainers.image.revision={{ .FullCommit }} - - --label=org.opencontainers.image.licenses=MIT - -- goos: linux - goarch: arm64 - use: buildx - dockerfile: Dockerfile - image_templates: - - "docker.io/twdps/{{ .ProjectName }}:{{ .Version }}-linux-arm64" - - "docker.io/twdps/{{ .ProjectName }}:latest-linux-arm64" - build_flag_templates: - - --platform=linux/arm64/v8 - - --label=org.opencontainers.image.title={{ .ProjectName }} - - --label=org.opencontainers.image.description={{ .ProjectName }} - - --label=org.opencontainers.image.url=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} - - --label=org.opencontainers.image.source=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} - - --label=org.opencontainers.image.version={{ .Version }} - - --label=org.opencontainers.image.revision={{ .FullCommit }} - - --label=org.opencontainers.image.licenses=MIT + - goos: linux + goarch: amd64 + use: buildx + dockerfile: Dockerfile + ids: + - lab-api-teams + image_templates: + - "docker.io/twdps/{{ .ProjectName }}:{{ .Version }}-linux-amd64" + - "docker.io/twdps/{{ .ProjectName }}:latest-linux-amd64" + build_flag_templates: + - --platform=linux/amd64 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=MIT + - goos: linux + goarch: arm64 + use: buildx + dockerfile: Dockerfile + ids: + - lab-api-teams + image_templates: + - "docker.io/twdps/{{ .ProjectName }}:{{ .Version }}-linux-arm64" + - "docker.io/twdps/{{ .ProjectName }}:latest-linux-arm64" + build_flag_templates: + - --platform=linux/arm64/v8 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=MIT + - goos: linux + goarch: arm64 + use: buildx + dockerfile: Dockerfile.migrate + ids: + - lab-api-teams-migrate + image_templates: + - "docker.io/twdps/{{ .ProjectName }}-migrate:{{ .Version }}-linux-arm64" + - "docker.io/twdps/{{ .ProjectName }}-migrate:latest-linux-arm64" + build_flag_templates: + - --platform=linux/arm64/v8 + - --label=org.opencontainers.image.title={{ .ProjectName }}-migrate + - --label=org.opencontainers.image.description={{ .ProjectName }}-migrate + - --label=org.opencontainers.image.url=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=MIT + - goos: linux + goarch: amd64 + use: buildx + dockerfile: Dockerfile.migrate + ids: + - lab-api-teams-migrate + image_templates: + - "docker.io/twdps/{{ .ProjectName }}-migrate:{{ .Version }}-linux-amd64" + - "docker.io/twdps/{{ .ProjectName }}-migrate:latest-linux-amd64" + build_flag_templates: + - --platform=linux/amd64 + - --label=org.opencontainers.image.title={{ .ProjectName }}-migrate + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/ThoughtWorks-DPS/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=MIT docker_manifests: - name_template: docker.io/twdps/{{ .ProjectName }}:v{{ .Version }} @@ -56,6 +107,14 @@ docker_manifests: image_templates: - docker.io/twdps/{{ .ProjectName }}:latest-linux-amd64 - docker.io/twdps/{{ .ProjectName }}:latest-linux-arm64 + - name_template: docker.io/twdps/{{ .ProjectName }}-migrate:v{{ .Version }} + image_templates: + - docker.io/twdps/{{ .ProjectName }}-migrate:{{ .Version }}-linux-amd64 + - docker.io/twdps/{{ .ProjectName }}-migrate:{{ .Version }}-linux-arm64 + - name_template: docker.io/twdps/{{ .ProjectName }}-migrate:latest + image_templates: + - docker.io/twdps/{{ .ProjectName }}-migrate:latest-linux-amd64 + - docker.io/twdps/{{ .ProjectName }}-migrate:latest-linux-arm64 docker_signs: - cmd: cosign diff --git a/Dockerfile.migrate b/Dockerfile.migrate index b4f081d..8bc62dc 100644 --- a/Dockerfile.migrate +++ b/Dockerfile.migrate @@ -1,11 +1,6 @@ -FROM golang:1.20 as builder -WORKDIR /app -COPY go.mod go.sum ./ -RUN go mod download -COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o /migrate ./cmd/migrate - -FROM gcr.io/distroless/base +FROM gcr.io/distroless/static:nonroot WORKDIR / -COPY --from=builder /migrate . +COPY ./migrate ./migrate +USER 65532:65532 + CMD ["./migrate"] \ No newline at end of file