Skip to content

Commit

Permalink
docs: document release process
Browse files Browse the repository at this point in the history
+ add helper script
  • Loading branch information
alexgarel committed Jan 8, 2025
1 parent 765d796 commit 20e33a4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/dev/how-to-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# How to release

## Staging environment

This is automatically done by the CI of github,
see `.github/workflows/container-build.yml`.

The deployment uses docker compose with specific environments variables
and the `docker/prod.yml` overlay.

As soon as you merge a pull request in the `main` branch,
the action is triggered. You can see it at
https://github.com/openfoodfacts/openfoodfacts-server/actions/workflows/container-build.yml

## Production environment

Product Opener is deployed on a container in Proxmox.
The container is a debian server, it must follow the `backend` container version.

In the command lines, I use $SERVICE and $VERSION variables,
corresponding to the service short name (off, opf, etc.) and the version tag.

To deploy you need to execute the following steps:
1. merge the Release Please pull request.
This will create a new release / version tag on github
1. update the code:
```bash
sudo -u off bash
cd /srv/$SERVICE
git fetch
git checkout $VERSION
```
1. update the frontend assets you just downloaded
```bash
sudo -u off /srv/$SERVICE/scripts/deploy/install-dist-files.sh
```
1. restart services
```bash
sudo systemctl daemon-reload
sudo systemctl restart nginx apache2
sudo systemctl restart cloud_vision_ocr@$SERVICE.service
```
47 changes: 47 additions & 0 deletions scripts/deploy/install-dist-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# this script is a helper for deployment
# it downloads the assets for a version and extracts them
# It must be followed by install-dist-files.sh which will install files


# fail on error
set -e

if [[ -z "$1" ]]
then
echo "Usage: $0 <version> [<instance short name>]"
echo "ex: $0 v2.53.0 off"
echo "If <instance short name> is not provided, it will be the server name"
exit 2
fi

VERSION=$1

if [[ -n $2 ]]
then
SERVICE=$2
else
SERVICE=$(hostname)
fi

if [[ $(whoami) != off ]]
then
echo "This script must be run as the off user"
exit 3
fi

echo "Downloading dist files $VERSION for $SERVICE"
# get archive and untar
curl --fail --location https://github.com/openfoodfacts/openfoodfacts-server/releases/download/$VERSION/frontend-dist.tgz -o /tmp/frontend-dist.tgz
rm -rf /srv/$SERVICE-dist/tmp/$VERSION || true
mkdir -p /srv/$SERVICE-dist/tmp/$VERSION
tar --directory=/srv/$SERVICE-dist/tmp/$VERSION -xzf /tmp/frontend-dist.tgz
# remove old files
rm -rf /srv/$SERVICE-dist/tmp/old || true
mkdir /srv/$SERVICE-dist/tmp/old
# swap current version and old version
shopt -s extglob # extended globbing
mv /srv/$SERVICE-dist/!(tmp) /srv/$SERVICE-dist/tmp/old
mv /srv/$SERVICE-dist/tmp/$VERSION/* /srv/$SERVICE-dist/
rmdir /srv/$SERVICE-dist/tmp/$VERSION

0 comments on commit 20e33a4

Please sign in to comment.