From 6b2b4162d2695948e11b6c7d5d2250ab3e5b7a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Apayd=C4=B1n?= Date: Sat, 4 Dec 2021 23:47:05 +0300 Subject: [PATCH] feat: goreleaser release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Batuhan Apaydın Co-authored-by: Furkan Türkal Signed-off-by: Batuhan Apaydın --- .github/workflows/release.yaml | 71 +++++++++++++--------------------- .goreleaser.yaml | 43 +++++++++++++++++++- Dockerfile.goreleaser | 8 ++++ 3 files changed, 76 insertions(+), 46 deletions(-) create mode 100644 Dockerfile.goreleaser diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f57158d..887347a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,65 +5,48 @@ on: tags: - '*' +permissions: + contents: 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" + REGISTYRY: "ghcr.io" + IMAGE_NAME: "google/addlicense" 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.2.0 + - uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # pin@v1.6.0 + - name: dockerhub-login + if: startsWith(github.ref, 'refs/tags/v') + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 # pin@v1.10.0 + 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.10.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@5df302e5e9e4c66310a6b6493a8865b12c555af2 # pin@v2.8.0 with: distribution: goreleaser version: latest args: release --rm-dist env: + REGISTRY: ${{ env.REGISTRY }} + IMAGE: ${{ env.IMAGE_NAME }} 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 }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index b06b10e..9e91a71 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,9 +1,13 @@ before: hooks: - go mod tidy + +env: + - GO111MODULE=on + - CGO_ENABLED=0 + builds: - - env: - - CGO_ENABLED=0 + - binary: addlicense goos: - linux - windows @@ -11,6 +15,41 @@ builds: goarch: - amd64 - arm64 +dockers: + - image_templates: + - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .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: + - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .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: '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}::{{ .Tag }}' + image_templates: + - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64' + - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64' + - name_template: 'ghcr.io/google/addlicense:latest' + image_templates: + - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64' + - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64' archives: - format_overrides: - goos: windows diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser new file mode 100644 index 0000000..a38a9f5 --- /dev/null +++ b/Dockerfile.goreleaser @@ -0,0 +1,8 @@ +# make a bare minimal image +FROM scratch + +WORKDIR /src + +COPY addlicense /app/addlicense + +ENTRYPOINT ["/app/addlicense"]