diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 34d65d81..d10778e9 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -109,13 +109,13 @@ jobs: needs: build-deb strategy: matrix: - distro: - - debian10 - - debian11 - - debian12 - - ubuntu2004 - - ubuntu2204 - - ubuntu2404 + image: + - geerlingguy/docker-debian10-ansible:latest + - geerlingguy/docker-debian11-ansible:latest + - geerlingguy/docker-debian12-ansible:latest + - geerlingguy/docker-ubuntu2004-ansible:latest + - geerlingguy/docker-ubuntu2204-ansible:latest + - geerlingguy/docker-ubuntu2404-ansible:latest steps: - uses: actions/checkout@v4.1.7 - uses: actions/download-artifact@v4.1.8 @@ -129,7 +129,21 @@ jobs: with: molecule_working_dir: './deployment/ansible/gnomeshade' env: - MOLECULE_DISTRO: ${{ matrix.distro }} + MOLECULE_IMAGE: ${{ matrix.image }} + + test-deb: + name: Test debian package + runs-on: ubuntu-20.04 + timeout-minutes: 10 + needs: build-deb + steps: + - uses: actions/checkout@v4.1.7 + - uses: actions/download-artifact@v4.1.8 + id: download + with: + name: Gnomeshade.WebApi_linux-x64.deb + + - run: ./deployment/test-deb.sh ${{ steps.download.outputs.download-path }}/gnomeshade.deb ${{ secrets.DEMO_ADMIN_PASSWORD }} docker: name: Test docker container diff --git a/deployment/ansible/gnomeshade/molecule/default/molecule.yml b/deployment/ansible/gnomeshade/molecule/default/molecule.yml index 3bcc827b..296ee79d 100644 --- a/deployment/ansible/gnomeshade/molecule/default/molecule.yml +++ b/deployment/ansible/gnomeshade/molecule/default/molecule.yml @@ -5,7 +5,7 @@ driver: name: docker platforms: - name: instance - image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" + image: "${MOLECULE_IMAGE}" command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw diff --git a/deployment/debian.sh b/deployment/debian.sh index 2ec407fc..0b99cde5 100755 --- a/deployment/debian.sh +++ b/deployment/debian.sh @@ -23,6 +23,7 @@ strip gnomeshade/opt/gnomeshade/libe_sqlite3.so mkdir -p gnomeshade/DEBIAN cp deployment/debian/postinst gnomeshade/DEBIAN/postinst cp deployment/debian/prerm gnomeshade/DEBIAN/prerm +cp deployment/debian/postrm gnomeshade/DEBIAN/postrm export FULL_VERSION=$full_version export MAINTAINER=$maintainer @@ -46,6 +47,10 @@ mv changelog.gz $changelog_path mkdir -p gnomeshade/lib/systemd/system cp deployment/debian/gnomeshade.service gnomeshade/lib/systemd/system/gnomeshade.service +mkdir -p gnomeshade/etc/init.d +cp deployment/debian/gnomeshade gnomeshade/etc/init.d/gnomeshade +echo "/etc/init.d/gnomeshade" >>gnomeshade/DEBIAN/conffiles + dpkg-deb --root-owner-group --build gnomeshade # unstripped-binary-or-object suppressed because gnomeshade/opt/gnomeshade/Gnomeshade.WebApi diff --git a/deployment/debian/gnomeshade b/deployment/debian/gnomeshade new file mode 100755 index 00000000..ccb7bc4e --- /dev/null +++ b/deployment/debian/gnomeshade @@ -0,0 +1,124 @@ +#!/bin/bash + +### BEGIN INIT INFO +# Provides: gnomeshade +# Required-Start: $local_fs $network +# Required-Stop: $local_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Gnomeshade server +### END INIT INFO + +# Source LSB helpers +. /lib/lsb/init-functions + +# Process name (for display only) +NAME=gnomeshade + +# Where is the actual executable for the daemon +DAEMON=/opt/gnomeshade/Gnomeshade.WebApi +WORKING_DIRECTORY=/etc/opt/gnomeshade +ASPNETCORE_WEBROOT=/opt/gnomeshade/wwwroot +ENVIRONMENT=Production +DOTNET_gcServer=0 +Database__Provider="Sqlite" +ConnectionStrings__Gnomeshade="Data Source=gnomeshade.db" + +# The user:group under which the daemon must run +RUN_AS_USER=gnomeshade + +# pid file for the daemon +PIDFILE=/var/run/gnomeshade.pid + +# If the daemon is not there, then exit. +if ! [ -x ${DAEMON} ] +then + log_failure_msg "Cannot find an executable at ${DAEMON}" + exit 1 +fi + +case $1 in + start) + # Check if pidfile exists + if [ -e ${PIDFILE} ] + then + # Check the actual status of process + status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && status="0" || status="$?" + # If the status is successfully, no need to start again. + [ "${status}" = "0" ] && exit 0 + fi + # Start the daemon. + log_daemon_msg "Starting ${NAME}" + # Start the daemon with the help of start-stop-daemon + if start-stop-daemon --start --quiet --oknodo --pidfile ${PIDFILE} --make-pidfile --background \ + --chuid ${RUN_AS_USER} --chdir ${WORKING_DIRECTORY} --no-close --startas ${DAEMON} >> /var/log/gnomeshade + then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + stop) + if [ -e ${PIDFILE} ] + then + status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && status="0" || status="$?" + if [ "$status" = "0" ]; then + log_daemon_msg "Stopping ${NAME}" + if start-stop-daemon -K --signal TERM --quiet --oknodo --pidfile ${PIDFILE} + then + log_end_msg 0 + rm -rf ${PIDFILE} + else + log_end_msg 1 + fi + fi + else + log_daemon_msg "${NAME} is not running" + log_end_msg 0 + fi + ;; + restart) + $0 stop && sleep 3 && $0 start + ;; + status) + # Check the status of the process. + if [ -e ${PIDFILE} ] + then + status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && exit 0 || exit $? + else + log_daemon_msg "${NAME} is not running (no pidfile)" + log_end_msg 0 + fi + ;; + reload) + if [ -e ${PIDFILE} ]; then + log_daemon_msg "Reloading ${NAME}" + if start-stop-daemon -K --quiet --signal HUP --pidfile ${PIDFILE} + then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_failure_msg "Cannot find pidfile at ${PIDFILE}" + fi + ;; + force-reload) + if [ -e ${PIDFILE} ]; then + log_daemon_msg "Reloading ${NAME}" + if start-stop-daemon -K --quiet --signal HUP --pidfile ${PIDFILE} + then + log_end_msg 0 + else + log_end_msg 1 + fi + else + log_failure_msg "Cannot find pidfile at ${PIDFILE}" + fi + ;; + *) + # Invalid argument, print the usage message. + echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" + exit 2 + ;; +esac diff --git a/deployment/debian/postinst b/deployment/debian/postinst index 71a760be..b4c7f23c 100755 --- a/deployment/debian/postinst +++ b/deployment/debian/postinst @@ -3,11 +3,13 @@ set -e GNOMESHADE_USER=gnomeshade -if [[ -z "$(getent group ${GNOMESHADE_USER})" ]]; then +if [[ -z "$(getent group ${GNOMESHADE_USER})" ]] +then addgroup --system ${GNOMESHADE_USER} fi -if [[ -z "$(getent passwd ${GNOMESHADE_USER})" ]]; then +if [[ -z "$(getent passwd ${GNOMESHADE_USER})" ]] +then adduser \ --system --ingroup ${GNOMESHADE_USER} ${GNOMESHADE_USER} \ --no-create-home --home /nonexistent \ @@ -17,4 +19,9 @@ fi chown gnomeshade /etc/opt/gnomeshade --recursive chown gnomeshade /opt/gnomeshade --recursive -deb-systemd-invoke enable gnomeshade.service +if [[ $(systemctl) =~ -\.mount ]] +then + deb-systemd-invoke enable gnomeshade.service +else + update-rc.d gnomeshade defaults +fi diff --git a/deployment/debian/postrm b/deployment/debian/postrm new file mode 100755 index 00000000..89760e8c --- /dev/null +++ b/deployment/debian/postrm @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +if [[ $(systemctl) =~ -\.mount ]] +then + exit +else + update-rc.d gnomeshade remove +fi diff --git a/deployment/debian/prerm b/deployment/debian/prerm index 08727411..e703ecdd 100755 --- a/deployment/debian/prerm +++ b/deployment/debian/prerm @@ -1,4 +1,9 @@ #!/bin/bash set -e -deb-systemd-invoke stop gnomeshade.service +if [[ $(systemctl) =~ -\.mount ]] +then + deb-systemd-invoke stop gnomeshade.service +else + exit +fi diff --git a/deployment/docker/devuan/daedalus/Dockerfile b/deployment/docker/devuan/daedalus/Dockerfile new file mode 100644 index 00000000..f45d9359 --- /dev/null +++ b/deployment/docker/devuan/daedalus/Dockerfile @@ -0,0 +1,8 @@ +FROM devuan/devuan:daedalus + +COPY gnomeshade.deb /gnomeshade.deb + +RUN apt-get update && apt-get install -y libicu72 libssl3 libgssapi-krb5-2 +RUN dpkg -i /gnomeshade.deb + +EXPOSE 5000 diff --git a/deployment/docker/Dockerfile b/deployment/docker/gnomeshade-build/Dockerfile similarity index 100% rename from deployment/docker/Dockerfile rename to deployment/docker/gnomeshade-build/Dockerfile diff --git a/deployment/test-deb.sh b/deployment/test-deb.sh new file mode 100755 index 00000000..0bb45749 --- /dev/null +++ b/deployment/test-deb.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e + +name="test" + +function printLogs() { + docker logs $name + docker exec $name service --status-all + docker exec $name ls -lah /opt/gnomeshade + docker exec $name ls -lah /etc/opt/gnomeshade + docker exec $name ls -lah /var/log + docker exec $name cat /var/log/gnomeshade +} + +trap printLogs EXIT + +cd ./deployment/docker/devuan/daedalus +cp "$1" ./gnomeshade.deb + +docker build --tag devuan:test ./ +docker pull devuan/devuan:daedalus +docker run --detach --name $name --publish 5000:5000 \ + --env "Admin__Password=$2" \ + devuan:test /bin/bash -c \ + "service gnomeshade start && { while true; do sleep 2; done }" + +wget --tries=10 --retry-connrefused --waitretry=10 --timeout=15 "http://localhost:5000/api/v1.0/health" + +if [[ $(cat health) != "Healthy" ]]; then + exit 1 +fi + +curl --header "Content-Type: application/json" \ + --request POST \ + --data '{"username":"john.doe", "password": "Password123!", "email": "john.doe@example.com", "fullName": "John Doe" }' \ + http://localhost:8000/Authorization/Register