From 9a52197d633411482442136c346347e259d1187e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blaisot?= Date: Thu, 12 Oct 2023 17:02:11 +0200 Subject: [PATCH 1/2] Add debian packaging --- .github/CODEOWNERS | 7 ++ .gitignore | 14 ++- debian/compat | 1 + debian/control | 24 +++++ debian/copyright | 19 ++++ debian/cozy-stack.conffiles | 0 debian/cozy-stack.config | 56 +++++++++++ debian/cozy-stack.install | 8 ++ debian/cozy-stack.postinst | 96 ++++++++++++++++++ debian/cozy-stack.prerm | 14 +++ debian/cozy-stack.service | 15 +++ debian/cozy-stack.syslog | 7 ++ debian/cozy-stack.templates | 119 +++++++++++++++++++++++ debian/cozy.yml | 20 ++++ debian/rules | 24 +++++ debian/source/format | 1 + debian/uninstall-onboarding.sh | 25 +++++ debian/websocket.conf | 4 + scripts/packaging/buildpackage.sh | 37 +++++++ scripts/packaging/docker_package.sh | 17 ++++ scripts/packaging/installrequirements.sh | 36 +++++++ 21 files changed, 543 insertions(+), 1 deletion(-) create mode 100755 debian/compat create mode 100755 debian/control create mode 100755 debian/copyright create mode 100755 debian/cozy-stack.conffiles create mode 100755 debian/cozy-stack.config create mode 100755 debian/cozy-stack.install create mode 100755 debian/cozy-stack.postinst create mode 100755 debian/cozy-stack.prerm create mode 100755 debian/cozy-stack.service create mode 100644 debian/cozy-stack.syslog create mode 100755 debian/cozy-stack.templates create mode 100755 debian/cozy.yml create mode 100755 debian/rules create mode 100755 debian/source/format create mode 100755 debian/uninstall-onboarding.sh create mode 100644 debian/websocket.conf create mode 100755 scripts/packaging/buildpackage.sh create mode 100755 scripts/packaging/docker_package.sh create mode 100755 scripts/packaging/installrequirements.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a5aaa415f48..635df1892e1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,3 +3,10 @@ # These owners will be the default owners for everything in the repo. * @cozy/back + +# Order is important; the last matching pattern takes the most +# precedence. When someone opens a pull request that only +# impact debian packaging files, only sblaisot and not the global +# owner(s) will be requested for a review. +debian/* @sblaisot +scripts/packaging/* @sblaisot diff --git a/.gitignore b/.gitignore index 37d3d424d30..f1e0fc01893 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ /.assets /.cozy /cozy-stack* -/debian /debug-assets node_modules /scripts/cozy-stack* @@ -14,3 +13,16 @@ tmp *.log *.enc *.dec + +# Debian packaging stuff / temporary files +/.pc/ +/bin +/packages +/debian/changelog +/debian/*.debhelper +/debian/*.log +/debian/*.substvars +/debian/files +/debian/cozy/ +/debian/cozy-stack/ +/debian/tmp/ diff --git a/debian/compat b/debian/compat new file mode 100755 index 00000000000..f599e28b8ab --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +10 diff --git a/debian/control b/debian/control new file mode 100755 index 00000000000..c9ae9529d4b --- /dev/null +++ b/debian/control @@ -0,0 +1,24 @@ +Source: cozy-stack +Section: devel +Priority: extra +Maintainer: Cozycloud Packaging Team +Build-Depends: debhelper (>= 9), dh-exec +Standards-Version: 3.9.8 +Homepage: https://github.com/cozy/cozy-stack +Vcs-Browser: https://anonscm.debian.org/cgit/pkg-go/packages/cozy-stack.git +Vcs-Git: https://anonscm.debian.org/git/pkg-go/packages/cozy-stack.git +XS-Go-Import-Path: github.com/cozy/cozy-stack + +Package: cozy-stack +Architecture: any +Depends: ${misc:Depends}, ${shlibs:Depends}, + adduser, members, curl, sed, + git, imagemagick, libprotobuf-c1, fonts-lato +Recommends: couchdb (>= 2.3), nginx, + debootstrap, lsb-release, + mail-transport-agent, nodejs (>= 16) +Description: Cozy: Simple, Versatile, Yours + Cozy (https://cozy.io) is a platform that brings all your web services + in the same private space. + . + This package installs the cozy stack. diff --git a/debian/copyright b/debian/copyright new file mode 100755 index 00000000000..2ade9849bc6 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,19 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: cozy-stack +Source: https://github.com/cozy/cozy-stack + +Files: * +Copyright: Copyright 2012, 2023 Cozy Cloud +License: AGPL-3.0-only + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + . + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . diff --git a/debian/cozy-stack.conffiles b/debian/cozy-stack.conffiles new file mode 100755 index 00000000000..e69de29bb2d diff --git a/debian/cozy-stack.config b/debian/cozy-stack.config new file mode 100755 index 00000000000..68db325d07e --- /dev/null +++ b/debian/cozy-stack.config @@ -0,0 +1,56 @@ +#!/bin/sh +set -e +. /usr/share/debconf/confmodule + +# prompt for password + confirmation until we get matching entries +# or an empty password +promptpass() { + TARGET="${1}" + PRIORITY="${2:-high}" + + while :; do + RET="" + db_input ${PRIORITY} ${TARGET} || true + db_go + db_get ${TARGET} + # if password isn't empty we ask for password verification + if [ -z "${RET}" ]; then + break + fi + PW="${RET}" + db_input ${PRIORITY} ${TARGET}_again || true + db_go + db_get ${TARGET}_again + if [ "${RET}" = "${PW}" ]; then + PW="" + break + fi + db_fset ${TARGET}_mismatch seen false + db_input critical ${TARGET}_mismatch + db_set ${TARGET} "" + db_set ${TARGET}_again "" + db_go + done +} + +prompt() { + TARGET="${1}" + PRIORITY="${2:-high}" + + db_input ${PRIORITY} ${TARGET} || true + db_go + db_get ${TARGET} +} + +prompt cozy-stack/couchdb/address +prompt cozy-stack/couchdb/nodename +prompt cozy-stack/couchdb/admin/user +promptpass cozy-stack/couchdb/admin/password +prompt cozy-stack/couchdb/cozy/user +promptpass cozy-stack/couchdb/cozy/password +promptpass cozy-stack/cozy/password + +prompt cozy-stack/address low +prompt cozy-stack/port low +prompt cozy-stack/admin/address low +prompt cozy-stack/admin/port low diff --git a/debian/cozy-stack.install b/debian/cozy-stack.install new file mode 100755 index 00000000000..6daba2c3ffc --- /dev/null +++ b/debian/cozy-stack.install @@ -0,0 +1,8 @@ +#!/usr/bin/dh-exec +bin/cozy-stack usr/bin/ +scripts/konnector-node16-run.sh => usr/share/cozy/konnector-run.sh + +debian/cozy.yml etc/cozy/ +debian/cozy-stack.syslog => etc/rsyslog.d/cozy.conf +debian/uninstall-onboarding.sh usr/share/cozy/ +debian/websocket.conf etc/nginx/conf.d/ diff --git a/debian/cozy-stack.postinst b/debian/cozy-stack.postinst new file mode 100755 index 00000000000..a37b92ad693 --- /dev/null +++ b/debian/cozy-stack.postinst @@ -0,0 +1,96 @@ +#!/bin/sh +set -e +. /usr/share/debconf/confmodule + +case $1 in +configure) + db_get cozy-stack/couchdb/address && COUCH_ADDRESS="${RET}" + db_get cozy-stack/couchdb/cozy/user && COUCH_USER="${RET}" + db_get cozy-stack/couchdb/cozy/password && COUCH_PASS="${RET}" + db_get cozy-stack/address && ADDRESS="${RET}" + db_get cozy-stack/port && PORT="${RET}" + db_get cozy-stack/admin/address && ADMIN_ADDRESS="${RET}" + db_get cozy-stack/admin/port && ADMIN_PORT="${RET}" + COUCH_URL="http://${COUCH_USER}:${COUCH_PASS}@${COUCH_ADDRESS}/" + + if [ -z "$2" ]; then + getent group cozy >/dev/null 2>&1 || \ + addgroup --quiet --system cozy + getent passwd cozy-stack >/dev/null 2>&1 || \ + adduser --quiet --system \ + --home /var/lib/cozy --no-create-home \ + --shell /usr/sbin/nologin --ingroup cozy cozy-stack + + [ -d /var/log/cozy ] || \ + install -o root -g cozy -m u=rwX,g=rwX,o= -d /var/log/cozy + + db_get cozy-stack/couchdb/nodename && COUCH_NODE="${RET}" + db_get cozy-stack/couchdb/admin/user && COUCH_ADMIN_USER="${RET}" + db_get cozy-stack/couchdb/admin/password && COUCH_ADMIN_PASS="${RET}" + ENCODED_COUCH_ADMIN_USER=$(echo "${COUCH_ADMIN_USER}" | sed -e 's/:/%3A/g') + curl -fsX PUT -u "${ENCODED_COUCH_ADMIN_USER}:${COUCH_ADMIN_PASS}" "${COUCH_ADDRESS}/_node/${COUCH_NODE}/_config/admins/${COUCH_USER}" -d "\"${COUCH_PASS}\"" >/dev/null || \ + ( + echo "=====================" >&2 + echo "Unable to create cozy user in couchdb" >&2 + echo "Check that you provided the correct couchdb admin user, password and address" >&2 + echo "You can try again by purging and reinstalling the cozy-stack package" >&2 + echo "apt-get purge cozy-stack; apt-get install cozy-stack" >&2 + echo "=====================" >&2 + ) + + if [ ! -f /etc/cozy/cozy-admin-passphrase ]; then + db_get cozy-stack/cozy/password && COZY_PASS="${RET}" + COZY_ADMIN_PASSPHRASE="${COZY_PASS}" cozy-stack config passwd /etc/cozy/cozy-admin-passphrase + printf "%s" "${COZY_PASS}" > /etc/cozy/.cozy-admin-passphrase + chmod u=rw,og= /etc/cozy/.cozy-admin-passphrase + fi + + chown cozy-stack: /etc/cozy/cozy.yml + chown cozy-stack: /etc/cozy/cozy-admin-passphrase + chown -R cozy-stack: /usr/share/cozy + + install -o cozy-stack -g cozy -m u=rwX,g=rwX,o= -d /var/lib/cozy + + [ -f /usr/sbin/rsyslogd ] && systemctl restart rsyslog + [ -f /usr/sbin/nginx ] && systemctl reload nginx + else + if [ ! -f /etc/cozy/.cozy-admin-passphrase ]; then + db_input critical cozy-stack/admin/passphrase + db_go + db_get cozy-stack/admin/passphrase && COZY_PASS="${RET}" + echo "${COZY_PASS}" > /etc/cozy/.cozy-admin-passphrase + chmod u=rw,og= /etc/cozy/.cozy-admin-passphrase + fi + + if dpkg --compare-versions "${2}" lt 2:1.2.0-1; then + /usr/share/cozy/uninstall-onboarding.sh + fi + fi + + if [ ! -f /etc/cozy/cozy.yml.local ]; then + cat > /etc/cozy/cozy.yml.local <<-EOF + host: ${ADDRESS} + port: ${PORT} + + admin: + host: ${ADMIN_ADDRESS} + port: ${ADMIN_PORT} + + couchdb: + url: ${COUCH_URL} + EOF + chown cozy-stack: /etc/cozy/cozy.yml.local + chmod u=rw,og= /etc/cozy/cozy.yml.local + fi + + if [ ! -f /etc/cozy/vault.enc ] || [ ! -f /etc/cozy/vault.dec ]; then + cozy-stack config gen-keys /etc/cozy/vault + chown cozy-stack: /etc/cozy/vault.enc /etc/cozy/vault.dec + chmod u=rw,og= /etc/cozy/vault.enc /etc/cozy/vault.dec + fi + + systemctl restart cozy-stack +;; +esac + +#DEBHELPER# diff --git a/debian/cozy-stack.prerm b/debian/cozy-stack.prerm new file mode 100755 index 00000000000..4cfa5d26245 --- /dev/null +++ b/debian/cozy-stack.prerm @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +#DEBHELPER# + +case $1 in +remove) + #rm -rf /var/lib/cozy + rm -f /etc/cozy/cozy-admin-passphrase + + getent passwd cozy-stack 2>&1 >/dev/null && deluser --quiet cozy-stack + members cozy &>/dev/null || delgroup cozy +;; +esac diff --git a/debian/cozy-stack.service b/debian/cozy-stack.service new file mode 100755 index 00000000000..c0fa05987b5 --- /dev/null +++ b/debian/cozy-stack.service @@ -0,0 +1,15 @@ +[Unit] +Description=Cozy service +Wants=couchdb.service +After=network.target couchdb.service + +[Service] +User=cozy-stack +Group=cozy +WorkingDirectory=/var/lib/cozy/ +PermissionsStartOnly=true +ExecStart=/usr/bin/cozy-stack serve +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/debian/cozy-stack.syslog b/debian/cozy-stack.syslog new file mode 100644 index 00000000000..569a59f42d5 --- /dev/null +++ b/debian/cozy-stack.syslog @@ -0,0 +1,7 @@ +if $programname == 'cozy' then { + if $syslogseverity <= '6' then /var/log/cozy/stack.log + /var/log/cozy/stack.debug.log +} +if $programname == 'cozy-stack' then { + /var/log/cozy/stack.log +} diff --git a/debian/cozy-stack.templates b/debian/cozy-stack.templates new file mode 100755 index 00000000000..45ff10ba398 --- /dev/null +++ b/debian/cozy-stack.templates @@ -0,0 +1,119 @@ +Template: cozy-stack/couchdb/address +Type: string +Default: 127.0.0.1:5984 +Description: CouchDB address: + Please enter the CouchDB address to use + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/nodename +Type: string +Default: couchdb@127.0.0.1 +Description: CouchDB nodename: + Please enter the CouchDB nodename + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/admin/user +Type: string +Default: admin +Description: CouchDB admin user: + Please enter the CouchDB admin user + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/admin/password +Type: password +Default: admin +Description: CouchDB admin password: + Please enter the CouchDB admin password + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/admin/password_again +Type: password +Default: admin +Description: CouchDB admin password (confirmation): + Please confirm the CouchDB admin password + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/admin/password_mismatch +Type: error +Description: Password input error: + The two passwords you entered were not the same. Please try again. + +Template: cozy-stack/couchdb/cozy/user +Type: string +Default: cozy +Description: CouchDB cozy user: + Please enter the CouchDB cozy username + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/cozy/password +Type: password +Default: cozy +Description: CouchDB cozy password: + Please enter the CouchDB cozy password + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/cozy/password_again +Type: password +Default: cozy +Description: CouchDB cozy password (confirmation): + Please confirm the CouchDB cozy password + . + This will be used to create a Cozy administrator on the cluster + +Template: cozy-stack/couchdb/cozy/password_mismatch +Type: error +Description: Password input error: + The two passwords you entered were not the same. Please try again. + +Template: cozy-stack/cozy/password +Type: password +Default: admin +Description: Cozy stack admin password: + Please enter the Cozy admin password + +Template: cozy-stack/cozy/password_again +Type: password +Default: admin +Description: Cozy stack admin password: + Please confirm the Cozy admin password + +Template: cozy-stack/cozy/password_mismatch +Type: error +Description: Password input error: + The two passwords you entered were not the same. Please try again. + +Template: cozy-stack/address +Type: string +Default: 127.0.0.1 +Description: Cozy stack bind address: + Your cozy stack will listen on this address + +Template: cozy-stack/port +Type: string +Default: 8080 +Description: Cozy stack bind port: + Your cozy stack will listen on this port + +Template: cozy-stack/admin/address +Type: string +Default: 127.0.0.1 +Description: Cozy stack admin bind address: + Your cozy stack admin API will listen on this address + +Template: cozy-stack/admin/port +Type: string +Default: 6060 +Description: Cozy stack admin bind port: + Your cozy stack admin API will listen on this port + +Template: cozy-stack/admin/passphrase +Type: password +Description: Cozy stack admin passphrase: + Please enter your Cozy admin passphrase diff --git a/debian/cozy.yml b/debian/cozy.yml new file mode 100755 index 00000000000..4d4090a6640 --- /dev/null +++ b/debian/cozy.yml @@ -0,0 +1,20 @@ +fs: + url: file:///var/lib/cozy + +vault: + credentials_encryptor_key: /etc/cozy/vault.enc + credentials_decryptor_key: /etc/cozy/vault.dec + +konnectors: + cmd: /usr/share/cozy/konnector-run.sh + +log: + level: info + syslog: true + +registries: + default: + - https://apps-registry.cozycloud.cc/selfhosted + - https://apps-registry.cozycloud.cc/mespapiers + - https://apps-registry.cozycloud.cc/banks + - https://apps-registry.cozycloud.cc/ diff --git a/debian/rules b/debian/rules new file mode 100755 index 00000000000..2d58a02a5d1 --- /dev/null +++ b/debian/rules @@ -0,0 +1,24 @@ +#!/usr/bin/make -f +DESTDIR := $(CURDIR)/debian/cozy-stack +export DEBIAN_VERSION := $(shell dpkg-parsechangelog -S Version) +export UPSTREAM_VERSION := $(shell echo $(DEBIAN_VERSION) | awk -F- '{print $$1}') +export BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") + +%: + dh $@ --with=systemd + +override_dh_auto_build: + go build -o $(CURDIR)/bin/cozy-stack -ldflags "\ + -X github.com/cozy/cozy-stack/pkg/config.Version=$(UPSTREAM_VERSION) \ + -X github.com/cozy/cozy-stack/pkg/config.BuildTime=$(BUILD_TIME) \ + -X github.com/cozy/cozy-stack/pkg/config.BuildMode=production" + +override_dh_clean: + dh_clean + ./scripts/build.sh clean + +#override_dh_auto_test: +#ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) +# go get -u -v github.com/stretchr/testify +# go test $(DH_GOPKG)/... +#endif diff --git a/debian/source/format b/debian/source/format new file mode 100755 index 00000000000..163aaf8d82b --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/uninstall-onboarding.sh b/debian/uninstall-onboarding.sh new file mode 100755 index 00000000000..5e73cf3247a --- /dev/null +++ b/debian/uninstall-onboarding.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +export COZY_ADMIN_PASSWORD="$(cat /etc/cozy/.cozy-admin-passphrase)" + +function app_installed { + DOMAIN="${1}" + APP="${2}" + cozy-stack apps show --domain "${DOMAIN}" "${APP}" &>/dev/null +} + +function uninstall_app { + DOMAIN="${1}" + APP="${2}" + if app_installed "${@}"; then + echo " Uninstalling app ${APP}" + cozy-stack apps uninstall --domain "${DOMAIN}" "${APP}" 1>/dev/null + else + echo " App ${APP} already uninstalled, nothing to do" + fi +} + +echo "Uninstall onboarding" +cozy-stack instances ls | awk '{print $1}' | while read domain; do + echo " Migrating ${domain}" + uninstall_app "${domain}" onboarding +done diff --git a/debian/websocket.conf b/debian/websocket.conf new file mode 100644 index 00000000000..1d89716e060 --- /dev/null +++ b/debian/websocket.conf @@ -0,0 +1,4 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} diff --git a/scripts/packaging/buildpackage.sh b/scripts/packaging/buildpackage.sh new file mode 100755 index 00000000000..e3ec83ccde9 --- /dev/null +++ b/scripts/packaging/buildpackage.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -euo pipefail + +export GOROOT="${GOROOT:-/tmp/go}" +export GOPATH="${GOPATH:-/tmp/goroot}" +export PATH="${GOPATH}/bin:$GOROOT/bin:${PATH}" + + +cd "$(dirname $0)/../.." +if [ -f debian/changelog ]; then + echo "ERROR: debian/changelog already exists" + exit 1 +fi + +echo "=============" +echo "Build package" +echo "=============" +DISTRO="$(lsb_release -sc)" +EPOCH=2 +if [ -z "${TAG_DESC:-}" ]; then + TAG_DESC="$(git describe --tags)" +fi +if [ -z "${VERSION:-}" ]; then + VERSION="$(git describe --tags --abbrev=0)" +fi +if [ -z "${RELEASE:-}" ]; then + if echo "${TAG_DESC}" | grep -q -- '-'; then + RELEASE=$(echo "${TAG_DESC}" | cut -d- -f2) + else + RELEASE="1" + fi +fi +DEBEMAIL="Cozycloud Packaging Team " dch --create --package cozy-stack --no-auto-nmu --force-distribution -D "${DISTRO}" -v "${EPOCH}:${VERSION}-${RELEASE}~${DISTRO}" --vendor cozy "release ${TAG_DESC} for ${DISTRO}" +dpkg-buildpackage -us -uc -ui -i -I.git -b +mv ../cozy-stack_* packages/ +rm -f debian/changelog diff --git a/scripts/packaging/docker_package.sh b/scripts/packaging/docker_package.sh new file mode 100755 index 00000000000..6824e895a10 --- /dev/null +++ b/scripts/packaging/docker_package.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +TARGETS="debian:10 debian:11 debian:12 ubuntu:20.04 ubuntu:22.04" + +if [ $# -ne 0 ]; then + TARGETS="$@" +fi + +SCRIPT_DIR=$(dirname $0) +STACK_DIR=$(readlink -f ${SCRIPT_DIR}/../..) + +for i in ${TARGETS}; do + echo "*** building for $i" + [ -f "${STACK_DIR}/debian/changelog" ] && rm -f "${STACK_DIR}/debian/changelog" + docker run --rm -v ${STACK_DIR}:/build $i /bin/bash -c 'echo "[safe]" > /root/.gitconfig && echo " directory = /build" >> /root/.gitconfig && cd /build && scripts/packaging/installrequirements.sh && scripts/packaging/buildpackage.sh' +done + diff --git a/scripts/packaging/installrequirements.sh b/scripts/packaging/installrequirements.sh new file mode 100755 index 00000000000..30f6a3e96ac --- /dev/null +++ b/scripts/packaging/installrequirements.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +set -euo pipefail + +GOVERSION="${GOVERSION:-1.21.3}" + +cd "$(dirname $0)/../.." +if [ -f debian/changelog ]; then + echo "ERROR: debian/changelog already exists" + exit 1 +fi + +echo "====================" +echo "Install Requirements" +echo "====================" +apt-get update +DEBIAN_FRONTEND=noninteractive apt-get install --yes devscripts lsb-release binutils fakeroot quilt devscripts dpkg-dev libdistro-info-perl equivs aptitude wget build-essential git --no-install-recommends --no-install-suggests +dpkg-checkbuilddeps || (yes y | mk-build-deps debian/control -ir) || true + +if [ -z "${SKIP_GO}" ]; then + echo "==========" + echo "Install GO" + echo "==========" + export GOROOT="${GOROOT:-/tmp/goroot}" + [ ! -d "/tmp/goroot" ] && mkdir -p "/tmp/goroot" + export GOPATH="${GOPATH:-/tmp/go}" + if [ ! -x "${GOROOT}/bin/go" ]; then + echo ". download go archive" + [ -f "go.tar.gz" ] || wget --quiet https://dl.google.com/go/go${GOVERSION}.linux-amd64.tar.gz -O /tmp/go.tar.gz + echo ". extract go archive" + [ ! -d "${GOROOT}" ] && mkdir -p "${GOROOT}" + tar xf /tmp/go.tar.gz -C "${GOROOT}" --strip-components=1 + rm -rf /tmp/go.tar.gz + fi + export PATH="${GOPATH}/bin:$GOROOT/bin:${PATH}" +fi From a7df6439cdefc4efce768d5d26e58d2ca9306d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blaisot?= Date: Fri, 13 Oct 2023 09:35:30 +0200 Subject: [PATCH 2/2] Build deb packages in CI --- .github/workflows/release.yml | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b72e0eacbd6..be4c2fec290 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Create releases on: push: tags: - - '*.*.*' # Matching a version number like 1.4.19 + - "*.*.*" # Matching a version number like 1.4.19 jobs: publish_on_release: runs-on: ubuntu-22.04 @@ -10,8 +10,8 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: '1.21.x' - - name: Check code + go-version: "1.21.x" + - name: Checkout code uses: actions/checkout@v4 - name: Build the binaries run: | @@ -31,3 +31,30 @@ jobs: password: ${{ secrets.DOCKERHUB_SECRET }} - name: Build and publish the cozy-app-dev image run: scripts/release.sh + build_deb_packages: + strategy: + matrix: + os: [debian-10, debian-11, debian-12, ubuntu-20.04, ubuntu-22.04] + runs-on: ${{ matrix.os }} + needs: publish_on_release + steps: + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: "1.21.x" + - name: Checkout code + uses: actions/checkout@v4 + - name: Install requirements + env: + SKIP_GO: "true" + run: | + scripts/packaging/installrequirements.sh + - name: Build package + run: | + scripts/packaging/buildpackage.sh + - name: Upload package to release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + tag_name="${GITHUB_REF##*/}" + gh release upload "$tag_name" packages/*.deb