From 4fa048090ac69a0cb0604514b60b41612e30f1b2 Mon Sep 17 00:00:00 2001 From: Florian Bauer Date: Wed, 22 Jan 2025 13:32:24 +0100 Subject: [PATCH] fix: systemd stuff; pipeline; packagebuild --- .gitlab-ci.yml | 47 +++++++++++++++++++++++++++++++++++++++++++ .goreleaser.yaml | 27 +++++++++++++++++++++++++ init/ocspcrl.slice | 4 ++++ init/ocspcrl@.service | 16 +++++++++++++++ init/postinstall.sh | 3 +++ 5 files changed, 97 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 .goreleaser.yaml create mode 100644 init/ocspcrl.slice create mode 100644 init/ocspcrl@.service create mode 100755 init/postinstall.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..50ebd61 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,47 @@ +--- +stages: + - test + - release + +.go_template_defaults: + stage: test +.semver_template_defaults: + stage: release +include: + - { project: fsrvcorp/templates, file: templates/language/go.yml, ref: 1.0.10 } + - { project: fsrvcorp/templates, file: templates/release/semver.yml, ref: 1.0.10 } + +packages: + stage: release + image: goreleaser/goreleaser@sha256:f7f4c58b0259a37104ada4db42f2781883ac231e304164f1f352f8a084939dbd + script: + - git reset --hard $CI_COMMIT_SHA + - git clean -ffdx + - | + if [ -n "$CI_COMMIT_TAG" ]; then + goreleaser release --skip publish --clean + else + goreleaser release --skip publish --clean --snapshot + fi + artifacts: + paths: + - dist/*.deb + expire_in: 1 week + +deb mirror: + stage: release + image: alpine@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099 + only: + - tags + dependencies: + - packages + needs: + - packages + before_script: + - apk add --no-cache ca-certificates curl + script: + - | + for file in dist/*.deb; do + URL="$(curl --upload-file ${file} https://t.fsrv.xyz)" + curl -X POST --fail -F token=$CI_JOB_TOKEN -F "variables[PACKAGE_URL]=${URL}" -F ref=main https://ref.ci/api/v4/projects/185/trigger/pipeline + done diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..5b943a4 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,27 @@ +version: 2 + +builds: + - env: + - CGO_ENABLED=0 + flags: + - -trimpath + ldflags: + - -s + - -w + goarch: + - amd64 + - arm64 + goos: + - linux + +nfpms: + - maintainer: "Florian Bauer" + formats: + - deb + scripts: + postinstall: ./init/postinstall.sh + contents: + - src: ./init/ocspcrl@.service + dst: /etc/systemd/system/ocspcrl@.service + type: config + diff --git a/init/ocspcrl.slice b/init/ocspcrl.slice new file mode 100644 index 0000000..0a27cbb --- /dev/null +++ b/init/ocspcrl.slice @@ -0,0 +1,4 @@ +[Unit] +Description="OCSPCRL Server Instances" + +[Slice] diff --git a/init/ocspcrl@.service b/init/ocspcrl@.service new file mode 100644 index 0000000..55f101a --- /dev/null +++ b/init/ocspcrl@.service @@ -0,0 +1,16 @@ +[Unit] +Description=OCSP / CRL server %i +After=network.target +ConditionPathExists=/etc/default/ocspcrl-%i + +[Service] +IPAccounting=true +MemoryAccounting=true +Slice=ocspcrl.slice +EnvironmentFile=/etc/default/ocspcrl-%i +ExecStart=/usr/bin/ocspcrl $OCSPCRL_OPTS +ExecReload=/bin/kill -HUP $MAINPID +TimeoutStopSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/init/postinstall.sh b/init/postinstall.sh new file mode 100755 index 0000000..b43e67a --- /dev/null +++ b/init/postinstall.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +systemctl daemon-reload +systemctl restart ocspcrl.slice \ No newline at end of file