From 9f5fb86f90a046f6702b2c0904b49ab7870c04b7 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 31 Oct 2022 09:51:47 -0600 Subject: [PATCH] Add NFPM packaging recipe --- .gitignore | 1 + Jenkinsfile | 49 ++++++++++++++++++++++++++ Makefile | 12 +++++++ misc/ci/Dockerfile | 9 +++++ misc/packaging/postgres-backup.service | 10 ++++++ misc/packaging/postgres-backup.timer | 9 +++++ nfpm.yml | 39 ++++++++++++++++++++ 7 files changed, 129 insertions(+) create mode 100644 .gitignore create mode 100644 Jenkinsfile create mode 100644 Makefile create mode 100644 misc/ci/Dockerfile create mode 100644 misc/packaging/postgres-backup.service create mode 100644 misc/packaging/postgres-backup.timer create mode 100644 nfpm.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e22129 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/dist \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..23e5641 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,49 @@ +@Library('cadoles') _ + +pipeline { + agent { + dockerfile { + label 'docker' + filename 'Dockerfile' + dir 'misc/ci' + } + } + + stages { + stage('Build and publish packages') { + when { + anyOf { + branch 'master' + } + } + steps { + script { + List packagers = ['deb', 'rpm'] + packagers.each { pkgr -> + sh "make NFPM_PACKAGER='${pkgr}' package" + } + + List attachments = sh(returnStdout: true, script: "find dist -type f -name '*.deb' -or -name '*.rpm' -or -name '*.ipk'").split(' ') + String releaseVersion = sh(returnStdout: true, script: "git describe --always | rev | cut -d '/' -f 1 | rev").trim() + + String releaseBody = """ + _Publication automatisée réalisée par Jenkins._ [Voir le job](${env.RUN_DISPLAY_URL}) + """ + + gitea.release('forge-jenkins', 'Cadoles', 'postgres-backup', [ + 'attachments': attachments, + 'body': releaseBody, + 'releaseName': "${releaseVersion}", + 'releaseVersion': "${releaseVersion}" + ]) + } + } + } + } + + post { + always { + cleanWs() + } + } +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3082e50 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +PACKAGE_VERSION ?= $(shell git describe --always | rev | cut -d '/' -f 1 | rev) +NFPM_PACKAGER ?= deb + +package: dist + PACKAGE_VERSION=$(PACKAGE_VERSION) \ + nfpm package \ + --config nfpm.yml \ + --target ./dist \ + --packager $(NFPM_PACKAGER) + +dist: + mkdir -p dist \ No newline at end of file diff --git a/misc/ci/Dockerfile b/misc/ci/Dockerfile new file mode 100644 index 0000000..0b19ff0 --- /dev/null +++ b/misc/ci/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.15 + +RUN apk add --no-cache make git curl jq bash openssl + +RUN curl -k https://forge.cadoles.com/Cadoles/Jenkins/raw/branch/master/resources/com/cadoles/common/add-letsencrypt-ca.sh | bash + +RUN wget https://github.com/goreleaser/nfpm/releases/download/v2.20.0/nfpm_2.20.0_Linux_x86_64.tar.gz \ + && tar -xzf nfpm_2.20.0_Linux_x86_64.tar.gz -C /usr/local/bin \ + && chmod +x /usr/local/bin/nfpm \ No newline at end of file diff --git a/misc/packaging/postgres-backup.service b/misc/packaging/postgres-backup.service new file mode 100644 index 0000000..a3547b1 --- /dev/null +++ b/misc/packaging/postgres-backup.service @@ -0,0 +1,10 @@ +[Unit] +Description=Run PostgreSQL backup + +[Service] +Type=oneshot +ExecStart=/usr/bin/pg_backup_rotated.sh -c /etc/postgres-backup/pg_backup.conf +User=postgres + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/misc/packaging/postgres-backup.timer b/misc/packaging/postgres-backup.timer new file mode 100644 index 0000000..237a6e9 --- /dev/null +++ b/misc/packaging/postgres-backup.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Timer for periodic execution of postgres-backup service. + +[Timer] +OnCalendar=daily +Persistent=true + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/nfpm.yml b/nfpm.yml new file mode 100644 index 0000000..833192c --- /dev/null +++ b/nfpm.yml @@ -0,0 +1,39 @@ +name: "postgres-backup" +arch: "amd64" +platform: "linux" +version: "${PACKAGE_VERSION}" +section: "default" +priority: "extra" +maintainer: "Cadoles " +description: | + PostgreSQL automated backup scripts +vendor: "Cadoles" +homepage: "https://forge.cadoles.com/Cadoles/postgres-backup" +license: "AGPL-3.0" +contents: + - src: script/pg_backup.sh + dst: /usr/share/postgres-backup/pg_backup.sh + file_info: + mode: 0755 + - src: script/pg_backup_rotated.sh + dst: /usr/share/postgres-backup/pg_backup_rotated.sh + file_info: + mode: 0755 + - src: /usr/share/postgres-backup/pg_backup.sh + dst: /usr/bin/pg_backup.sh + type: symlink + - src: /usr/share/postgres-backup/pg_backup_rotated.sh + dst: /usr/bin/pg_backup_rotated.sh + type: symlink + - src: conf/pg_backup.conf + dst: /etc/postgres-backup/pg_backup.conf + type: config|noreplace + - src: misc/packaging/postgres-backup.timer + dst: /usr/lib/systemd/system/postgres-backup.timer + - src: misc/packaging/postgres-backup.service + dst: /usr/lib/systemd/system/postgres-backup.service + - dst: /var/backups/database/postgresql + type: dir + file_info: + owner: postgres + group: postgres \ No newline at end of file