Skip to content

Commit e59988e

Browse files
committed
add github ci/cd work flow
1 parent 4176278 commit e59988e

File tree

10 files changed

+436
-24
lines changed

10 files changed

+436
-24
lines changed

.github/workflows/pages.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ defaults:
2929
jobs:
3030
# Build job
3131
build:
32+
# Only run on commits starting with "docs:" or manual workflow dispatch
33+
if: |
34+
github.event_name == 'workflow_dispatch' ||
35+
(github.event_name == 'push' && startsWith(github.event.head_commit.message, 'docs:'))
3236
runs-on: ubuntu-latest
3337
env:
3438
HUGO_VERSION: 0.147.7

.github/workflows/release.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version-file: 'go.mod'
24+
cache: true
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Login to Docker Hub
33+
uses: docker/login-action@v3
34+
with:
35+
username: ${{ secrets.DOCKERHUB_USERNAME }}
36+
password: ${{ secrets.DOCKERHUB_TOKEN }}
37+
38+
- name: Run GoReleaser
39+
uses: goreleaser/goreleaser-action@v6
40+
with:
41+
distribution: goreleaser
42+
version: latest
43+
args: release --clean
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Upload artifacts
48+
uses: actions/upload-artifact@v4
49+
if: always()
50+
with:
51+
name: dist
52+
path: dist/
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Test Release
2+
3+
on:
4+
workflow_dispatch: # 允许手动触发
5+
pull_request:
6+
paths:
7+
- '.goreleaser.yml'
8+
- '.github/workflows/release.yaml'
9+
- '.github/workflows/test-release.yaml'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: 'go.mod'
27+
cache: true
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Test GoReleaser config
36+
uses: goreleaser/goreleaser-action@v6
37+
with:
38+
distribution: goreleaser
39+
version: latest
40+
args: check
41+
42+
- name: Build snapshot
43+
uses: goreleaser/goreleaser-action@v6
44+
with:
45+
distribution: goreleaser
46+
version: latest
47+
args: release --snapshot --clean --skip=publish,docker
48+
49+
- name: List artifacts
50+
run: |
51+
echo "Generated artifacts:"
52+
ls -lh dist/*.tar.gz || true
53+
echo ""
54+
echo "Checksums:"
55+
cat dist/checksums.txt || true

.goreleaser.yml

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
version: 2
2+
3+
env:
4+
- CGO_ENABLED=0
5+
6+
before:
7+
hooks:
8+
- go mod download
9+
- go mod tidy
10+
11+
builds:
12+
- id: pg_exporter
13+
main: ./main.go
14+
binary: pg_exporter
15+
goos:
16+
- linux
17+
- darwin
18+
- windows
19+
goarch:
20+
- amd64
21+
- arm64
22+
- ppc64le
23+
goarm:
24+
- 6
25+
- 7
26+
goamd64:
27+
- v1
28+
ignore:
29+
# Darwin only supports amd64 and arm64
30+
- goos: darwin
31+
goarch: ppc64le
32+
# Windows only supports amd64 and 386
33+
- goos: windows
34+
goarch: arm64
35+
- goos: windows
36+
goarch: arm
37+
- goos: windows
38+
goarch: ppc64le
39+
ldflags:
40+
- -s -w
41+
- -extldflags "-static"
42+
- -X 'pg_exporter/exporter.Version={{.Version}}'
43+
- -X 'pg_exporter/exporter.Branch={{.Branch}}'
44+
- -X 'pg_exporter/exporter.Revision={{.ShortCommit}}'
45+
- -X 'pg_exporter/exporter.BuildDate={{.Date}}'
46+
flags:
47+
- -a
48+
49+
archives:
50+
- id: pg_exporter
51+
name_template: >-
52+
{{ .ProjectName }}-{{ .Version }}.{{ .Os }}-
53+
{{- if eq .Arch "amd64" }}amd64
54+
{{- else if eq .Arch "386" }}386
55+
{{- else if eq .Arch "arm64" }}arm64
56+
{{- else if eq .Arch "arm" }}armv{{ .Arm }}
57+
{{- else if eq .Arch "ppc64le" }}ppc64le
58+
{{- else }}{{ .Arch }}{{ end }}
59+
files:
60+
- pg_exporter.yml
61+
- LICENSE
62+
- package/pg_exporter.default
63+
- package/pg_exporter.service
64+
65+
nfpms:
66+
- id: pg_exporter_rpm
67+
package_name: pg_exporter
68+
file_name_template: >-
69+
{{ .PackageName }}-{{ .Version }}-{{ .Release }}.
70+
{{- if eq .Arch "amd64" }}x86_64
71+
{{- else if eq .Arch "arm64" }}aarch64
72+
{{- else }}{{ .Arch }}{{ end }}
73+
vendor: PGSTY
74+
homepage: https://exp.pgsty.com
75+
maintainer: Ruohang Feng <rh@vonng.com>
76+
description: |
77+
Prometheus exporter for PostgreSQL / Pgbouncer server metrics.
78+
Supported version: Postgres9.4 - 17+ & Pgbouncer 1.8 - 1.24+
79+
Part of Project Pigsty -- Battery Included PostgreSQL Distribution
80+
with ultimate observability support: https://doc.pgsty.com
81+
license: Apache-2.0
82+
formats:
83+
- rpm
84+
bindir: /usr/bin
85+
release: "1"
86+
section: database
87+
priority: optional
88+
contents:
89+
- src: pg_exporter.yml
90+
dst: /etc/pg_exporter.yml
91+
type: config|noreplace
92+
file_info:
93+
mode: 0700
94+
owner: prometheus
95+
group: prometheus
96+
- src: package/pg_exporter.default
97+
dst: /etc/default/pg_exporter
98+
type: config|noreplace
99+
file_info:
100+
mode: 0700
101+
owner: prometheus
102+
group: prometheus
103+
- src: package/pg_exporter.service
104+
dst: /usr/lib/systemd/system/pg_exporter.service
105+
type: config
106+
- src: LICENSE
107+
dst: /usr/share/doc/pg_exporter/LICENSE
108+
file_info:
109+
mode: 0644
110+
scripts:
111+
preinstall: package/preinstall.sh
112+
rpm:
113+
compression: gzip
114+
prefixes:
115+
- /usr/bin
116+
117+
- id: pg_exporter_deb
118+
package_name: pg-exporter
119+
file_name_template: >-
120+
{{ .PackageName }}_{{ .Version }}-{{ .Release }}_
121+
{{- if eq .Arch "amd64" }}amd64
122+
{{- else if eq .Arch "arm64" }}arm64
123+
{{- else }}{{ .Arch }}{{ end }}
124+
vendor: PGSTY
125+
homepage: https://exp.pgsty.com
126+
maintainer: Ruohang Feng <rh@vonng.com>
127+
description: |
128+
Prometheus exporter for PostgreSQL / Pgbouncer server metrics.
129+
Supported version: Postgres9.4 - 17+ & Pgbouncer 1.8 - 1.24+
130+
Part of Project Pigsty -- Battery Included PostgreSQL Distribution
131+
with ultimate observability support: https://doc.pgsty.com
132+
license: Apache-2.0
133+
formats:
134+
- deb
135+
bindir: /usr/bin
136+
release: "1"
137+
section: database
138+
priority: optional
139+
contents:
140+
- src: pg_exporter.yml
141+
dst: /etc/pg_exporter.yml
142+
type: config|noreplace
143+
file_info:
144+
mode: 0700
145+
owner: prometheus
146+
group: prometheus
147+
- src: package/pg_exporter.default
148+
dst: /etc/default/pg_exporter
149+
type: config|noreplace
150+
file_info:
151+
mode: 0700
152+
owner: prometheus
153+
group: prometheus
154+
- src: package/pg_exporter.service
155+
dst: /lib/systemd/system/pg_exporter.service
156+
type: config
157+
- src: LICENSE
158+
dst: /usr/share/doc/pg_exporter/LICENSE
159+
file_info:
160+
mode: 0644
161+
scripts:
162+
preinstall: package/preinstall.sh
163+
164+
checksum:
165+
name_template: 'checksums.txt'
166+
algorithm: sha256
167+
168+
snapshot:
169+
version_template: "{{ .Tag }}-next"
170+
171+
changelog:
172+
sort: asc
173+
filters:
174+
exclude:
175+
- '^docs:'
176+
- '^test:'
177+
- '^chore:'
178+
- 'Merge pull request'
179+
- 'Merge branch'
180+
181+
release:
182+
github:
183+
owner: pgsty
184+
name: pg_exporter
185+
draft: false
186+
prerelease: false
187+
mode: replace # Replace existing release with same tag
188+
replace_existing_artifacts: true # Replace existing artifacts
189+
name_template: "{{.ProjectName}}-v{{.Version}}"
190+
disable: false
191+
discussion_category_name: "" # Skip discussion creation
192+
193+
announce:
194+
skip: true # Skip all announcements
195+
196+
# Docker configuration for multi-arch images
197+
dockers:
198+
- id: pg_exporter_amd64
199+
ids:
200+
- pg_exporter
201+
goos: linux
202+
goarch: amd64
203+
image_templates:
204+
- "pgsty/pg_exporter:{{ .Version }}-amd64"
205+
- "pgsty/pg_exporter:latest-amd64"
206+
dockerfile: Dockerfile.goreleaser
207+
use: buildx
208+
build_flag_templates:
209+
- "--platform=linux/amd64"
210+
- "--label=org.opencontainers.image.version={{.Version}}"
211+
- "--label=org.opencontainers.image.created={{.Date}}"
212+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
213+
extra_files:
214+
- pg_exporter.yml
215+
- LICENSE
216+
217+
- id: pg_exporter_arm64
218+
ids:
219+
- pg_exporter
220+
goos: linux
221+
goarch: arm64
222+
image_templates:
223+
- "pgsty/pg_exporter:{{ .Version }}-arm64"
224+
- "pgsty/pg_exporter:latest-arm64"
225+
dockerfile: Dockerfile.goreleaser
226+
use: buildx
227+
build_flag_templates:
228+
- "--platform=linux/arm64"
229+
- "--label=org.opencontainers.image.version={{.Version}}"
230+
- "--label=org.opencontainers.image.created={{.Date}}"
231+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
232+
extra_files:
233+
- pg_exporter.yml
234+
- LICENSE
235+
236+
docker_manifests:
237+
- name_template: "pgsty/pg_exporter:{{ .Version }}"
238+
image_templates:
239+
- "pgsty/pg_exporter:{{ .Version }}-amd64"
240+
- "pgsty/pg_exporter:{{ .Version }}-arm64"
241+
- name_template: "pgsty/pg_exporter:latest"
242+
image_templates:
243+
- "pgsty/pg_exporter:latest-amd64"
244+
- "pgsty/pg_exporter:latest-arm64"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# syntax=docker/dockerfile:1
2-
FROM golang:1.24-alpine AS builder-env
2+
FROM golang:1.25-alpine AS builder-env
33

44
# Build a self-contained pg_exporter container with a clean environment and no
55
# dependencies.

Dockerfile.goreleaser

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Dockerfile for goreleaser
2+
# This uses pre-built binaries from goreleaser instead of building from source
3+
FROM scratch
4+
5+
LABEL org.opencontainers.image.authors="Ruohang Feng <rh@vonng.com>" \
6+
org.opencontainers.image.url="https://github.com/pgsty/pg_exporter" \
7+
org.opencontainers.image.source="https://github.com/pgsty/pg_exporter" \
8+
org.opencontainers.image.licenses="Apache-2.0" \
9+
org.opencontainers.image.title="pg_exporter" \
10+
org.opencontainers.image.description="PostgreSQL/Pgbouncer metrics exporter for Prometheus"
11+
12+
WORKDIR /bin
13+
COPY pg_exporter /bin/pg_exporter
14+
COPY pg_exporter.yml /etc/pg_exporter.yml
15+
COPY LICENSE /LICENSE
16+
17+
EXPOSE 9630/tcp
18+
ENTRYPOINT ["/bin/pg_exporter"]

0 commit comments

Comments
 (0)