Skip to content

Commit 274303b

Browse files
committed
build: fix binary releaser
for docker, also fix ci in release & generate-pgo workflows build(make): seperate PGO subcommand Signed-off-by: Dwi Siswanto <[email protected]> build(docker): use PGO from the ARG Signed-off-by: Dwi Siswanto <[email protected]> build: use project name field and packaging the docker thru goreleaser Signed-off-by: Dwi Siswanto <[email protected]> ci(generate-pgo): artifact PGO file Signed-off-by: Dwi Siswanto <[email protected]> ci(release): refactor release workflow ci(release-publish): remove docker packaging job also download the PGO file artifact, if doesn't exists, make it Signed-off-by: Dwi Siswanto <[email protected]> ci: rename release-publish workflow Signed-off-by: Dwi Siswanto <[email protected]> ci(release): rm job input && cond expr Signed-off-by: Dwi Siswanto <[email protected]> ci(release): rm tag input && add if ref type is tag Signed-off-by: Dwi Siswanto <[email protected]> ci(release): seperate is-tag as a job Signed-off-by: Dwi Siswanto <[email protected]> revert: "ci(release): rm tag input && add if ref type is tag" Signed-off-by: Dwi Siswanto <[email protected]> ci(release): update tag input desc Signed-off-by: Dwi Siswanto <[email protected]> ci(release): fix build PGO file expr Signed-off-by: Dwi Siswanto <[email protected]> ci(release): build PGO file on failure only ci(release): update build PGO file script Signed-off-by: Dwi Siswanto <[email protected]> ci(release): build PGO file on failure only Signed-off-by: Dwi Siswanto <[email protected]> ci(generate-pgo): make pgo Signed-off-by: Dwi Siswanto <[email protected]> ci(release): `continue-on-error` while `download-artifact` Signed-off-by: Dwi Siswanto <[email protected]> build: fix seq & key indents in goreleaser config Signed-off-by: Dwi Siswanto <[email protected]> ci(release): make PGO with POSIX-comp script coz we are on container Signed-off-by: Dwi Siswanto <[email protected]> ci(release): copy the PGO instead of download artifact Signed-off-by: Dwi Siswanto <[email protected]> build(docker): fix COPY cmd Signed-off-by: Dwi Siswanto <[email protected]> ci(generate-pgo): copying PGO b4 upload as artifact Signed-off-by: Dwi Siswanto <[email protected]> ci(release): download PGO (artifact) and fallback copy from PGO branch Signed-off-by: Dwi Siswanto <[email protected]> ci(release): add `continue-on-error` while `download-artifact` Signed-off-by: Dwi Siswanto <[email protected]> build(docker): fix COPY cmd Signed-off-by: Dwi Siswanto <[email protected]> build(docker): set USER & GROUP and add labels Signed-off-by: Dwi Siswanto <[email protected]> chore(dockerignore): add out & test exts Signed-off-by: Dwi Siswanto <[email protected]> build: using dedicated dockerfile Signed-off-by: Dwi Siswanto <[email protected]>
1 parent 6868f3a commit 274303b

File tree

8 files changed

+170
-123
lines changed

8 files changed

+170
-123
lines changed

.dockerignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
**/.github
44
**/Dockerfile
55
**/.dockerignore
6-
**/demo
6+
**/demo
7+
**/*.out
8+
**/*.test
9+
**/bin
10+
**/dist

.github/workflows/generate-pgo.yaml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,36 @@ env:
1414
PGO_BRANCH: "pgo"
1515

