1616 # FIXME name you envs, see reuse below
1717 # it's also the name of the directory for the application
1818 - ${{ startsWith(github.ref, 'refs/tags/v') && 'off-query-org' || 'off-query-net' }}
19+ - ${{ startsWith(github.ref, 'refs/tags/v') && 'off-query-replica-org' || 'NONE' }}
20+ exclude :
21+ - env : ' NONE'
1922 environment : ${{ matrix.env }}
2023 concurrency : ${{ matrix.env }}
2124 steps :
4346 echo "POSTGRES_SHM_SIZE=512m" >> $GITHUB_ENV
4447 echo "QUERY_POSTGRES_SHARED_BUFFERS=4GB" >> $GITHUB_ENV
4548 echo "QUERY_POSTGRES_WORK_MEM=256MB" >> $GITHUB_ENV
49+
4650 - name : Set various variable for production deployment
4751 if : matrix.env == 'off-query-org'
4852 run : |
6670 echo "POSTGRES_SHM_SIZE=2g" >> $GITHUB_ENV
6771 echo "QUERY_POSTGRES_SHARED_BUFFERS=16GB" >> $GITHUB_ENV
6872 echo "QUERY_POSTGRES_WORK_MEM=1GB" >> $GITHUB_ENV
73+
74+ - name : Set various variable for prod replica deployment
75+ if : matrix.env == 'off-query-replica-org'
76+ run : |
77+ # This is deployed on Hetzner, close to superset
78+ echo "SSH_PROXY_HOST=hetzner-02.infra.openfoodfacts.org" >> $GITHUB_ENV
79+ echo "SSH_USERNAME=off" >> $GITHUB_ENV
80+ echo "SSH_PROXY_USERNAME=off" >> $GITHUB_ENV
81+ echo "SSH_HOST=10.3.0.201" >> $GITHUB_ENV
82+
83+ # we don't need to be in common net, use a specific name
84+ echo "COMMON_NET_NAME=off-query-replica-org_default" >> $GITHUB_ENV
85+
86+ # Reduce log level on production
87+ echo "LOG_LEVEL=log" >> $GITHUB_ENV
88+
89+ # Postgres config. We use memory to gain performance on reads and writes
90+ echo "POSTGRES_SHM_SIZE=2g" >> $GITHUB_ENV
91+ echo "QUERY_POSTGRES_SHARED_BUFFERS=16GB" >> $GITHUB_ENV
92+ echo "QUERY_POSTGRES_WORK_MEM=1GB" >> $GITHUB_ENV
93+
6994 - name : Wait for container build workflow
70957196 id : wait-build
@@ -110,7 +135,7 @@ jobs:
110135 # Checkout current commit SHA
111136 git checkout -qf ${{ github.sha }}
112137
113- - name : Set environment variables
138+ - name : Set common environment variables
114139 uses : appleboy/ssh-action@master
115140 with :
116141 host : ${{ env.SSH_HOST }}
@@ -130,6 +155,7 @@ jobs:
130155 echo "DOCKER_CLIENT_TIMEOUT=120" >> .env
131156 echo "COMPOSE_HTTP_TIMEOUT=120" >> .env
132157 echo "COMPOSE_PROJECT_NAME=off-query" >> .env
158+ echo "COMPOSE_PROFILES=app" >> .env
133159 echo "COMPOSE_PATH_SEPARATOR=," >> .env
134160 echo "RESTART_POLICY=always" >> .env
135161 echo "COMPOSE_FILE=docker-compose.yml" >> .env
@@ -140,6 +166,7 @@ jobs:
140166 echo "POSTGRES_USER=postgres" >> .env
141167 echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env
142168 echo "POSTGRES_DB=query" >> .env
169+ echo "POSTGRES_CONFIG_FILE=./confs/postgresql/prod.conf" >> .env
143170 echo "COMMON_NET_NAME=${{ env.COMMON_NET_NAME }}" >> .env
144171 echo "MONGO_URI=${{ env.MONGO_URI }}" >> .env
145172 echo "REDIS_URL=${{ env.REDIS_URL }}" >> .env
@@ -153,6 +180,29 @@ jobs:
153180 echo "QUERY_DATA_DIR=dbdata" >> .env
154181 echo "LOG_LEVEL=${{ env.LOG_LEVEL }}" >> .env
155182
183+ - name : Create Postgresql config file
184+ uses : appleboy/ssh-action@master
185+ with :
186+ host : ${{ env.SSH_HOST }}
187+ username : ${{ env.SSH_USERNAME }}
188+ key : ${{ secrets.SSH_PRIVATE_KEY }}
189+ proxy_host : ${{ env.SSH_PROXY_HOST }}
190+ proxy_username : ${{ env.SSH_USERNAME }}
191+ proxy_key : ${{ secrets.SSH_PRIVATE_KEY }}
192+ script : |
193+ # start from the dev file
194+ cp confs/postgresql/dev.conf confs/postgresql/prod.conf
195+ # add replication settings
196+ echo >>confs/postgresql/prod.conf <<END_CONF
197+ # replication settings
198+ wal_level=replica
199+ max_wal_senders=3
200+ # we don't set a large wal_keep_size because we will use slots
201+ max_slot_wal_keep_size=20G
202+ # this is large (current db size 140G)
203+ max_slot_wal_keep_size=100G
204+ END_CONF
205+
156206 - name : Start services
157207 uses : appleboy/ssh-action@master
158208 with :
0 commit comments