From 040e74e8f2c960a5494c8134113b48105edb0f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Thu, 12 Dec 2024 10:33:24 +0100 Subject: [PATCH] chore: enable fetching product updates from Redis --- .env | 4 ++++ .github/workflows/container-deploy.yml | 11 +++++++++++ Makefile | 8 +++++++- docker-compose.yml | 11 +++++++++++ docker/prod.yml | 6 ++++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 4f03f4ca..32c6f1b5 100644 --- a/.env +++ b/.env @@ -3,6 +3,10 @@ COMPOSE_PATH_SEPARATOR=; # dev is default target COMPOSE_FILE=docker-compose.yml;docker/dev.yml +# for dev only: connection to local product opener network and for Product Opener redis +# in staging +COMMON_NET_NAME=po_default + SECRET_KEY=key DEBUG=True diff --git a/.github/workflows/container-deploy.yml b/.github/workflows/container-deploy.yml index 3a65517b..786fd93f 100644 --- a/.github/workflows/container-deploy.yml +++ b/.github/workflows/container-deploy.yml @@ -40,6 +40,8 @@ jobs: echo "CSRF_TRUSTED_ORIGINS=https://prices.openfoodfacts.net" >> $GITHUB_ENV # Triton server is on the same datacenter as the staging server, so we use the internal IP echo "TRITON_URI=10.1.0.200:5504" >> $GITHUB_ENV + echo "REDIS_HOST=redis.po_webnet" >> $GITHUB_ENV + echo "REDIS_PORT=6379" >> $GITHUB_ENV - name: Set various variable for production deployment if: matrix.env == 'open-prices-org' run: | @@ -49,6 +51,8 @@ jobs: # Triton server is on Moji datacenter, so we use the stunnel client running # on the OVH datacenter to access it echo "TRITON_URI=10.1.0.101:5504" >> $GITHUB_ENV + echo "REDIS_HOST=10.1.0.113" >> $GITHUB_ENV + echo "REDIS_PORT=6379" >> $GITHUB_ENV - name: Wait for docker image container build workflow uses: tomchv/wait-my-workflow@v1.1.0 id: wait-build @@ -115,6 +119,10 @@ jobs: echo "COMPOSE_PROJECT_NAME=open_prices" >> .env echo "COMPOSE_PATH_SEPARATOR=;" >> .env echo "COMPOSE_FILE=docker-compose.yml;docker/prod.yml" >> .env + # This is the network shared with Product Opener. + # In staging, Product Opener is deployed on the same VM. + # In production Product Opener is deployed on a separate server and is not dockerized. + echo "COMMON_NET_NAME=po_webnet" >> .env # Set docker variables echo "TAG=sha-${{ github.sha }}" >> .env echo "RESTART_POLICY=always" >> .env @@ -138,6 +146,9 @@ jobs: echo "GOOGLE_GEMINI_API_KEY=${{ secrets.GOOGLE_GEMINI_API_KEY }}" >> .env echo "TRITON_URI=${{ env.TRITON_URI }}" >> .env echo "ENABLE_ML_PREDICTIONS=True" >> .env + echo "REDIS_HOST=${{ env.REDIS_HOST }}" >> .env + echo "REDIS_PORT=${{ env.REDIS_PORT }}" >> .env + echo "ENABLE_REDIS_UPDATES=True" >> .env - name: Create Docker volumes uses: appleboy/ssh-action@master diff --git a/Makefile b/Makefile index 6d61a4d5..faf81e3f 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ export USER_UID:=${UID} export DOCKER_BUILDKIT=1 export COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_COMPOSE=docker compose --env-file=${ENV_FILE} -DOCKER_COMPOSE_TEST=COMPOSE_PROJECT_NAME=open_prices_test docker compose --env-file=${ENV_FILE} +DOCKER_COMPOSE_TEST=COMPOSE_PROJECT_NAME=open_prices_test COMMON_NET_NAME=po_test docker compose --env-file=${ENV_FILE} # avoid target corresponding to file names, to depends on them .PHONY: * @@ -152,6 +152,12 @@ create_external_volumes: docker volume create open_prices_images docker volume create open_prices_data-dump +create_external_networks: + @echo "🥫 Creating external networks if needed … (dev only)" + ( docker network create ${COMMON_NET_NAME} || true ) +# for tests + ( docker network create po_test || true ) + cp-static-files: @echo "🥫 Copying static files from api container to the host …" docker cp open_prices-api-1:/opt/open-prices/static www/ diff --git a/docker-compose.yml b/docker-compose.yml index a0fa88a5..c1084b64 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,7 @@ x-api-common: &api-common - REDIS_LATEST_ID_KEY networks: - default + - common_net services: api: @@ -97,3 +98,13 @@ volumes: name: ${COMPOSE_PROJECT_NAME:-open_prices}_home_cache static: name: ${COMPOSE_PROJECT_NAME:-open_prices}_static + + +networks: + default: + name: ${COMPOSE_PROJECT_NAME:-open_prices}_default + + # this is the network shared with product opener, it's only used in staging (and locally) + common_net: + name: ${COMMON_NET_NAME} + external: true diff --git a/docker/prod.yml b/docker/prod.yml index 0d41a230..c84d668a 100644 --- a/docker/prod.yml +++ b/docker/prod.yml @@ -11,3 +11,9 @@ volumes: data-dump: external: true name: ${COMPOSE_PROJECT_NAME:-open_prices}_data-dump + + +networks: + common_net: + name: ${COMMON_NET_NAME} + external: true