dev: use goreleaser to create Docker images (#4370)
This commit is contained in:
parent
5a78c8a06a
commit
dcddbda2a7
72
.github/workflows/tag.yml
vendored
72
.github/workflows/tag.yml
vendored
@ -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
|
||||
|
||||
@ -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
.goreleaser.yml
114
.goreleaser.yml
@ -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'
|
||||
|
@ -1,22 +0,0 @@
|
||||
# stage 1 building the code
|
||||
FROM golang:1.22 as builder
|
||||
|
||||
ARG VERSION
|
||||
ARG SHORT_COMMIT
|
||||
ARG DATE
|
||||
|
||||
COPY / /golangci
|
||||
WORKDIR /golangci
|
||||
RUN APP_VERSION=${VERSION#v} \
|
||||
CGO_ENABLED=0 \
|
||||
go build -trimpath -ldflags "-s -w -X main.version=$APP_VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
|
||||
|
||||
# stage 2
|
||||
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 '*'
|
||||
# don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume
|
||||
COPY --from=builder /golangci/golangci-lint /usr/bin/
|
||||
CMD ["golangci-lint"]
|
@ -1,31 +0,0 @@
|
||||
# stage 1 building the code
|
||||
FROM golang:1.22-alpine as builder
|
||||
|
||||
ARG VERSION
|
||||
ARG SHORT_COMMIT
|
||||
ARG DATE
|
||||
|
||||
COPY / /golangci
|
||||
WORKDIR /golangci
|
||||
|
||||
# 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
|
||||
RUN APP_VERSION=${VERSION#v} \
|
||||
CGO_ENABLED=0 \
|
||||
go build -trimpath -ldflags "-s -w -X main.version=$APP_VERSION -X main.commit=$SHORT_COMMIT -X main.date=$DATE" -o golangci-lint ./cmd/golangci-lint/main.go
|
||||
|
||||
# stage 2
|
||||
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 '*'
|
||||
# don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume
|
||||
COPY --from=builder /golangci/golangci-lint /usr/bin/
|
||||
CMD ["golangci-lint"]
|
16
build/buildx-alpine.Dockerfile
Normal file
16
build/buildx-alpine.Dockerfile
Normal file
@ -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
build/buildx.Dockerfile
Normal file
11
build/buildx.Dockerfile
Normal file
@ -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"]
|
Loading…
x
Reference in New Issue
Block a user