diff --git a/docs/dev/how-to-deploy.md b/docs/dev/how-to-deploy.md deleted file mode 100644 index 503e8ad4c33d0..0000000000000 --- a/docs/dev/how-to-deploy.md +++ /dev/null @@ -1,22 +0,0 @@ -# How to deploy to Prod environment - -Note: prod deployment is very manual and not automated yet. - -- Login to the off1 server, as the "off" user -- cd /home/off/openfoodfacts-server -- Check that you are on the main branch -- git pull -- Copy changed files (don't copy everything, in particular not the lang directory that is being moved to the openfoodfacts-web repository) -- e.g. cp cgi scripts lib po taxonomies templates /srv/off/ -- cd /srv/off -- export NPM_CONFIG_PREFIX=~/.npm-global -- npm install -- npm run build -- cd /srv/off/cgi -- export PERL5LIB=. -- ./build_lang.pl -- as the root user: -- systemctl stop apache2@off -- systemctl start apache2@off -- systemctl stop minion-off -- systemctl start minion-off diff --git a/docs/dev/how-to-release.md b/docs/dev/how-to-release.md new file mode 100644 index 0000000000000..e071d6d7d988b --- /dev/null +++ b/docs/dev/how-to-release.md @@ -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 + ``` diff --git a/env/setenv.sh b/env/setenv.sh index 07d07b9eb1a8e..7afe4068d0cd8 100755 --- a/env/setenv.sh +++ b/env/setenv.sh @@ -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 diff --git a/scripts/deploy/install-dist-files.sh b/scripts/deploy/install-dist-files.sh new file mode 100755 index 0000000000000..fe41525235006 --- /dev/null +++ b/scripts/deploy/install-dist-files.sh @@ -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 []" + echo "ex: $0 v2.53.0 off" + echo "If 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 \ No newline at end of file