From a0d21c547855764ec4041b497c7cfae4070ebd4d Mon Sep 17 00:00:00 2001 From: odidev Date: Mon, 21 Sep 2020 04:56:35 +0000 Subject: [PATCH 1/2] Releasing docker image for arm64 Signed-off-by: odidev --- .github/workflows/tag.yml | 35 +++++++++++++++++++++++++++++++++++ .goreleaser.yml | 16 ---------------- build/Dockerfile | 11 +++++++++-- build/Dockerfile.alpine | 12 ++++++++++-- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index ed70cc6fa13e..6552d8068d00 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -17,6 +17,17 @@ jobs: go-version: 1.15 - name: Unshallow run: git fetch --prune --unshallow + - 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: Login do docker.io run: docker login -u golangci -p ${{ secrets.GOLANGCI_LINT_DOCKER_TOKEN }} - name: Create release @@ -26,3 +37,27 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GOLANGCI_LINT_TOKEN }} + - 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..ed853e99e3fd 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 # don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume -COPY golangci-lint /usr/bin/ +RUN git clone https://github.com/golangci/golangci-lint +WORKDIR golangci-lint +RUN go build -o /usr/bin/golangci-lint ./cmd/golangci-lint/main.go + +# stage 2 +FROM golang:1.15 +COPY --from=builder /usr/bin/golangci-lint /usr/bin/ CMD ["golangci-lint"] diff --git a/build/Dockerfile.alpine b/build/Dockerfile.alpine index b9c34e0a4386..0e9122a3b722 100644 --- a/build/Dockerfile.alpine +++ b/build/Dockerfile.alpine @@ -1,4 +1,5 @@ -FROM golang:1.15-alpine +# stage 1 building the code +FROM golang:1.15-alpine as builder # gcc is required to support cgo; # git and mercurial are needed most times for go get`, etc. @@ -6,5 +7,12 @@ FROM golang:1.15-alpine 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/ +RUN git clone https://github.com/golangci/golangci-lint +WORKDIR golangci-lint +RUN CGO_ENABLED=0 go build -o /usr/bin/golangci-lint ./cmd/golangci-lint/main.go + +# stage 2 +FROM golang:1.15-alpine +RUN apk --no-cache add gcc musl-dev git mercurial +COPY --from=builder /usr/bin/golangci-lint /usr/bin/ CMD ["golangci-lint"] From 84bf68f62ea4fb098a71011f99716a19b4d03ca2 Mon Sep 17 00:00:00 2001 From: odidev Date: Mon, 21 Sep 2020 09:01:03 +0000 Subject: [PATCH 2/2] Releasing docker image for arm64: Incorporate review comment Signed-off-by: odidev --- .github/workflows/tag.yml | 18 +++++++++--------- build/Dockerfile | 10 +++++----- build/Dockerfile.alpine | 16 +++++++--------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 6552d8068d00..b970de5b25cb 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -17,6 +17,15 @@ jobs: go-version: 1.15 - name: Unshallow run: git fetch --prune --unshallow + - name: Login do docker.io + run: docker login -u golangci -p ${{ secrets.GOLANGCI_LINT_DOCKER_TOKEN }} + - name: Create release + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GOLANGCI_LINT_TOKEN }} - name: Prepare id: prepare run: | @@ -28,15 +37,6 @@ jobs: uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Login do docker.io - run: docker login -u golangci -p ${{ secrets.GOLANGCI_LINT_DOCKER_TOKEN }} - - name: Create release - uses: goreleaser/goreleaser-action@v2 - with: - version: latest - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GOLANGCI_LINT_TOKEN }} - name: build and publish main image id: docker_build uses: docker/build-push-action@v2 diff --git a/build/Dockerfile b/build/Dockerfile index ed853e99e3fd..b9dc78c1d508 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,12 +1,12 @@ # stage 1 building the code FROM golang:1.15 as builder -# don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume -RUN git clone https://github.com/golangci/golangci-lint -WORKDIR golangci-lint -RUN go build -o /usr/bin/golangci-lint ./cmd/golangci-lint/main.go +COPY / /golangci +WORKDIR /golangci +RUN go build -o golangci-lint ./cmd/golangci-lint/main.go # stage 2 FROM golang:1.15 -COPY --from=builder /usr/bin/golangci-lint /usr/bin/ +# don't place it into $GOPATH/bin because Drone mounts $GOPATH as volume +COPY --from=builder /golangci/golangci-lint /usr/bin/ CMD ["golangci-lint"] diff --git a/build/Dockerfile.alpine b/build/Dockerfile.alpine index 0e9122a3b722..065c6596db6b 100644 --- a/build/Dockerfile.alpine +++ b/build/Dockerfile.alpine @@ -1,18 +1,16 @@ # 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 -RUN git clone https://github.com/golangci/golangci-lint -WORKDIR golangci-lint -RUN CGO_ENABLED=0 go build -o /usr/bin/golangci-lint ./cmd/golangci-lint/main.go - -# stage 2 -FROM golang:1.15-alpine -RUN apk --no-cache add gcc musl-dev git mercurial -COPY --from=builder /usr/bin/golangci-lint /usr/bin/ +COPY --from=builder /golangci/golangci-lint /usr/bin/ CMD ["golangci-lint"]