Skip to content

Commit

Permalink
build: add linux packages build
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarschulte committed Jul 10, 2024
1 parent d3f9d25 commit 05b1372
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist
/coverageout
/.idea
*.iml
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ jobs:
uses: steadybit/extension-kit/.github/workflows/reusable-extension-ci.yml@main
with:
go_version: '1.22'
build_linux_packages: false
build_linux_packages: true
VERSION_BUMPER_APPID: ${{ vars.GH_APP_STEADYBIT_APP_ID }}
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
PAT_TOKEN_EXTENSION_DEPLOYER: ${{ secrets.PAT_TOKEN_EXTENSION_DEPLOYER }}
MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
MAVEN_GPG_PRIVATE_KEY_PASSWORD: ${{ secrets.MAVEN_GPG_PRIVATE_KEY_PASSWORD }}
PAT_TOKEN_GORELEASER: ${{ secrets.PAT_TOKEN }}
STEADYBIT_ARTIFACT_SERVER_USERNAME: ${{ secrets.STEADYBIT_ARTIFACT_SERVER_USERNAME }}
STEADYBIT_ARTIFACT_SERVER_PASSWORD: ${{ secrets.STEADYBIT_ARTIFACT_SERVER_PASSWORD }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
VERSION_BUMPER_SECRET: ${{ secrets.GH_APP_STEADYBIT_PRIVATE_KEY }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ extension-prometheus.iml
/e2e/e2e-coverage-docker.out
/licenses
/snyk.sarif
/gpg.key
/dist
/extension

83 changes: 83 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
project_name: steadybit-extension-prometheus
version: 2
before:
hooks:
- go mod download
- make licenses-report

release:
prerelease: "false"

git:
ignore_tags:
- steadybit-extension-prometheus-*

builds:
- binary: extension-prometheus
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
flags:
- -cover={{ if index .Env "BUILD_WITH_COVERAGE" }}{{ .Env.BUILD_WITH_COVERAGE }}{{ else }}false{{ end }}
- -covermode=atomic
ldflags:
- -s -w
- -X github.com/steadybit/extension-kit/extbuild.ExtensionName={{.ProjectName}}
- -X github.com/steadybit/extension-kit/extbuild.Version={{.Version}}
- -X github.com/steadybit/extension-kit/extbuild.Revision={{.Commit}}

archives:
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"

checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

nfpms:
- package_name: "steadybit-extension-prometheus"
file_name_template: "{{ .ConventionalFileName }}"
formats:
- deb
- rpm
maintainer: "Johannes Edmeier <[email protected]>"
description: |
Steadybit Extension Prometheus
vendor: "steadybit GmbH"
homepage: "https://steadybit.com"
license: "Steadybit license"
builds:
- steadybit-extension-prometheus
bindir: /opt/steadybit/extension-prometheus
contents:
- src: ./linuxpkg/systemd
dst: /usr/lib/systemd/system
- src: ./linuxpkg/init.d
dst: /etc/init.d
- src: ./linuxpkg/config
dst: /etc
type: config
- src: ./licenses
dst: /opt/steadybit/extension-prometheus/licenses
scripts:
preinstall: ./linuxpkg/scripts/preinstall.sh
postinstall: ./linuxpkg/scripts/postinstall.sh
preremove: ./linuxpkg/scripts/preremove.sh
postremove: ./linuxpkg/scripts/postremove.sh

rpm:
signature:
key_file: ./gpg.key
deb:
signature:
key_file: ./gpg.key
22 changes: 5 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@
##
## Build
##
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS build
FROM --platform=$BUILDPLATFORM goreleaser/goreleaser:v2.0.1 AS build

ARG TARGETOS TARGETARCH
ARG NAME
ARG VERSION
ARG REVISION
ARG ADDITIONAL_BUILD_PARAMS
ARG BUILD_WITH_COVERAGE
ARG BUILD_SNAPSHOT=true
ARG SKIP_LICENSES_REPORT=false

WORKDIR /app

RUN apk add build-base
COPY go.mod ./
COPY go.sum ./
RUN go mod download

COPY . .

RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
-ldflags="\
-X 'github.com/steadybit/extension-kit/extbuild.ExtensionName=${NAME}' \
-X 'github.com/steadybit/extension-kit/extbuild.Version=${VERSION}' \
-X 'github.com/steadybit/extension-kit/extbuild.Revision=${REVISION}'" \
-o ./extension \
${ADDITIONAL_BUILD_PARAMS}
RUN make licenses-report

RUN GOOS=$TARGETOS GOARCH=$TARGETARCH goreleaser build --snapshot="${BUILD_SNAPSHOT}" --single-target -o extension
##
## Runtime
##
Expand All @@ -49,7 +38,6 @@ WORKDIR /
COPY --from=build /app/extension /extension
COPY --from=build /app/licenses /licenses

EXPOSE 8087
EXPOSE 8088
EXPOSE 8087 8088

ENTRYPOINT ["/extension"]
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ chart-bump-version:
## build: build the extension
.PHONY: build
build:
go mod verify
go build -o=./extension
goreleaser build --clean --snapshot --single-target -o extension

## run: run the extension
.PHONY: run
Expand All @@ -84,4 +83,9 @@ run: tidy build
## container: build the container image
.PHONY: container
container:
docker build --build-arg ADDITIONAL_BUILD_PARAMS="-cover -covermode=atomic" --build-arg SKIP_LICENSES_REPORT="true" -t extension-prometheus:latest .
docker buildx build --build-arg BUILD_WITH_COVERAGE="true" -t extension-prometheus:latest --output=type=docker .

## linuxpkg: build the linux packages
.PHONY: linuxpkg
linuxpkg:
goreleaser release --clean --snapshot --skip=sign
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/elastic/go-windows v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/getkin/kin-openapi v0.125.0 // indirect
github.com/getkin/kin-openapi v0.126.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand Down Expand Up @@ -112,11 +112,11 @@ require (
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cilium/ebpf v0.15.0 h1:7NxJhNiBT3NG8pZJ3c+yfrVdHY8ScgKD27sScgjLMMk=
github.com/cilium/ebpf v0.15.0/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
github.com/containerd/containerd v1.7.18 h1:jqjZTQNfXGoEaZdW1WwPU0RqSn1Bm2Ay/KJPUuO8nao=
Expand Down Expand Up @@ -60,6 +61,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/getkin/kin-openapi v0.125.0 h1:jyQCyf2qXS1qvs2U00xQzkGCqYPhEhZDmSmVt65fXno=
github.com/getkin/kin-openapi v0.125.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/getkin/kin-openapi v0.126.0 h1:c2cSgLnAsS0xYfKsgt5oBV6MYRM/giU8/RtwUY4wyfY=
github.com/getkin/kin-openapi v0.126.0/go.mod h1:7mONz8IwmSRg6RttPu6v8U/OJ+gr+J99qSFNjPGSQqw=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down Expand Up @@ -312,6 +315,8 @@ golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down Expand Up @@ -360,6 +365,8 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand Down Expand Up @@ -387,6 +394,7 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
8 changes: 8 additions & 0 deletions linuxpkg/config/logrotate.d/steadybit-extension-prometheus
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/var/log/steadybit-extension-prometheus.log {
copytruncate
size 10m
create 700 steadybit steadybit
dateext
rotate 5
compress
}
3 changes: 3 additions & 0 deletions linuxpkg/config/steadybit/extension-prometheus
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
STEADYBIT_LOG_LEVEL=info
STEADYBIT_LOG_FORMAT=text
STEADYBIT_EXTENSION_UNIX_SOCKET=/run/steadybit/extension-prometheus.sock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unixSocket: /run/steadybit/extension-prometheus.sock
types:
- ACTION
- DISCOVERY
99 changes: 99 additions & 0 deletions linuxpkg/init.d/steadybit-extension-prometheus
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/sh
#
# Copyright 2024 steadybit GmbH. All rights reserved.
#

### BEGIN INIT INFO
# Provides: steadybit-extension-prometheus
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Steadybit Extension Prometheus
# chkconfig: 2345 99 01
### END INIT INFO

SCRIPT=/opt/steadybit/extension-prometheus/extension-prometheus
RUNAS=steadybit

PIDFILE=/var/run/steadybit-extension-prometheus.pid
LOGFILE=/var/log/steadybit-extension-prometheus.log
ENVFILE=/etc/steadybit/extension-prometheus

start() {
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service...' >&2

if [ ! -e "$LOGFILE" ]; then
touch "$LOGFILE"
if [ -n "$RUNAS" ]; then
chown "$RUNAS" "$LOGFILE"
fi
fi

if [ -f "$ENVFILE" ]; then
export $(grep -v "^#" "$ENVFILE" | xargs)
fi

su -s /bin/sh -c "$SCRIPT > \"$LOGFILE\" 2>&1 & echo \$!" $RUNAS >"$PIDFILE"
PID=$(cat "$PIDFILE")
sleep 1

if [ -z "$PID" ] || ! kill -0 "$PID" 2>/dev/null; then
echo "Service failed to start" >&2
tail -n 10 "$LOGFILE"
return 1
fi
echo 'Service started' >&2
}

stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service...' >&2
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}

status() {
if [ ! -f "$PIDFILE" ]; then
echo 'Service not running'. >&2
return 3
fi
PID=$(cat "$PIDFILE")
if ! kill -0 "$PID" 2>/dev/null; then
echo "Service not running: process $PID not found." >&2
return 1
fi

echo 'Service running'. >&2
return 0
}

case "$1" in
start)
start
;;
status)
status
;;
stop)
stop
;;
force-reload)
stop
start
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
;;
esac
Loading

0 comments on commit 05b1372

Please sign in to comment.