Skip to content

Commit

Permalink
Merge pull request #34 from steadybit/build/linuxpackages
Browse files Browse the repository at this point in the history
build: add linux packages build
  • Loading branch information
joshiste authored Jul 14, 2023
2 parents 05dd3cd + c912c84 commit 67998c0
Show file tree
Hide file tree
Showing 19 changed files with 494 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/dist
/coverageout
/.github
/.idea
*.iml
/.vscode
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ jobs:
with:
fetch-depth: 0

- name: Remove non-semver tags (from helmchart) for goreleaser to work properly
run: |
git tag -d $(git tag -l | grep -v "^v[0-9]*.[0-9]*.[0-9]*")
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

Expand Down Expand Up @@ -98,6 +102,64 @@ jobs:
VERSION=${{ steps.meta.outputs.version }}
REVISION=${{ github.sha }}
build-packages:
name: Build Linux Packages
needs:
- audit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Remove non-semver tags (from helmchart) for goreleaser to work properly
run: |
git tag -d $(git tag -l | grep -v "^v[0-9]*.[0-9]*.[0-9]*")
- uses: actions/setup-go@v4
with:
go-version: '^1.20.0'

- name: Export GPG key
run: |
mkdir -p gpg
echo -n "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}" > gpg.key
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean ${{ !startsWith(github.ref, 'refs/tags/') && '--snapshot' || '' }}
env:
NFPM_KEY_FILE: gpg.key
NFPM_DEFAULT_PASSPHRASE: ${{ secrets.MAVEN_GPG_PRIVATE_KEY_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}

- name: "[build] Upload packages to internal repositories"
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: |
REPO_USER="${{ secrets.STEADYBIT_ARTIFACT_SERVER_USERNAME }}:${{ secrets.STEADYBIT_ARTIFACT_SERVER_PASSWORD }}"
echo "Uploading deb packages to artifacts server"
find ./dist -name '*.deb' -type f | xargs -i curl -u "$REPO_USER" -X POST -H "Content-Type: multipart/form-data" --data-binary "@{}" https://artifacts.steadybit.io/repository/deb-internal/
echo "Uploading rpm packages to artifacts server"
find ./dist -name '*.rpm' -type f | xargs -i curl -u "$REPO_USER" --upload-file {} https://artifacts.steadybit.io/repository/yum-internal/
- name: "[release] Upload packages to public repositories"
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
REPO_USER="${{ secrets.STEADYBIT_ARTIFACT_SERVER_USERNAME }}:${{ secrets.STEADYBIT_ARTIFACT_SERVER_PASSWORD }}"
echo "Uploading deb packages to artifacts server"
find ./dist -name '*.deb' -type f | xargs -i curl -u "$REPO_USER" -X POST -H "Content-Type: multipart/form-data" --data-binary "@{}" https://artifacts.steadybit.io/repository/deb/
echo "Uploading rpm packages to artifacts server"
find ./dist -name '*.rpm' -type f | xargs -i curl -u "$REPO_USER" --upload-file {} https://artifacts.steadybit.io/repository/yum/
echo "Invalidating artifacts server cache"
curl -X POST -u $REPO_USER https://artifacts.steadybit.io/service/rest/v1/repositories/yum-proxy/invalidate-cache
curl -X POST -u $REPO_USER https://artifacts.steadybit.io/service/rest/v1/repositories/yum-public/invalidate-cache
curl -X POST -u $REPO_USER https://artifacts.steadybit.io/service/rest/v1/repositories/deb-public/invalidate-cache
test-helm-charts:
name: "Test Helm Charts"
runs-on: ubuntu-latest
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extension-kong

*.iml
/extension
/coverage.out
/e2e/e2e-coverage-docker.out
/gpg.key
/dist
73 changes: 73 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
project_name: steadybit-extension-kong
before:
hooks:
- go mod download
release:
prerelease: "false"
builds:
- binary: extension-kong
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
flags:
- -cover={{ if index .Env "BUILD_WITH_COVERAGE" }}{{ .Env.BUILD_WITH_COVERAGE }}{{ else }}false{{ end }}
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-kong"
file_name_template: "{{ .ConventionalFileName }}"
formats:
- deb
- rpm
maintainer: "Johannes Edmeier <[email protected]>"
description: |
Steadybit Extension Container
vendor: "steadybit GmbH"
homepage: "https://steadybit.com"
license: "Steadybit license"
builds:
- steadybit-extension-kong
bindir: /opt/steadybit/extension-kong
contents:
- src: ./linuxpkg/systemd
dst: /usr/lib/systemd/system
- src: ./linuxpkg/init.d
dst: /etc/init.d
- src: ./linuxpkg/config
dst: /etc
type: config

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
19 changes: 5 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
##
## Build
##
FROM golang:1.20-alpine AS build
FROM goreleaser/goreleaser:v1.19.2 AS build

ARG NAME
ARG VERSION
ARG REVISION
ARG BUILD_WITH_COVERAGE

WORKDIR /app

Expand All @@ -17,17 +15,11 @@ RUN go mod download

COPY . .

RUN 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

RUN goreleaser build --snapshot --single-target -o extension
##
## Runtime
##
FROM alpine:3.16
FROM alpine:3.17

ARG USERNAME=steadybit
ARG USER_UID=10000
Expand All @@ -40,7 +32,6 @@ WORKDIR /

COPY --from=build /app/extension /extension

EXPOSE 8084
EXPOSE 8085
EXPOSE 8084 8085

ENTRYPOINT ["/extension"]
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ chartlint:
## 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 @@ -58,4 +57,8 @@ run: tidy build
## container: build the container image
.PHONY: container
container:
docker build -t extension-kong:latest .
docker buildx build --build-arg BUILD_WITH_COVERAGE="true" -t extension-kong:latest --output=type=docker .

.PHONY: linuxpkg
linuxpkg:
goreleaser release --clean --snapshot --skip-sign
Binary file added extension-kong
Binary file not shown.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.6.3
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.4
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.3.0
github.com/steadybit/extension-kit v1.7.19
github.com/steadybit/extension-kit v1.8.2
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.21.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ github.com/steadybit/action-kit/go/action_kit_sdk v1.1.4 h1:3N3STdye1D7/1P/DgK6a
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.4/go.mod h1:fRKc0RTkFljjzGA20kfinw0f1hDScWVpJM7KONmdl50=
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.3.0 h1:HwvovoYbAYpJ5PnMeiJUgrjwVkV5EpveAjeHH9pPDMQ=
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.3.0/go.mod h1:OnIfjrBhmMQCYxriHmr8mT1wCpvqIZxwBHWnanFhgNA=
github.com/steadybit/extension-kit v1.7.19 h1:bP9BxdHG5DtIv7hWt1H1jrGf3lLvIcX0hzSA5+uB7RA=
github.com/steadybit/extension-kit v1.7.19/go.mod h1:zC5Tw+wrJTx4xvOlsIY+MfMoRYoglj83vR15Xr3aP5c=
github.com/steadybit/extension-kit v1.8.2 h1:g3JahmtXchPiOZ9mERqtCHmxEWgQ3GKvhhTJVSznc3Q=
github.com/steadybit/extension-kit v1.8.2/go.mod h1:rgMxJhheOSIMgTiqAHpzfjfc+fjMm5h6gzuMWCzBq4w=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
8 changes: 8 additions & 0 deletions linuxpkg/config/logrotate.d/steadybit-extension-kong
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/var/log/steadybit-extension-kong.log {
copytruncate
size 10m
create 700 steadybit steadybit
dateext
rotate 5
compress
}
12 changes: 12 additions & 0 deletions linuxpkg/config/steadybit/extension-kong
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
STEADYBIT_LOG_LEVEL=info
STEADYBIT_LOG_FORMAT=text
STEADYBIT_EXTENSION_UNIX_SOCKET=/run/steadybit/extension-kong.sock
#
# TODO:
# Please configure your kon instances
# For more information visit https:/steadybit/extension-kong
#
STEADYBIT_EXTENSION_KONG_INSTANCE_0_NAME=
STEADYBIT_EXTENSION_KONG_INSTANCE_0_ORIGIN=
STEADYBIT_EXTENSION_KONG_INSTANCE_0_HEADER_KEY=
STEADYBIT_EXTENSION_KONG_INSTANCE_0_HEADER_VALUE=
4 changes: 4 additions & 0 deletions linuxpkg/config/steadybit/extensions.d/extension-kong.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unixSocket: /run/steadybit/extension-kong.sock
types:
- ACTION
- DISCOVERY
99 changes: 99 additions & 0 deletions linuxpkg/init.d/steadybit-extension-kong
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/sh
#
# Copyright 2023 steadybit GmbH. All rights reserved.
#

### BEGIN INIT INFO
# Provides: steadybit-extension-kong
# 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 Kong
# chkconfig: 2345 99 01
### END INIT INFO

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

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

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 67998c0

Please sign in to comment.