Skip to content

Commit

Permalink
fix(#28): publish db migration binary and image for use in K8s Job
Browse files Browse the repository at this point in the history
  • Loading branch information
saylerb committed Apr 22, 2024
1 parent 1d6e336 commit dc1cd32
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 42 deletions.
125 changes: 92 additions & 33 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
13 changes: 4 additions & 9 deletions Dockerfile.migrate
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit dc1cd32

Please sign in to comment.