Skip to content

dev: use goreleaser to create Docker images #4370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 6 additions & 66 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,6 @@ jobs:
- name: Unshallow
run: git fetch --prune --unshallow

- name: Create release
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GOLANGCI_LINT_TOKEN }}

docker-release:
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
target:
- Dockerfile: build/Dockerfile
- Dockerfile: build/alpine.Dockerfile
steps:
- uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
# https://github.com/actions/setup-go#supported-version-syntax
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
go-version: '1.22'

- name: Unshallow
run: git fetch --prune --unshallow

- name: Prepare
id: prepare
run: |
TAG=${GITHUB_REF#refs/tags/}
MAJOR=${TAG%.*}
SHORT_COMMIT=${GITHUB_SHA::8}
DATE=$(date '+%Y-%m-%dT%H:%M:%SZ')
echo tag_name=${TAG} >> $GITHUB_OUTPUT
echo major_tag=${MAJOR} >> $GITHUB_OUTPUT
echo short_commit=${SHORT_COMMIT} >> $GITHUB_OUTPUT
echo date=${DATE} >> $GITHUB_OUTPUT
if [[ ${{ matrix.target.Dockerfile }} == *"alpine"* ]]; then
echo full_tag_name=${TAG}-alpine >> $GITHUB_OUTPUT
echo full_major_tag=${MAJOR}-alpine >> $GITHUB_OUTPUT
echo latest_tag=latest-alpine >> $GITHUB_OUTPUT
else
echo full_tag_name=${TAG} >> $GITHUB_OUTPUT
echo full_major_tag=${MAJOR} >> $GITHUB_OUTPUT
echo latest_tag=latest >> $GITHUB_OUTPUT
fi

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -81,18 +29,10 @@ jobs:
- name: Login do docker.io
run: docker login -u golangci -p ${{ secrets.GOLANGCI_LINT_DOCKER_TOKEN }}

- name: Build and publish ${{ matrix.target.Dockerfile }}
uses: docker/build-push-action@v5
- name: Create release
uses: goreleaser/goreleaser-action@v5
with:
context: .
file: ${{ matrix.target.Dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ steps.prepare.outputs.tag_name }}
SHORT_COMMIT=${{ steps.prepare.outputs.short_commit }}
DATE=${{ steps.prepare.outputs.date }}
tags: |
golangci/golangci-lint:${{ steps.prepare.outputs.full_tag_name }}
golangci/golangci-lint:${{ steps.prepare.outputs.full_major_tag }}
golangci/golangci-lint:${{ steps.prepare.outputs.latest_tag }}
version: latest
args: release --clean --timeout=90m
env:
GITHUB_TOKEN: ${{ secrets.GOLANGCI_LINT_TOKEN }}
114 changes: 114 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,117 @@ nfpms:
- /usr/bin/go
rpm:
group: Development/Tools

docker_manifests:
# basic
- name_template: 'golangci/golangci-lint:latest'
image_templates:
- 'golangci/golangci-lint:{{ .Tag }}-amd64'
- 'golangci/golangci-lint:{{ .Tag }}-arm64'
- name_template: 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}'
image_templates:
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-amd64'
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-arm64'
- name_template: 'golangci/golangci-lint:{{ .Tag }}'
image_templates:
- 'golangci/golangci-lint:{{ .Tag }}-amd64'
- 'golangci/golangci-lint:{{ .Tag }}-arm64'

# alpine
- name_template: 'golangci/golangci-lint:latest-alpine'
image_templates:
- 'golangci/golangci-lint:{{ .Tag }}-alpine-amd64'
- 'golangci/golangci-lint:{{ .Tag }}-alpine-arm64'
- name_template: 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-alpine'
image_templates:
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-alpine-amd64'
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-alpine-arm64'
- name_template: 'golangci/golangci-lint:{{ .Tag }}'
image_templates:
- 'golangci/golangci-lint:{{ .Tag }}-alpine-amd64'
- 'golangci/golangci-lint:{{ .Tag }}-alpine-arm64'

dockers:
- use: buildx
goos: linux
goarch: amd64
dockerfile: build/buildx.Dockerfile
image_templates:
- 'golangci/golangci-lint:latest-amd64'
- 'golangci/golangci-lint:{{ .Tag }}-amd64'
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-amd64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Fast linters Runner for Go'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://golangci-lint.run'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/amd64'

- use: buildx
goos: linux
goarch: arm64
dockerfile: build/buildx.Dockerfile
image_templates:
- 'golangci/golangci-lint:latest-arm64'
- 'golangci/golangci-lint:{{ .Tag }}-arm64'
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-arm64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Fast linters Runner for Go'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://golangci-lint.run'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/arm64'

- use: buildx
goos: linux
goarch: amd64
dockerfile: build/buildx-alpine.Dockerfile
image_templates:
- 'golangci/golangci-lint:latest-alpine-amd64'
- 'golangci/golangci-lint:{{ .Tag }}-alpine-amd64'
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-alpine-amd64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Fast linters Runner for Go'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://golangci-lint.run'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/amd64'

- use: buildx
goos: linux
goarch: arm64
dockerfile: build/buildx-alpine.Dockerfile
image_templates:
- 'golangci/golangci-lint:latest-alpine-arm64'
- 'golangci/golangci-lint:{{ .Tag }}-alpine-arm64'
- 'golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-alpine-arm64'
build_flag_templates:
- '--pull'
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.description=Fast linters Runner for Go'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--label=org.opencontainers.image.url={{.GitURL}}'
- '--label=org.opencontainers.image.documentation=https://golangci-lint.run'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--platform=linux/arm64'
22 changes: 0 additions & 22 deletions build/Dockerfile

This file was deleted.

31 changes: 0 additions & 31 deletions build/alpine.Dockerfile

This file was deleted.

16 changes: 16 additions & 0 deletions build/buildx-alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# syntax=docker/dockerfile:1.4
FROM golang:1.22-alpine

# related to https://github.com/golangci/golangci-lint/issues/3107
ENV GOROOT /usr/local/go

# gcc is required to support cgo;
# git and mercurial are needed most times for go get`, etc.
# See https://github.com/docker-library/golang/issues/80
RUN apk --no-cache add gcc musl-dev git mercurial

# Set all directories as safe
RUN git config --global --add safe.directory '*'

COPY golangci-lint /usr/bin/
CMD ["golangci-lint"]
11 changes: 11 additions & 0 deletions build/buildx.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# syntax=docker/dockerfile:1.4
FROM golang:1.22

# related to https://github.com/golangci/golangci-lint/issues/3107
ENV GOROOT /usr/local/go

# Set all directories as safe
RUN git config --global --add safe.directory '*'

COPY golangci-lint /usr/bin/
CMD ["golangci-lint"]