From 61e3ce30f5377ff20a0930afccc1989447f73dc0 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Tue, 16 Apr 2024 19:50:54 +0200 Subject: [PATCH 1/4] Build packages for releases --- .gitignore | 3 ++ LICENSE.md => LICENSE | 0 assets/packages/default | 3 ++ assets/packages/hareply.service | 15 +++++++ assets/packages/post-install.sh | 4 ++ assets/packages/post-uninstall.sh | 3 ++ assets/packages/pre-uninstall.sh | 4 ++ goreleaser.yml | 66 ++++++++++++++++++++++++++++++- 8 files changed, 96 insertions(+), 2 deletions(-) rename LICENSE.md => LICENSE (100%) create mode 100644 assets/packages/default create mode 100644 assets/packages/hareply.service create mode 100755 assets/packages/post-install.sh create mode 100755 assets/packages/post-uninstall.sh create mode 100755 assets/packages/pre-uninstall.sh diff --git a/.gitignore b/.gitignore index d0dc2a2..e03fadb 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ # Go workspace file go.work +# Goreleaser dist output file +dist/ + agentstate \ No newline at end of file diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/assets/packages/default b/assets/packages/default new file mode 100644 index 0000000..1b37d05 --- /dev/null +++ b/assets/packages/default @@ -0,0 +1,3 @@ +# Options for hareply + +HAREPLY_FILE='/etc/hareply/agentstate' diff --git a/assets/packages/hareply.service b/assets/packages/hareply.service new file mode 100644 index 0000000..4e545be --- /dev/null +++ b/assets/packages/hareply.service @@ -0,0 +1,15 @@ +[Unit] +Description=hareply +After=syslog.target network-online.target + +[Service] +Environment="PIDFILE=/run/hareply.pid" +EnvironmentFile=/etc/default/hareply +ExecStart=/usr/sbin/hareply +ExecReload=/bin/kill -s SIGUSR1 $MAINPID +Type=simple +PIDFile= +GuessMainPID=1 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/assets/packages/post-install.sh b/assets/packages/post-install.sh new file mode 100755 index 0000000..06f66d8 --- /dev/null +++ b/assets/packages/post-install.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +systemctl --system daemon-reload || true +systemctl enable hareply || true diff --git a/assets/packages/post-uninstall.sh b/assets/packages/post-uninstall.sh new file mode 100755 index 0000000..4c0c884 --- /dev/null +++ b/assets/packages/post-uninstall.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +systemctl --system daemon-reload || true diff --git a/assets/packages/pre-uninstall.sh b/assets/packages/pre-uninstall.sh new file mode 100755 index 0000000..785f0e5 --- /dev/null +++ b/assets/packages/pre-uninstall.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +systemctl stop hareply || true +systemctl disable hareply || true diff --git a/goreleaser.yml b/goreleaser.yml index 43b5ca4..0842ce7 100644 --- a/goreleaser.yml +++ b/goreleaser.yml @@ -1,6 +1,8 @@ project_name: hareply builds: - - binary: hareply + - + id: hareply-build + binary: hareply goos: - linux - darwin @@ -11,7 +13,10 @@ builds: ldflags: - -s -w -X github.com/friendlycaptcha/hareply/buildinfo.version={{.Version}} -X github.com/friendlycaptcha/hareply/buildinfo.commit={{.Commit}} -X github.com/friendlycaptcha/hareply/buildinfo.commitDate={{.CommitDate}} archives: - - id: hareply-archive + - + id: hareply-archive + builds: + - hareply-build name_template: >- {{ .ProjectName }}_ {{- .Tag }}_ @@ -20,3 +25,60 @@ archives: format_overrides: - goos: windows format: zip + files: + - LICENSE + - README.md +nfpms: + - + id: hareply-package + package_name: hareply + builds: + - hareply-build + file_name_template: >- + {{ .ProjectName }}_ + {{- .Tag }}_ + {{- .Os }}_ + {{- .Arch}} + vendor: Friendly Captcha GmbH + homepage: https://github.com/friendlycaptcha/hareply + maintainer: Guido Zuidhof + description: "hareply - responder for HAProxy's agent-check" + license: MIT + formats: + - apk + - deb + - rpm + bindir: /usr/sbin + section: net + priority: optional + contents: + - dst: /etc/hareply + type: dir + file_info: + owner: root + group: root + mode: 0750 + - src: assets/packages/hareply.service + dst: /etc/systemd/system/hareply.service + type: config + file_info: + owner: root + group: root + mode: 0640 + - src: assets/packages/default + dst: /etc/default/hareply + type: config + file_info: + owner: root + group: root + mode: 0640 + scripts: + postinstall: "assets/packages/post-install.sh" + preremove: "assets/packages/pre-uninstall.sh" + postremove: "assets/packages/post-uninstall.sh" + deb: + lintian_overrides: + - statically-linked-binary + - changelog-file-missing-in-native-package +snapshot: + name_template: "{{ .Tag }}-next" \ No newline at end of file From dcea3eebb73425d97a79e5f2ca7d2d4a01940b26 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Wed, 17 Apr 2024 11:04:35 +0200 Subject: [PATCH 2/4] Minor doc improvements --- .gitignore | 2 +- README.md | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e03fadb..85fb504 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ # Go workspace file go.work -# Goreleaser dist output file +# Goreleaser dist output files dist/ agentstate \ No newline at end of file diff --git a/README.md b/README.md index 9beba84..7fb036b 100644 --- a/README.md +++ b/README.md @@ -29,5 +29,13 @@ hareply serve * The file is read again on any TCP connection, if that fails the last known file contents are used. * If the value in the file is not a valid response for `agent-check`, the last valid response is returned instead. +## Release +Releases are built using `goreleaser`, see the [`goreleaser.yml`](./goreleaser.yml) file. + +To mint a (test) release locally, install [goreleaser](https://goreleaser.com/install/) and run +```shell +goreleaser --snapshot --skip=publish --clean +``` + ## License [MIT](./LICENSE.md) [🎶](https://suno.com/song/da6d4a83-1001-4694-8c28-648a6e8bad0a). \ No newline at end of file From b5ca4e48945cf400c4a90d3b1cd1fe5b85d89a17 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Wed, 17 Apr 2024 11:10:56 +0200 Subject: [PATCH 3/4] Fix goreleaser CI to only run on published releases --- .github/workflows/goreleaser.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 02fb576..0705f3d 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -1,10 +1,8 @@ name: goreleaser on: - push: - branches: - - master - - main + release: + types: [published] jobs: goreleaser: From 395227211522709d96ff7e905f8d68cfd8b6c7d1 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Wed, 17 Apr 2024 11:32:38 +0200 Subject: [PATCH 4/4] Address comments, rename env file, simplify systemd --- assets/packages/default | 3 --- assets/packages/hareply.conf | 1 + assets/packages/hareply.service | 9 +++------ goreleaser.yml | 6 +++--- 4 files changed, 7 insertions(+), 12 deletions(-) delete mode 100644 assets/packages/default create mode 100644 assets/packages/hareply.conf diff --git a/assets/packages/default b/assets/packages/default deleted file mode 100644 index 1b37d05..0000000 --- a/assets/packages/default +++ /dev/null @@ -1,3 +0,0 @@ -# Options for hareply - -HAREPLY_FILE='/etc/hareply/agentstate' diff --git a/assets/packages/hareply.conf b/assets/packages/hareply.conf new file mode 100644 index 0000000..38b6fe9 --- /dev/null +++ b/assets/packages/hareply.conf @@ -0,0 +1 @@ +HAREPLY_FILE=/etc/hareply/agentstate diff --git a/assets/packages/hareply.service b/assets/packages/hareply.service index 4e545be..7cf0ef1 100644 --- a/assets/packages/hareply.service +++ b/assets/packages/hareply.service @@ -3,13 +3,10 @@ Description=hareply After=syslog.target network-online.target [Service] -Environment="PIDFILE=/run/hareply.pid" -EnvironmentFile=/etc/default/hareply -ExecStart=/usr/sbin/hareply -ExecReload=/bin/kill -s SIGUSR1 $MAINPID +EnvironmentFile=/etc/hareply/hareply.conf +ExecStart=/usr/bin/hareply +Restart=always Type=simple -PIDFile= -GuessMainPID=1 [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/goreleaser.yml b/goreleaser.yml index 0842ce7..5f3d2c8 100644 --- a/goreleaser.yml +++ b/goreleaser.yml @@ -48,7 +48,7 @@ nfpms: - apk - deb - rpm - bindir: /usr/sbin + bindir: /usr/bin section: net priority: optional contents: @@ -65,8 +65,8 @@ nfpms: owner: root group: root mode: 0640 - - src: assets/packages/default - dst: /etc/default/hareply + - src: assets/packages/hareply.conf + dst: /etc/hareply/hareply.conf type: config file_info: owner: root