Skip to content

Commit 41d40ca

Browse files
committed
Print version and commit hash during start-up
1 parent a65a819 commit 41d40ca

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

.github/workflows/main.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish (main)
2+
3+
on:
4+
push:
5+
branches: main
6+
7+
jobs:
8+
image:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Set up QEMU
12+
uses: docker/setup-qemu-action@v1
13+
- name: Set up Docker Buildx
14+
uses: docker/setup-buildx-action@v1
15+
- name: Login to ghcr.io
16+
uses: docker/login-action@v1
17+
with:
18+
registry: ghcr.io
19+
username: ${{ github.repository_owner }}
20+
password: ${{ secrets.GITHUB_TOKEN }}
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
- name: Modify Dockerfile
24+
run: |
25+
sed -i -e "s|%VERSION%|latest|g" Dockerfile
26+
- name: Build and push
27+
id: docker_build_master
28+
uses: docker/build-push-action@v2
29+
with:
30+
context: .
31+
push: true
32+
tags: ghcr.io/snorwin/haproxy:latest
33+
platforms: linux/amd64
34+
build-args: |
35+
VERSION=main
36+
HASH=${{ github.sha }}
37+
- name: Prune ghcr images
38+
uses: vlaurin/action-ghcr-prune@main
39+
with:
40+
token: ${{ secrets.PRUNE_IMAGE_TOKEN }}
41+
container: ${{github.event.repository.name}}
42+
dry-run: false
43+
older-than: 7
44+
keep-last: 2
45+
untagged: true
46+
keep-tags-regexes: (latest|alpine|2.5|2.5-alpine|2.5.5|2.5.5-alpine)

.github/workflows/publish.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
name: Publish
1+
name: Publish Release
22

33
on:
4-
push:
5-
branches: main
64
release:
75
types:
86
- published
@@ -36,4 +34,7 @@ jobs:
3634
context: .
3735
push: true
3836
tags: ghcr.io/snorwin/haproxy:${{ matrix.tag }}
39-
platforms: linux/amd64
37+
platforms: linux/amd64
38+
build-args: |
39+
VERSION=${{ github.event.release.tag_name }}
40+
HASH=${{ github.sha }}

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
push: true
3434
tags: ghcr.io/snorwin/haproxy:${{ github.sha }}
3535
platforms: linux/amd64
36+
build-args: |
37+
VERSION=test
38+
HASH=${{ github.sha }}
3639
test:
3740
needs: image
3841
runs-on: ubuntu-latest

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
FROM golang:1.17.8-alpine3.15 as builder
2+
ARG VERSION
3+
ARG HASH
24

35
RUN mkdir /build
46
WORKDIR /build
57
COPY .. .
6-
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -a -o haproxy-reload-wrapper .
8+
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.Version=${VERSION} -X main.Hash=${HASH}" -a -o haproxy-reload-wrapper .
79

810
FROM docker.io/haproxy:%VERSION%
911

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ import (
1313
"github.com/snorwin/haproxy-reload-wrapper/pkg/utils"
1414
)
1515

16+
var (
17+
Version = "v0.0.0"
18+
Hash = ""
19+
)
20+
1621
func main() {
22+
log.Notice(fmt.Sprintf("haproxy-reload-wrapper version is %s-%s", Version, Hash))
23+
1724
// fetch the absolut path of the haproxy executable
1825
executable, err := utils.LookupExecutablePathAbs("haproxy")
1926
if err != nil {

0 commit comments

Comments
 (0)