Skip to content

Commit 6449b55

Browse files
Create CI github workflow (#2)
Refactor Dockerfile and create github workflow for image build
1 parent 7d56f3f commit 6449b55

File tree

8 files changed

+223
-2817
lines changed

8 files changed

+223
-2817
lines changed

.github/workflows/build-and-push.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Image Build
2+
run-name: "Build: ${{ github.ref_name }}"
3+
4+
on:
5+
push:
6+
tags:
7+
- v*
8+
9+
env:
10+
AWS_REGION: eu-central-1
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
id-token: write
17+
contents: read
18+
steps:
19+
- name: Checkout current tag
20+
uses: actions/checkout@v4
21+
22+
- name: Configure AWS Credentials
23+
uses: aws-actions/configure-aws-credentials@v4
24+
with:
25+
role-to-assume: ${{ secrets.AWS_GITHUB_ROLE }}
26+
aws-region: ${{ env.AWS_REGION }}
27+
28+
- name: Login to Amazon ECR
29+
id: login-ecr
30+
uses: aws-actions/amazon-ecr-login@v2
31+
with:
32+
registries: ${{ secrets.AWS_ECR }}
33+
34+
- name: Build, tag, and push docker image to Amazon ECR
35+
env:
36+
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
37+
REPOSITORY: ${{ vars.REPOSITORY }}
38+
IMAGE_TAG: ${GITHUB_REF_NAME#v}
39+
run: |
40+
docker build -t $REGISTRY/$REPOSITORY:${{ env.IMAGE_TAG }} .
41+
docker push $REGISTRY/$REPOSITORY:${{ env.IMAGE_TAG }}

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ jobs:
6464
# make release
6565

6666
- name: Perform CodeQL Analysis
67-
uses: github/codeql-action/analyze@v2
67+
uses: github/codeql-action/analyze@v2

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ jobs:
6363
version: latest
6464
args: release --rm-dist
6565
env:
66-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ jobs:
8686
- name: Upload Anchore scan SARIF report
8787
uses: github/codeql-action/upload-sarif@v2
8888
with:
89-
sarif_file: ${{ steps.scan.outputs.sarif }}
89+
sarif_file: ${{ steps.scan.outputs.sarif }}

.github/workflows/test_push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ jobs:
8686
- name: Upload Anchore scan SARIF report
8787
uses: github/codeql-action/upload-sarif@v2
8888
with:
89-
sarif_file: ${{ steps.scan.outputs.sarif }}
89+
sarif_file: ${{ steps.scan.outputs.sarif }}

Dockerfile

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
FROM alpine:3.20.3
2-
3-
ARG BUILD_DATE
4-
ARG VCS_REF
5-
ARG VERSION
6-
7-
COPY php-fpm_exporter /
8-
9-
EXPOSE 9253
10-
ENTRYPOINT [ "/php-fpm_exporter", "server" ]
11-
12-
LABEL org.label-schema.build-date=$BUILD_DATE \
13-
org.label-schema.name="php-fpm_exporter" \
14-
org.label-schema.description="A prometheus exporter for PHP-FPM." \
15-
org.label-schema.url="https://hipages.com.au/" \
16-
org.label-schema.vcs-ref=$VCS_REF \
17-
org.label-schema.vcs-url="https://github.com/hipages/php-fpm_exporter" \
18-
org.label-schema.vendor="hipages" \
19-
org.label-schema.version=$VERSION \
20-
org.label-schema.schema-version="1.0" \
21-
org.label-schema.docker.cmd="docker run -it --rm -e PHP_FPM_SCRAPE_URI=\"tcp://127.0.0.1:9000/status\" hipages/php-fpm_exporter"
1+
ARG GO_VERSION=1.23 \
2+
ALPINE_VERSION=3.21.2
3+
4+
FROM golang:${GO_VERSION}-alpine AS builder
5+
6+
ENV GOOS=linux \
7+
GOARCH=amd64
8+
9+
COPY . /app
10+
11+
WORKDIR /app
12+
13+
RUN go mod download
14+
15+
RUN go build -o php-fpm-exporter .
16+
17+
FROM alpine:${ALPINE_VERSION}
18+
19+
COPY --from=builder /app/php-fpm-exporter .
20+
21+
EXPOSE 9253
22+
23+
ENTRYPOINT [ "/php-fpm-exporter", "server" ]

go.mod

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,85 @@ module github.com/hipages/php-fpm_exporter
33
require (
44
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
55
github.com/gosuri/uitable v0.0.4
6-
github.com/mattn/go-runewidth v0.0.8 // indirect
76
github.com/mitchellh/go-homedir v1.1.0
87
github.com/prometheus/client_golang v1.20.5
98
github.com/sirupsen/logrus v1.9.3
109
github.com/spf13/cobra v1.8.0
1110
github.com/spf13/viper v1.19.0
1211
github.com/stretchr/testify v1.10.0
1312
github.com/tomasen/fcgi_client v0.0.0-20180423082037-2bb3d819fd19
13+
k8s.io/api v0.32.0
14+
k8s.io/apimachinery v0.32.0
15+
k8s.io/client-go v0.32.0
16+
)
17+
18+
require (
19+
github.com/beorn7/perks v1.0.1 // indirect
20+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
21+
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
22+
github.com/fatih/color v1.15.0 // indirect
23+
github.com/fsnotify/fsnotify v1.7.0 // indirect
24+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
25+
github.com/go-logr/logr v1.4.2 // indirect
26+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
27+
github.com/go-openapi/jsonreference v0.20.2 // indirect
28+
github.com/go-openapi/swag v0.23.0 // indirect
29+
github.com/gogo/protobuf v1.3.2 // indirect
30+
github.com/golang/protobuf v1.5.4 // indirect
31+
github.com/google/gnostic-models v0.6.8 // indirect
32+
github.com/google/go-cmp v0.6.0 // indirect
33+
github.com/google/gofuzz v1.2.0 // indirect
34+
github.com/google/uuid v1.6.0 // indirect
35+
github.com/hashicorp/hcl v1.0.0 // indirect
36+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
37+
github.com/josharian/intern v1.0.0 // indirect
38+
github.com/json-iterator/go v1.1.12 // indirect
39+
github.com/klauspost/compress v1.17.9 // indirect
40+
github.com/magiconair/properties v1.8.7 // indirect
41+
github.com/mailru/easyjson v0.7.7 // indirect
42+
github.com/mattn/go-colorable v0.1.13 // indirect
43+
github.com/mattn/go-isatty v0.0.19 // indirect
44+
github.com/mattn/go-runewidth v0.0.8 // indirect
45+
github.com/mitchellh/mapstructure v1.5.0 // indirect
46+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
47+
github.com/modern-go/reflect2 v1.0.2 // indirect
48+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
49+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
50+
github.com/pkg/errors v0.9.1 // indirect
51+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
52+
github.com/prometheus/client_model v0.6.1 // indirect
53+
github.com/prometheus/common v0.55.0 // indirect
54+
github.com/prometheus/procfs v0.15.1 // indirect
55+
github.com/sagikazarmark/locafero v0.4.0 // indirect
56+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
57+
github.com/sourcegraph/conc v0.3.0 // indirect
58+
github.com/spf13/afero v1.11.0 // indirect
59+
github.com/spf13/cast v1.6.0 // indirect
60+
github.com/spf13/pflag v1.0.5 // indirect
61+
github.com/subosito/gotenv v1.6.0 // indirect
62+
github.com/x448/float16 v0.8.4 // indirect
63+
go.uber.org/atomic v1.9.0 // indirect
64+
go.uber.org/multierr v1.9.0 // indirect
65+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
66+
golang.org/x/net v0.30.0 // indirect
67+
golang.org/x/oauth2 v0.23.0 // indirect
68+
golang.org/x/sys v0.26.0 // indirect
69+
golang.org/x/term v0.25.0 // indirect
70+
golang.org/x/text v0.19.0 // indirect
71+
golang.org/x/time v0.7.0 // indirect
72+
google.golang.org/protobuf v1.35.1 // indirect
73+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
74+
gopkg.in/inf.v0 v0.9.1 // indirect
75+
gopkg.in/ini.v1 v1.67.0 // indirect
76+
gopkg.in/yaml.v3 v3.0.1 // indirect
77+
k8s.io/klog/v2 v2.130.1 // indirect
78+
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
79+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
80+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
81+
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
82+
sigs.k8s.io/yaml v1.4.0 // indirect
1483
)
1584

16-
go 1.13
85+
go 1.23.0
86+
87+
toolchain go1.23.4

0 commit comments

Comments
 (0)