Skip to content

Commit

Permalink
feat: goreleaser release
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <[email protected]>
Co-authored-by: Furkan Türkal <[email protected]>
  • Loading branch information
developer-guy and Dentrax committed Dec 4, 2021
1 parent 2b44b36 commit 2149704
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 46 deletions.
70 changes: 26 additions & 44 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,47 @@ on:
tags:
- '*'

permissions:
contents: write
id-token: write
packages: write

jobs:
# use goreleaser to cross-compile go binaries and add them to GitHub release
goreleaser:
runs-on: ubuntu-latest
permissions:
contents: write
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@5a54d7e660bda43b405e8463261b3d25631ffe86 #v2.7.0
- uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 # pin@v1
- uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # pin@v1
- uses: sigstore/cosign-installer@e5c096a9feb091d8afe0168547370270986f2f71 # [email protected]
- name: dockerhub-login
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 # pin@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: ghcr-login
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 # pin@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@5df302e5e9e4c66310a6b6493a8865b12c555af2 # pin@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# build and publish docker image
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 #v1.10.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8b842e721d38d18bea23b57f4c040e53331f4ca2 #v3.4.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@1bc1040caef9e604eb543693ba89b5bf4fc80935 #v2.6.1
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
76 changes: 74 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,88 @@
before:
hooks:
- go mod tidy

env:
- GO111MODULE=on
- CGO_ENABLED=0

#gomod:
# proxy: true

builds:
- env:
- CGO_ENABLED=0
- binary: addlicense
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
#signs:
# - cmd: cosign
# env:
# - COSIGN_EXPERIMENTAL=1
# certificate: '{{ trimsuffix .Env.artifact ".txt" }}.pem'
# args:
# - sign-blob
# - '--oidc-issuer=https://token.actions.githubusercontent.com'
# - '--output-certificate=${certificate}'
# - '--output-signature=${signature}'
# - '${artifact}'
#docker_signs:
# - cmd: cosign
# env:
# - COSIGN_EXPERIMENTAL=1
# artifacts: manifests
# args:
# - 'sign'
# - '--oidc-issuer=https://token.actions.githubusercontent.com'
# - '${artifact}'
dockers:
- image_templates:
- 'google/addlicense:{{ .Tag }}-amd64'
- 'ghcr.io/google/addlicense:{{ .Tag }}-amd64'
dockerfile: Dockerfile.goreleaser
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/amd64"
- image_templates:
- 'google/addlicense:{{ .Tag }}-arm64'
- 'ghcr.io/google/addlicense:{{ .Tag }}-arm64'
dockerfile: Dockerfile.goreleaser
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
goarch: arm64
docker_manifests:
- name_template: 'google/addlicense:{{ .Tag }}'
image_templates:
- 'google/addlicense:{{ .Tag }}-amd64'
- 'google/addlicense:{{ .Tag }}-arm64'
- name_template: 'ghcr.io/google/addlicense:{{ .Tag }}'
image_templates:
- 'ghcr.io/google/addlicense:{{ .Tag }}-amd64'
- 'ghcr.io/google/addlicense:{{ .Tag }}-arm64'
- name_template: 'google/addlicense:latest'
image_templates:
- 'google/addlicense:{{ .Tag }}-amd64'
- 'google/addlicense:{{ .Tag }}-arm64'
- name_template: 'ghcr.io/google/addlicense:latest'
image_templates:
- 'ghcr.io/google/addlicense:{{ .Tag }}-amd64'
- 'ghcr.io/google/addlicense:{{ .Tag }}-arm64'
archives:
- format_overrides:
- goos: windows
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# make a bare minimal image
FROM scratch

WORKDIR app

COPY addlicense ./

ENTRYPOINT ["/app/addlicense"]

0 comments on commit 2149704

Please sign in to comment.