Skip to content

Commit

Permalink
Update build process (#102)
Browse files Browse the repository at this point in the history
This updates the build process to use goreleaser for compiling the binaries and Docker containers, adding support for arm-based builds and Docker containers. It also bundles version information into the binary and log output for easier debugging.

Closes #96
Closes #52
  • Loading branch information
sethvargo authored Aug 23, 2022
1 parent a5b09b0 commit f4d96b8
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 274 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 'release'

on:
push:
tags:
- 'v*'

permissions:
contents: 'write'
packages: 'write'

jobs:
release:
runs-on: 'ubuntu-latest'
steps:
- uses: 'docker/setup-qemu-action@v2'

- uses: 'actions/checkout@v3'
with:
fetch-depth: 0

- uses: 'actions/setup-go@v3'
with:
go-version: '1.19'

- uses: 'docker/login-action@v2'
with:
registry: 'asia-docker.pkg.dev'
username: '_json_key'
password: '${{ secrets.GOOGLE_CREDENTIALS }}'

- uses: 'docker/login-action@v2'
with:
registry: 'europe-docker.pkg.dev'
username: '_json_key'
password: '${{ secrets.GOOGLE_CREDENTIALS }}'

- uses: 'docker/login-action@v2'
with:
registry: 'us-docker.pkg.dev'
username: '_json_key'
password: '${{ secrets.GOOGLE_CREDENTIALS }}'

- id: 'import_gpg'
uses: 'crazy-max/ghaction-import-gpg@v5'
with:
gpg_private_key: '${{ secrets.GPG_PRIVATE_KEY }}'
passphrase: '${{ secrets.GPG_PASSPHRASE }}'

- uses: 'goreleaser/goreleaser-action@v3'
with:
version: 'latest'
args: 'release --rm-dist'
env:
GPG_FINGERPRINT: '${{ steps.import_gpg.outputs.fingerprint }}'
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
21 changes: 8 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ name: 'test'
on:
push:
branches:
- 'main'
tags:
- '*'
- 'main'
pull_request:
branches:
- 'main'
- 'main'
workflow_dispatch:

concurrency:
group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
test:
runs-on: 'ubuntu-latest'
Expand All @@ -20,15 +22,8 @@ jobs:

- uses: 'actions/setup-go@v3'
with:
go-version: '1.18'
go-version: '1.19'

- uses: 'actions/cache@v3'
with:
path: |-
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |-
${{ runner.os }}-go-
- run: 'go mod download'

- run: 'make test'
253 changes: 253 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
before:
hooks:
- 'go mod tidy'

builds:
# cli
-
id: 'cli'
env:
- 'CGO_ENABLED=0'
- 'GO111MODULE=on'
- 'GOPROXY=https://proxy.golang.org,direct'
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- '-a'
- '-trimpath'
ldflags:
- '-s'
- '-w'
- '-X={{ .ModulePath }}/internal/version.Name=gcr-cleaner-cli'
- '-X={{ .ModulePath }}/internal/version.Version={{ .Version }}'
- '-X={{ .ModulePath }}/internal/version.Commit={{ .FullCommit }}'
- '-extldflags=-static'
main: './cmd/gcr-cleaner-cli/...'
goos:
- 'darwin'
- 'linux'
- 'windows'
goarch:
- 'amd64'
- 'arm64'

# server
-
id: 'server'
env:
- 'CGO_ENABLED=0'
- 'GO111MODULE=on'
- 'GOPROXY=https://proxy.golang.org,direct'
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- '-a'
- '-trimpath'
ldflags:
- '-s'
- '-w'
- '-X={{ .ModulePath }}/internal/version.Name=gcr-cleaner'
- '-X={{ .ModulePath }}/internal/version.Version={{ .Version }}'
- '-X={{ .ModulePath }}/internal/version.Commit={{ .FullCommit }}'
- '-extldflags=-static'
main: './cmd/gcr-cleaner-server/...'
goos:
- 'darwin'
- 'linux'
- 'windows'
goarch:
- 'amd64'
- 'arm64'

dockers:
# cli
-
use: 'buildx'
goos: 'linux'
goarch: 'amd64'
dockerfile: 'docker/cli.dockerfile'
ids:
- 'cli'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-amd64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-amd64'
build_flag_templates:
- '--platform=linux/amd64'
- '--pull'
- '--label=org.opencontainers.image.created={{ .CommitTimestamp }}'
- '--label=org.opencontainers.image.description=gcr-cleaner deletes untagged images in Docker container registries.'
- '--label=org.opencontainers.image.licenses=Apache-2.0'
- '--label=org.opencontainers.image.name=gcr-cleaner'
- '--label=org.opencontainers.image.revision={{ .FullCommit }}'
- '--label=org.opencontainers.image.source={{ .GitURL }}'
- '--label=org.opencontainers.image.title=gcr-cleaner'
- '--label=org.opencontainers.image.version={{ .Version }}'
-
use: 'buildx'
goos: 'linux'
goarch: 'arm64'
dockerfile: 'docker/cli.dockerfile'
ids:
- 'cli'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-arm64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-arm64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-arm64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-arm64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-arm64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-arm64'
build_flag_templates:
- '--platform=linux/arm64'
- '--pull'
- '--label=org.opencontainers.image.created={{ .CommitTimestamp }}'
- '--label=org.opencontainers.image.description=gcr-cleaner deletes untagged images in Docker container registries.'
- '--label=org.opencontainers.image.licenses=Apache-2.0'
- '--label=org.opencontainers.image.name=gcr-cleaner'
- '--label=org.opencontainers.image.revision={{ .FullCommit }}'
- '--label=org.opencontainers.image.source={{ .GitURL }}'
- '--label=org.opencontainers.image.title=gcr-cleaner'
- '--label=org.opencontainers.image.version={{ .Version }}'

# server
-
use: 'buildx'
goos: 'linux'
goarch: 'amd64'
dockerfile: 'docker/server.dockerfile'
ids:
- 'server'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-amd64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-amd64'
build_flag_templates:
- '--platform=linux/amd64'
- '--pull'
- '--label=org.opencontainers.image.created={{ .CommitTimestamp }}'
- '--label=org.opencontainers.image.description=gcr-cleaner deletes untagged images in Docker container registries.'
- '--label=org.opencontainers.image.licenses=Apache-2.0'
- '--label=org.opencontainers.image.name=gcr-cleaner'
- '--label=org.opencontainers.image.revision={{ .FullCommit }}'
- '--label=org.opencontainers.image.source={{ .GitURL }}'
- '--label=org.opencontainers.image.title=gcr-cleaner'
- '--label=org.opencontainers.image.version={{ .Version }}'
-
use: 'buildx'
goos: 'linux'
goarch: 'arm64'
dockerfile: 'docker/server.dockerfile'
ids:
- 'server'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-arm64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-arm64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-arm64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-arm64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-arm64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-arm64'
build_flag_templates:
- '--platform=linux/arm64'
- '--pull'
- '--label=org.opencontainers.image.created={{ .CommitTimestamp }}'
- '--label=org.opencontainers.image.description=gcr-cleaner deletes untagged images in Docker container registries.'
- '--label=org.opencontainers.image.licenses=Apache-2.0'
- '--label=org.opencontainers.image.name=gcr-cleaner'
- '--label=org.opencontainers.image.revision={{ .FullCommit }}'
- '--label=org.opencontainers.image.source={{ .GitURL }}'
- '--label=org.opencontainers.image.title=gcr-cleaner'
- '--label=org.opencontainers.image.version={{ .Version }}'

docker_manifests:
# cli
-
name_template: 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-amd64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-arm64'
-
name_template: 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-amd64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-arm64'
-
name_template: 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}'
image_templates:
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-arm64'
-
name_template: 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest'
image_templates:
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-arm64'
-
name_template: 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}'
image_templates:
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:{{ .Version }}-arm64'
-
name_template: 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest'
image_templates:
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest-arm64'

# server
-
name_template: 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-amd64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-arm64'
-
name_template: 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest'
image_templates:
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-amd64'
- 'asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-arm64'
-
name_template: 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}'
image_templates:
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-arm64'
-
name_template: 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest'
image_templates:
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-amd64'
- 'europe-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-arm64'
-
name_template: 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}'
image_templates:
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:{{ .Version }}-arm64'
-
name_template: 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest'
image_templates:
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-amd64'
- 'us-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner:latest-arm64'

archives:
- format: 'tar.gz'
name_template: 'gcr-cleaner_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
format_overrides:
- goos: 'windows'
format: 'zip'

checksum:
name_template: 'gcr-cleaner_{{ .Version }}_SHA512SUMS'
algorithm: 'sha512'

signs:
- artifacts: 'checksum'
args:
- '--batch'
- '--local-user'
- '{{ .Env.GPG_FINGERPRINT }}'
- '--output'
- '${signature}'
- '--detach-sign'
- '${artifact}'

release:
draft: false
45 changes: 0 additions & 45 deletions Dockerfile

This file was deleted.

Loading

0 comments on commit f4d96b8

Please sign in to comment.