Skip to content

Commit af48f24

Browse files
authored
build: publishing binary and container with goreleaser (#247)
* build: publishing binary and container with goreleaser * build: compile before make * build: add go lint dependencies
1 parent 4f45784 commit af48f24

File tree

5 files changed

+110
-94
lines changed

5 files changed

+110
-94
lines changed

.github/workflows/image.yaml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: goreleaser
2+
on:
3+
# when you push a tag that matches v*, build binaries
4+
push:
5+
tags:
6+
- v*
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
attestations: write
12+
id-token: write
13+
14+
jobs:
15+
goreleaser:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
- name: Log in to the Container registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Run GoReleaser
31+
uses: goreleaser/goreleaser-action@v6
32+
with:
33+
distribution: goreleaser
34+
version: 'latest'
35+
args: release --clean
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
env:
2+
- GO111MODULE=on
3+
- CGO_ENABLED=0
4+
5+
metadata:
6+
mod_timestamp: "{{ .CommitTimestamp }}"
7+
8+
builds:
9+
- env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
- darwin
14+
- windows
15+
goarch:
16+
- amd64
17+
- arm64
18+
mod_timestamp: "{{ .CommitTimestamp }}"
19+
flags:
20+
- -trimpath
21+
ldflags:
22+
- -s -w -X github.com/qiniu/reviewbot/internal/version.version={{.Version}}
23+
dockers:
24+
- image_templates:
25+
[
26+
"ghcr.io/qiniu/reviewbot:{{ .Version }}",
27+
"ghcr.io/qiniu/reviewbot:latest",
28+
]
29+
dockerfile: Dockerfile
30+
use: buildx
31+
build_flag_templates:
32+
- "--pull"
33+
- "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/qiniu/reviewbot/master/README.md"
34+
- "--label=org.opencontainers.image.description=Comprehensive linters runner for code review"
35+
- "--label=org.opencontainers.image.created={{.Date}}"
36+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
37+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
38+
- "--label=org.opencontainers.image.version={{.Version}}"
39+
- "--label=org.opencontainers.image.source={{.GitURL}}"
40+
- "--platform=linux/amd64"
41+
- image_templates:
42+
[
43+
"ghcr.io/qiniu/reviewbot:{{ .Version }}",
44+
"ghcr.io/qiniu/reviewbot:latest",
45+
]
46+
dockerfile: Dockerfile
47+
use: buildx
48+
build_flag_templates:
49+
- "--pull"
50+
- "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/qiniu/reviewbot/master/README.md"
51+
- "--label=org.opencontainers.image.description=Comprehensive linters runner for code review"
52+
- "--label=org.opencontainers.image.created={{.Date}}"
53+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
54+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
55+
- "--label=org.opencontainers.image.version={{.Version}}"
56+
- "--label=org.opencontainers.image.source={{.GitURL}}"
57+
- "--platform=linux/arm64"
58+
goarch: arm64
59+
archives:
60+
- format: binary

Dockerfile

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
FROM library/golang:1.22.4 as builder
2-
3-
WORKDIR /app
4-
5-
# keep this cache in a separate layer to speed up builds
6-
RUN GOPATH=/go go install -ldflags="-extldflags=-static" github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
7-
8-
COPY . ./
9-
10-
RUN CGO_ENABLED=0 GOOS=linux go build -v -trimpath -o /reviewbot .
11-
12-
FROM alpine:3.20 as runner
1+
# go lint tool dependencies `go list` `gofmt`
2+
FROM golang:alpine
133

144
# if you want to install other tools, please add them here.
155
# Do not install unnecessary tools to reduce image size.
166
RUN set -eux \
177
apk update && \
18-
apk --no-cache add ca-certificates luacheck cppcheck shellcheck git openssh yarn libpcap-dev curl build-base
8+
apk --no-cache add ca-certificates luacheck cppcheck shellcheck git openssh yarn libpcap-dev curl build-base && \
9+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.59.1
10+
1911
WORKDIR /
2012
# check binary
2113
RUN cppcheck --version \
@@ -25,12 +17,11 @@ RUN cppcheck --version \
2517
&& ssh -V \
2618
&& yarn --version \
2719
&& curl --version \
28-
&& gcc --version
20+
&& gcc --version \
21+
&& golangci-lint --version \
22+
&& go version
2923

30-
COPY --from=builder /reviewbot /reviewbot
31-
COPY --from=builder /go/bin/golangci-lint /usr/local/bin/
32-
# golangci-lint dependencies
33-
COPY --from=builder /usr/local/go/ /usr/local/go/
24+
COPY reviewbot /reviewbot
3425

3526
# SSH config
3627
RUN mkdir -p /root/.ssh && chown -R root /root/.ssh/ && chgrp -R root /root/.ssh/ \
@@ -39,8 +30,6 @@ RUN mkdir -p /root/.ssh && chown -R root /root/.ssh/ && chgrp -R root /root/.ss
3930
COPY deploy/config /root/.ssh/config
4031
COPY deploy/github-known-hosts /github_known_hosts
4132

42-
ENV PATH="${PATH}:/usr/local/go/bin"
43-
4433
EXPOSE 8888
4534

4635
ENTRYPOINT [ "/reviewbot" ]

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ staticcheck: check-staticcheck
3535
build: check-go
3636
CGO_ENABLED=0 go build -v -trimpath -ldflags "$(LDFLAGS)" -o ./reviewbot .
3737

38-
docker-build-latest: check-docker
39-
docker builder build --push -t $(DOCKER_IMAGE):$(TAG) -t $(DOCKER_IMAGE):latest --target runner .
38+
docker-build-latest: check-docker build
39+
docker builder build --push -t $(DOCKER_IMAGE):$(TAG) -t $(DOCKER_IMAGE):latest .
4040

41-
docker-dev: check-docker
42-
docker builder build -t $(DOCKER_IMAGE):$(TAG) --target runner .
41+
docker-dev: check-docker build
42+
docker builder build -t $(DOCKER_IMAGE):$(TAG) .
4343

4444
kubernetes-deploy: check-kubectl
4545
kubectl apply -k .

0 commit comments

Comments
 (0)