1616
jobs:
17-
tests:
17+
generate-pgo:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v3
21+
2122
- uses: actions/setup-go@v5
2223
with:
23-
go-version: 'stable'
24+
go-version-file: 'go.mod'
2425
cache-dependency-path: '**/go.sum'
25-
- run: make pprof && cp ${{ env.PGO_FILE }} /tmp/
26+
27+
- run: make pgo && cp ${{ env.PGO_FILE }} /tmp/
28+
2629
- uses: actions/checkout@v3
2730
with:
2831
ref: ${{ env.PGO_BRANCH }}
29-
- run: git rm --cached ${{ env.PGO_FILE }}
30-
- if: ${{ success() || failure() }}
31-
run: |
32+
33+
- run: |
34+
git rm --cached ${{ env.PGO_FILE }}
3235
cp /tmp/${{ env.PGO_FILE }} .
36+
37+
- uses: actions/upload-artifact@v4
38+
if: (success() || failure())
39+
with:
40+
name: pgo
41+
path: ${{ env.PGO_FILE }}
42+
retention-days: 90
43+
overwrite: true
44+
45+
- name: pushing PGO file
46+
run: |
3347
git config --local user.email "[email protected]"
3448
git config --local user.name "ghost"
3549
git add ${{ env.PGO_FILE }}

.github/workflows/release-publish.yaml

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

.github/workflows/release.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ["v*.*.**"]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: "Target tag to release"
10+
required: true
11+
type: string
12+
13+
env:
14+
PGO_FILE: "default.pgo"
15+
16+
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
container:
20+
image: ghcr.io/goreleaser/goreleaser-cross:latest
21+
steps:
22+
- uses: actions/download-artifact@v4
23+
id: artifact
24+
with:
25+
name: pgo
26+
continue-on-error: true
27+
28+
- uses: actions/checkout@v3
29+
if: steps.artifact.outcome != 'success'
30+
with:
31+
ref: pgo
32+
33+
- run: cp ${{ env.PGO_FILE }} /tmp
34+
if: steps.artifact.outcome != 'success'
35+
36+
- uses: actions/checkout@v3
37+
with:
38+
ref: "${{ inputs.tag || github.ref_name }}"
39+
40+
- run: cp /tmp/${{ env.PGO_FILE }} .
41+
if: steps.artifact.outcome != 'success'
42+
43+
- uses: actions/setup-go@v5
44+
with:
45+
go-version-file: 'go.mod'
46+
cache-dependency-path: '**/go.sum'
47+
48+
- name: Build PGO file
49+
run: '[ -f "${{ env.PGO_FILE }}" ] || make pgo'
50+
51+
- run: git config --global --add safe.directory "$(pwd)"
52+
53+
- run: goreleaser release --clean
54+
env:
55+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.goreleaser.yaml

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
env:
22
- CGO_ENABLED=1
3+
- PGO_FILE=default.pgo
34

45
before:
56
hooks:
@@ -9,9 +10,9 @@ release:
910
prerelease: auto
1011

1112
builds:
12-
- id: teler-proxy_darwin-amd64
13-
binary: teler-proxy
14-
main: ./cmd/teler-proxy
13+
- id: "{{ .ProjectName }}_darwin-amd64"
14+
binary: "{{ .ProjectName }}"
15+
main: ./cmd/{{ .ProjectName }}
1516
goarch:
1617
- amd64
1718
goos:
@@ -21,13 +22,13 @@ builds:
2122
- CXX=o64-clang++
2223
flags:
2324
- -trimpath
24-
- -pgo=default.pgo
25+
- -pgo={{ .Env.PGO_FILE }}
2526
ldflags:
26-
- -s -w -X github.com/kitabisa/teler-proxy/common.Version={{ .Version }}
27+
- -s -w -X github.com/kitabisa/{{ .ProjectName }}/common.Version={{ .Version }}
2728

28-
- id: teler-proxy_darwin-arm64
29-
binary: teler-proxy
30-
main: ./cmd/teler-proxy
29+
- id: "{{ .ProjectName }}_darwin-arm64"
30+
binary: "{{ .ProjectName }}"
31+
main: ./cmd/{{ .ProjectName }}
3132
goarch:
3233
- arm64
3334
goos:
@@ -37,13 +38,13 @@ builds:
3738
- CXX=oa64-clang++
3839
flags:
3940
- -trimpath
40-
- -pgo=default.pgo
41+
- -pgo={{ .Env.PGO_FILE }}
4142
ldflags:
42-
- -s -w -X github.com/kitabisa/teler-proxy/common.Version={{ .Version }}
43+
- -s -w -X github.com/kitabisa/{{ .ProjectName }}/common.Version={{ .Version }}
4344

