Skip to content

Commit

Permalink
docs: document release process (#11210)
Browse files Browse the repository at this point in the history
+ add helper script
  • Loading branch information
alexgarel authored Jan 9, 2025
1 parent a35d15a commit d996a33
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 23 deletions.
22 changes: 0 additions & 22 deletions docs/dev/how-to-deploy.md

This file was deleted.

55 changes: 55 additions & 0 deletions docs/dev/how-to-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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. verify every needed symlink is in place
```bash
sudo -u off scripts/deploy/verify-deployment.sh $SERVICE
```
1. rebuild taxonomies and lang
```bash
sudo -u off bash
cd /srv/$SERVICE
source env/setenv.sh $SERVICE
./scripts/taxonomies/build_tags_taxonomy.pl
./scripts/build_lang.pl
```
1. update the frontend assets you just downloaded
```bash
sudo -u off /srv/$SERVICE/scripts/deploy/install-dist-files.sh $VERSION $SERVICE
```
1. restart services
```bash
sudo systemctl daemon-reload
sudo systemctl restart nginx
sudo systemctl stop apache2 cloud_vision_ocr@$SERVICE.service minion@$SERVICE.service
sudo systemctl start apache2 cloud_vision_ocr@$SERVICE.service minion@$SERVICE.service
```
8 changes: 7 additions & 1 deletion env/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ MINION_QUEUE=
# Load environment variables from env file
source env/env.$1

# Set a variable that we use in Makefile to add an extra env file
# Set a variable that we use in Makefile to add an extra env file
# in addition to .env when we run docker compose
EXTRA_ENV_FILE=env/env.$1
LOAD_EXTRA_ENV_FILE=--env-file=env/env.$1

# eventually add lib for prod environment
if [[ -d /srv/$1/lib ]]
then
PERL5LIB=/srv/$1/lib
fi

set +o allexport

# add (env) to the prompt
Expand Down
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 d996a33

Please sign in to comment.