automatically build deb and rpm Linux packages

The packages are built after each tag/commit

Fixes #176
This commit is contained in:
Nicola Murino
2020-09-26 14:07:24 +02:00
parent 4ebedace1e
commit 03bf595525
9 changed files with 281 additions and 1 deletions

View File

@@ -24,6 +24,8 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
@@ -106,6 +108,29 @@ jobs:
name: sftpgo-${{ matrix.os }}-go${{ matrix.go }} name: sftpgo-${{ matrix.os }}-go${{ matrix.go }}
path: output path: output
- name: Build Linux Packages
id: build_linux_pkgs
if: ${{ matrix.upload-coverage && startsWith(matrix.os, 'ubuntu-') }}
run: |
cd pkgs
./build.sh
PKG_VERSION=$(cat dist/version)
echo "::set-output name=pkg-version::${PKG_VERSION}"
- name: Upload Debian Package
if: ${{ matrix.upload-coverage && startsWith(matrix.os, 'ubuntu-') }}
uses: actions/upload-artifact@v2
with:
name: sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-x86_64-deb
path: pkgs/dist/deb/*
- name: Upload RPM Package
if: ${{ matrix.upload-coverage && startsWith(matrix.os, 'ubuntu-') }}
uses: actions/upload-artifact@v2
with:
name: sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-x86_64-rpm
path: pkgs/dist/rpm/*
test-postgresql-mysql: test-postgresql-mysql:
name: Test with PostgreSQL/MySQL name: Test with PostgreSQL/MySQL
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -182,4 +207,4 @@ jobs:
- name: Run golangci-lint - name: Run golangci-lint
uses: golangci/golangci-lint-action@v1 uses: golangci/golangci-lint-action@v1
with: with:
version: v1.30 version: v1.31

View File

@@ -176,6 +176,17 @@ jobs:
SFTPGO_VERSION: ${{ steps.get_version.outputs.VERSION }} SFTPGO_VERSION: ${{ steps.get_version.outputs.VERSION }}
OS: ${{ steps.get_os_name.outputs.OS }} OS: ${{ steps.get_os_name.outputs.OS }}
- name: Prepare Linux Packages
id: build_linux_pkgs
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
cd pkgs
./build.sh
PKG_VERSION=${SFTPGO_VERSION:1}
echo "::set-output name=pkg-version::${PKG_VERSION}"
env:
SFTPGO_VERSION: ${{ steps.get_version.outputs.VERSION }}
- name: Prepare Release for Windows - name: Prepare Release for Windows
if: startsWith(matrix.os, 'windows-') if: startsWith(matrix.os, 'windows-')
run: | run: |
@@ -256,3 +267,25 @@ jobs:
asset_path: ./sftpgo_portable_x86_64.zip asset_path: ./sftpgo_portable_x86_64.zip
asset_name: sftpgo_${{ steps.get_version.outputs.VERSION }}_${{ steps.get_os_name.outputs.OS }}_portable_x86_64.zip asset_name: sftpgo_${{ steps.get_version.outputs.VERSION }}_${{ steps.get_os_name.outputs.OS }}_portable_x86_64.zip
asset_content_type: application/zip asset_content_type: application/zip
- name: Upload Debian Package
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.upload_url.outputs.url }}
asset_path: ./pkgs/dist/deb/sftpgo_${{ steps.build_linux_pkgs.outputs.pkg-version }}-1_amd64.deb
asset_name: sftpgo_${{ steps.build_linux_pkgs.outputs.pkg-version }}-1_amd64.deb
asset_content_type: application/vnd.debian.binary-package
- name: Upload RPM Package
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.upload_url.outputs.url }}
asset_path: ./pkgs/dist/rpm/sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-1.x86_64.rpm
asset_name: sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-1.x86_64.rpm
asset_content_type: application/x-rpm

109
pkgs/build.sh Executable file
View File

@@ -0,0 +1,109 @@
#!/bin/bash
NFPM_VERSION=1.8.0
if [ -z ${SFTPGO_VERSION} ]
then
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
NUM_COMMITS_FROM_TAG=$(git rev-list ${LATEST_TAG}.. --count)
#COMMIT_HASH=$(git rev-parse --short HEAD)
VERSION=$(echo "${LATEST_TAG}" | awk -F. -v OFS=. '{$NF++;print}')-dev.${NUM_COMMITS_FROM_TAG}
else
VERSION=${SFTPGO_VERSION}
fi
mkdir dist
echo -n ${VERSION} > dist/version
cd dist
BASE_DIR="../.."
echo "SFTPGO_HTTPD__TEMPLATES_PATH=/usr/share/sftpgo/templates" > sftpgo.env
echo "SFTPGO_HTTPD__STATIC_FILES_PATH=/usr/share/sftpgo/static" >> sftpgo.env
echo "SFTPGO_HTTPD__BACKUPS_PATH=/var/lib/sftpgo/backups" >> sftpgo.env
echo "SFTPGO_DATA_PROVIDER__CREDENTIALS_PATH=/var/lib/sftpgo/credentials" >> sftpgo.env
cp ../../sftpgo.json .
sed -i 's/sftpgo.db/\/var\/lib\/sftpgo\/sftpgo.db/g' sftpgo.json
$BASE_DIR/sftpgo gen completion bash > sftpgo-completion.bash
$BASE_DIR/sftpgo gen man -d man1
cat >nfpm.yaml <<EOF
name: "sftpgo"
arch: "amd64"
platform: "linux"
version: ${VERSION}
release: 1
section: "default"
priority: "extra"
maintainer: "Nicola Murino <nicola.murino@gmail.com>"
provides:
- sftpgo
description: |
SFTPGo is a fully featured and highly configurable
SFTP server with optional FTP/S and WebDAV support.
It can serve local filesystem, S3, GCS
vendor: "SFTPGo"
homepage: "https://github.com/drakkan/sftpgo"
license: "GPL-3.0"
files:
${BASE_DIR}/sftpgo: "/usr/bin/sftpgo"
./sftpgo.env: "/etc/sftpgo/sftpgo.env"
./sftpgo-completion.bash: "/etc/bash_completion.d/sftpgo-completion.bash"
./man1/*: "/usr/share/man/man1/"
${BASE_DIR}/init/sftpgo.service: "/lib/systemd/system/sftpgo.service"
${BASE_DIR}/examples/rest-api-cli/sftpgo_api_cli.py: "/usr/bin/sftpgo_api_cli"
${BASE_DIR}/templates/*: "/usr/share/sftpgo/templates/"
${BASE_DIR}/static/*: "/usr/share/sftpgo/static/"
${BASE_DIR}/static/css/*: "/usr/share/sftpgo/static/css/"
${BASE_DIR}/static/js/*: "/usr/share/sftpgo/static/js/"
${BASE_DIR}/static/vendor/bootstrap/js/*: "/usr/share/sftpgo/static/vendor/bootstrap/js/"
${BASE_DIR}/static/vendor/datatables/*: "/usr/share/sftpgo/static/vendor/datatables/"
${BASE_DIR}/static/vendor/fontawesome-free/css/*: "/usr/share/sftpgo/static/vendor/fontawesome-free/css/"
${BASE_DIR}/static/vendor/fontawesome-free/svgs/solid/*: "/usr/share/sftpgo/static/vendor/fontawesome-free/svgs/solid/"
${BASE_DIR}/static/vendor/fontawesome-free/webfonts/*: "/usr/share/sftpgo/static/vendor/fontawesome-free/webfonts/"
${BASE_DIR}/static/vendor/jquery/*: "/usr/share/sftpgo/static/vendor/jquery/"
${BASE_DIR}/static/vendor/jquery-easing/*: "/usr/share/sftpgo/static/vendor/jquery-easing/"
${BASE_DIR}/static/vendor/moment/js/*: "/usr/share/sftpgo/static/vendor/moment/js/"
${BASE_DIR}/static/vendor/tempusdominus/css/*: "/usr/share/sftpgo/static/vendor/tempusdominus/css/"
${BASE_DIR}/static/vendor/tempusdominus/js/*: "/usr/share/sftpgo/static/vendor/tempusdominus/js/"
config_files:
./sftpgo.json: "/etc/sftpgo/sftpgo.json"
empty_folders:
- /var/lib/sftpgo
overrides:
deb:
recommends:
- bash-completion
- python3-requests
scripts:
postinstall: ../scripts/deb/postinstall.sh
preremove: ../scripts/deb/preremove.sh
postremove: ../scripts/deb/postremove.sh
rpm:
recommends:
- bash-completion
# centos 8 has python3-requests, centos 6/7 python-requests
scripts:
postinstall: ../scripts/rpm/postinstall
preremove: ../scripts/rpm/preremove
postremove: ../scripts/rpm/postremove
rpm:
compression: lzma
config_noreplace_files:
./sftpgo.json: "/etc/sftpgo/sftpgo.json"
EOF
curl --retry 5 --retry-delay 2 --connect-timeout 10 -L -O \
https://github.com/goreleaser/nfpm/releases/download/v${NFPM_VERSION}/nfpm_${NFPM_VERSION}_Linux_x86_64.tar.gz
tar xvf nfpm_1.8.0_Linux_x86_64.tar.gz nfpm
chmod 755 nfpm
mkdir deb
./nfpm -f nfpm.yaml pkg -p deb -t deb
mkdir rpm
./nfpm -f nfpm.yaml pkg -p rpm -t rpm

View File

@@ -0,0 +1,53 @@
#!/bin/sh
set -e
if [ "$1" = "configure" ]; then
# Add user and group
if ! getent group sftpgo >/dev/null; then
groupadd --system sftpgo
fi
if ! getent passwd sftpgo >/dev/null; then
useradd --system \
--gid sftpgo \
--no-create-home \
--home-dir /var/lib/sftpgo \
--shell /usr/sbin/nologin \
--comment "SFTPGo user" \
sftpgo
fi
if [ -z "$2" ]; then
# initialize data provider
/usr/bin/sftpgo initprovider -c /etc/sftpgo
# ensure files and folders have the appropriate permissions
chown -R sftpgo:sftpgo /etc/sftpgo /var/lib/sftpgo
chmod 750 /etc/sftpgo /var/lib/sftpgo
chmod 640 /etc/sftpgo/sftpgo.json /etc/sftpgo/sftpgo.env
echo "Please be sure to have the python3-requests package installed if you want to use the REST API CLI"
fi
fi
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask sftpgo.service >/dev/null || true
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled sftpgo.service; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable sftpgo.service >/dev/null || true
deb-systemd-invoke start sftpgo.service >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state sftpgo.service >/dev/null || true
fi
# Restart only if it was already started
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -n "$2" ]; then
deb-systemd-invoke try-restart sftpgo.service >/dev/null || true
fi
fi
fi

View File

@@ -0,0 +1,19 @@
#!/bin/sh
set -e
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
fi
if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask sftpgo.service >/dev/null || true
fi
fi
if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge sftpgo.service >/dev/null || true
deb-systemd-helper unmask sftpgo.service >/dev/null || true
fi
fi

View File

@@ -0,0 +1,6 @@
#!/bin/sh
set -e
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
deb-systemd-invoke stop sftpgo.service >/dev/null || true
fi

View File

@@ -0,0 +1,25 @@
if [ $1 -eq 1 ]; then
# Initial installation
# Add user and group
if ! getent group sftpgo >/dev/null; then
/usr/sbin/groupadd --system sftpgo
fi
if ! getent passwd sftpgo >/dev/null; then
/usr/sbin/useradd --system \
--gid sftpgo \
--no-create-home \
--home-dir /var/lib/sftpgo \
--shell /sbin/nologin \
--comment "SFTPGo user" \
sftpgo
fi
# initialize data provider
/usr/bin/sftpgo initprovider -c /etc/sftpgo
# ensure files and folders have the appropriate permissions
/usr/bin/chown -R sftpgo:sftpgo /etc/sftpgo /var/lib/sftpgo
/usr/bin/chmod 750 /etc/sftpgo /var/lib/sftpgo
/usr/bin/chmod 640 /etc/sftpgo/sftpgo.json /etc/sftpgo/sftpgo.env
echo "Please be sure to have the python requests library installed if you want to use the REST API CLI"
fi
# reload to pick up any changes to systemd files
/bin/systemctl daemon-reload >/dev/null 2>&1 || :

View File

@@ -0,0 +1,5 @@
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ]; then
# Package upgrade, not uninstall
/bin/systemctl try-restart sftpgo.service >/dev/null 2>&1 || :
fi

View File

@@ -0,0 +1,5 @@
if [ $1 -eq 0 ]; then
# Package removal, not upgrade
/bin/systemctl --no-reload disable sftpgo.service >/dev/null 2>&1 || :
/bin/systemctl stop sftpgo.service >/dev/null 2>&1 || :
fi