44-
- id: teler-proxy_linux-amd64
45-
binary: teler-proxy
46-
main: ./cmd/teler-proxy
45+
- id: "{{ .ProjectName }}_linux-amd64"
46+
binary: "{{ .ProjectName }}"
47+
main: ./cmd/{{ .ProjectName }}
4748
env:
4849
- CC=x86_64-linux-gnu-gcc
4950
- CXX=x86_64-linux-gnu-g++
@@ -53,13 +54,13 @@ builds:
5354
- linux
5455
flags:
5556
- -trimpath
56-
- -pgo=default.pgo
57+
- -pgo={{ .Env.PGO_FILE }}
5758
ldflags:
58-
- -s -w -X github.com/kitabisa/teler-proxy/common.Version={{ .Version }}
59+
- -s -w -X github.com/kitabisa/{{ .ProjectName }}/common.Version={{ .Version }}
5960

60-
- id: teler-proxy_linux-arm64
61-
binary: teler-proxy
62-
main: ./cmd/teler-proxy
61+
- id: "{{ .ProjectName }}_linux-arm64"
62+
binary: "{{ .ProjectName }}"
63+
main: ./cmd/{{ .ProjectName }}
6364
goarch:
6465
- arm64
6566
goos:
@@ -69,13 +70,13 @@ builds:
6970
- CXX=aarch64-linux-gnu-g++
7071
flags:
7172
- -trimpath
72-
- -pgo=default.pgo
73+
- -pgo={{ .Env.PGO_FILE }}
7374
ldflags:
74-
- -s -w -X github.com/kitabisa/teler-proxy/common.Version={{ .Version }}
75+
- -s -w -X github.com/kitabisa/{{ .ProjectName }}/common.Version={{ .Version }}
7576

76-
- id: teler-proxy_windows-amd64
77-
binary: teler-proxy
78-
main: ./cmd/teler-proxy
77+
- id: "{{ .ProjectName }}_windows-amd64"
78+
binary: "{{ .ProjectName }}"
79+
main: ./cmd/{{ .ProjectName }}
7980
goarch:
8081
- amd64
8182
goos:
@@ -85,27 +86,20 @@ builds:
8586
- CXX=x86_64-w64-mingw32-g++
8687
flags:
8788
- -trimpath
88-
- -pgo=default.pgo
89+
- -pgo={{ .Env.PGO_FILE }}
8990
- -buildmode=exe
9091
ldflags:
91-
- -s -w -X github.com/kitabisa/teler-proxy/common.Version={{ .Version }}
92-
93-
universal_binaries:
94-
- id: teler-proxy_darwin-universal
95-
ids:
96-
- teler-proxy_darwin-amd64
97-
- teler-proxy_darwin-arm64
98-
replace: true
99-
name_template: "teler-proxy"
92+
- -s -w -X github.com/kitabisa/{{ .ProjectName }}/common.Version={{ .Version }}
10093

