diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index ed70cc6fa13e..b970de5b25cb 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -26,3 +26,38 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GOLANGCI_LINT_TOKEN }} + - name: Prepare + id: prepare + run: | + TAG=${GITHUB_REF#refs/tags/} + MAJOR=${TAG%.*} + echo ::set-output name=tag_name::${TAG} + echo ::set-output name=major_tag::${MAJOR} + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: build and publish main image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: build/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + golangci/golangci-lint:${{ steps.prepare.outputs.tag_name }} + golangci/golangci-lint:${{ steps.prepare.outputs.major_tag }} + golangci/golangci-lint:latest + - name: build and publish alpine image + id: docker_build_alpine + uses: docker/build-push-action@v2 + with: + context: . + file: build/Dockerfile.alpine + platforms: linux/amd64,linux/arm64 + push: true + tags: | + golangci/golangci-lint:${{ steps.prepare.outputs.tag_name }}-alpine + golangci/golangci-lint:${{ steps.prepare.outputs.major_tag }}-alpine + golangci/golangci-lint:latest-alpine diff --git a/.goreleaser.yml b/.goreleaser.yml index 8e543497ad9a..fcaa63c792c8 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -63,22 +63,6 @@ changelog: - Merge pull request - Merge branch -dockers: - - dockerfile: build/Dockerfile - binaries: - - golangci-lint - image_templates: - - "golangci/golangci-lint:latest" - - "golangci/golangci-lint:{{ .Tag }}" - - "golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}" - - dockerfile: build/Dockerfile.alpine - binaries: - - golangci-lint - image_templates: - - "golangci/golangci-lint:latest-alpine" - - "golangci/golangci-lint:{{ .Tag }}-alpine" - - "golangci/golangci-lint:v{{ .Major }}.{{ .Minor }}-alpine" - brews: - tap: owner: golangci diff --git a/build/Dockerfile b/build/Dockerfile index 2bee70587c61..b9dc78c1d508 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,5 +1,12 @@ -FROM golang:1.15 +# stage 1 building the code +FROM golang:1.15 as builder + +COPY / /golangci +WORKDIR /golangci +RUN go build -o golangci-lint ./cmd/golangci-lint/main.go +# stage 2 +FROM golang:1.15 # don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume -COPY golangci-lint /usr/bin/ +COPY --from=builder /golangci/golangci-lint /usr/bin/ CMD ["golangci-lint"] diff --git a/build/Dockerfile.alpine b/build/Dockerfile.alpine index b9c34e0a4386..065c6596db6b 100644 --- a/build/Dockerfile.alpine +++ b/build/Dockerfile.alpine @@ -1,10 +1,16 @@ -FROM golang:1.15-alpine +# stage 1 building the code +FROM golang:1.15-alpine as builder + +COPY / /golangci +WORKDIR /golangci +RUN CGO_ENABLED=0 go build -o golangci-lint ./cmd/golangci-lint/main.go +# stage 2 +FROM golang:1.15-alpine # 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 - # don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume -COPY golangci-lint /usr/bin/ +COPY --from=builder /golangci/golangci-lint /usr/bin/ CMD ["golangci-lint"]