10194
archives:
10295
- id: build
10396
builds:
104-
- teler-proxy_darwin-universal
105-
- teler-proxy_linux-amd64
106-
- teler-proxy_linux-arm64
107-
- teler-proxy_windows-amd64
108-
name_template: "teler-proxy_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
97+
- "{{ .ProjectName }}_darwin-amd64"
98+
- "{{ .ProjectName }}_darwin-arm64"
99+
- "{{ .ProjectName }}_linux-amd64"
100+
- "{{ .ProjectName }}_linux-arm64"
101+
- "{{ .ProjectName }}_windows-amd64"
102+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
109103
wrap_in_directory: false
110104
files:
111105
- "LICENSE*"
@@ -119,4 +113,24 @@ checksum:
119113
snapshot:
120114
name_template: "{{ incpatch .Version }}-next"
121115
changelog:
122-
sort: asc
116+
sort: asc
117+
118+
dockers:
119+
- image_templates:
120+
- "ghcr.io/kitabisa/{{ .ProjectName }}:{{ .Tag }}"
121+
- "ghcr.io/kitabisa/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}"
122+
- "ghcr.io/kitabisa/{{ .ProjectName }}:v{{ .Major }}"
123+
- "ghcr.io/kitabisa/{{ .ProjectName }}:latest"
124+
dockerfile: Dockerfile.goreleaser
125+
use: docker
126+
build_flag_templates:
127+
- "--pull"
128+
- "--label=org.opencontainers.image.authors=\"Dwi Siswanto <[email protected]>\""
129+
- "--label=org.opencontainers.image.created={{ .Date }}"
130+
- "--label=org.opencontainers.image.description=\"teler Proxy enabling seamless integration with teler WAF to protect locally running web service against a variety of web-based attacks\""
131+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
132+
- "--label=org.opencontainers.image.ref.name={{ .Tag }}"
133+
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
134+
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
135+
- "--label=org.opencontainers.image.url=https://github.com/kitabisa/{{ .ProjectName }}"
136+
- "--label=org.opencontainers.image.version={{ .Version }}"

Dockerfile

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
1-
FROM golang:alpine AS build
1+
FROM golang:alpine
22

33
ARG VERSION="docker"
44
ARG LDFLAGS="-s -w -X github.com/kitabisa/teler-proxy/common.Version=${VERSION}"
55
ARG PGO_FILE="default.pgo"
66

7-
LABEL description="teler Proxy enabling seamless integration with teler WAF to protect locally running web service against a variety of web-based attacks"
8-
LABEL repository="https://github.com/kitabisa/teler-proxy"
9-
LABEL maintainer="dwisiswant0"
7+
LABEL org.opencontainers.image.authors="Dwi Siswanto <[email protected]>"
8+
LABEL org.opencontainers.image.description="teler Proxy enabling seamless integration with teler WAF to protect locally running web service against a variety of web-based attacks"
9+
LABEL org.opencontainers.image.licenses="Apache-2.0"
10+
LABEL org.opencontainers.image.ref.name="${VERSION}"
11+
LABEL org.opencontainers.image.title="teler-proxy"
12+
LABEL org.opencontainers.image.url="https://github.com/kitabisa/teler-proxy"
13+
LABEL org.opencontainers.image.version="${VERSION}"
1014

1115
WORKDIR /app
12-
COPY ["go.mod", "."]
13-
COPY ["${PGO_FILE}", "./default.pgo"]
16+
17+
COPY ["go.mod", "${PGO_FILE}", "./"]
1418
RUN go mod download
1519

20+
COPY . .
21+
22+
ENV CGO_ENABLED=1
23+
1624
RUN apk add build-base
25+
RUN go build \
26+
-pgo "${PGO_FILE}" \
27+
-ldflags "${LDFLAGS}" \
28+
-o /bin/teler-proxy \
29+
-v ./cmd/teler-proxy
1730

18-
COPY . .
19-
RUN CGO_ENABLED="1" go build \
20-
-pgo "default.pgo" -ldflags "${LDFLAGS}" \
21-
-o ./bin/teler-proxy ./cmd/teler-proxy
31+
RUN addgroup \
32+
-g "2000" \
33+
teler-proxy && \
34+
adduser \
35+
-g "teler-proxy" \
36+
-G "teler-proxy" \
37+
-u "1000" \
38+
-h "/app" \
39+
-D teler-proxy
2240

23-
FROM alpine:latest
41+
USER teler-proxy:teler-proxy
2442

25-
COPY --from=build /app/bin/teler-proxy /bin/teler-proxy
26-
ENV HOME /
2743
ENTRYPOINT ["/bin/teler-proxy"]

Dockerfile.goreleaser

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM scratch
2+
3+
COPY teler-proxy /teler-proxy
4+
5+
ENTRYPOINT ["/teler-proxy"]

0 commit comments

Comments
 (0)