-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make nutripatrol production-ready
- fix container-deploy.yml for staging deployment - add environment info to sentry (dev, staging, prod) - add peewee_migrate to apply create/apply DB migrations. - remove remaining search-a-licious specific config - expose API on port 9010
- Loading branch information
1 parent
3dfe6ae
commit 8f9bc20
Showing
13 changed files
with
218 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,15 +29,19 @@ jobs: | |
environment: ${{ matrix.env }} | ||
concurrency: ${{ matrix.env }} | ||
steps: | ||
- name: Set common variables | ||
run: | | ||
echo "SSH_PROXY_HOST=ovh1.openfoodfacts.org" >> $GITHUB_ENV | ||
echo "SSH_USERNAME=off" >> $GITHUB_ENV | ||
- name: Set various variable for staging (net) deployment | ||
if: matrix.env == 'nutripatrol-net' | ||
run: | | ||
# direct container access | ||
echo "OPENFOODFACTS_API_URL=https://off:[email protected]" >> $GITHUB_ENV | ||
# deploy target | ||
echo "SSH_HOST=10.1.0.200" >> $GITHUB_ENV | ||
echo "SSH_PROXY_HOST=ovh1.openfoodfacts.org" >> $GITHUB_ENV | ||
echo "SSH_USERNAME=off" >> $GITHUB_ENV | ||
echo "ENVIRONMENT=staging" >> $GITHUB_ENV | ||
if: matrix.env == 'nutripatrol-org' | ||
run: | | ||
echo "SSH_HOST=10.1.0.201" >> $GITHUB_ENV | ||
echo "ENVIRONMENT=prod" >> $GITHUB_ENV | ||
- name: Wait for docker image container build workflow | ||
uses: tomchv/[email protected] | ||
id: wait-build | ||
|
@@ -99,32 +103,20 @@ jobs: | |
mv .env .env-dev | ||
# init .env | ||
echo "# Env file generated by container-deploy action"> .env | ||
echo "# Env file generated by container-deploy action" > .env | ||
# Set Docker Compose variables | ||
echo "DOCKER_CLIENT_TIMEOUT=180" >> .env | ||
echo "COMPOSE_HTTP_TIMEOUT=180" >> .env | ||
echo "COMPOSE_PROJECT_NAME=nutripatrol" >> .env | ||
echo "COMPOSE_PATH_SEPARATOR=;" >> .env | ||
echo "COMPOSE_FILE=docker-compose.yml;docker/prod.yml" >> .env | ||
# Copy variables that are same as dev | ||
grep '\(STACK_VERSION\|ES_PORT\)' .env-dev >> .env | ||
# Set docker variables | ||
echo "TAG=sha-${{ github.sha }}" >> .env | ||
echo "RESTART_POLICY=always" >> .env | ||
# Set App variables | ||
echo "CLUSTER_NAME=${{ matrix.env }}-es-cluster" >> .env | ||
echo "SEARCH_PORT=8180" >> .env | ||
echo "ES_VUE_PORT=8181" >> .env | ||
echo "REDIS_PORT=8182" >> .env | ||
echo "MEM_LIMIT=4294967296" >> .env | ||
# this is the network shared with productopener | ||
echo "COMMON_NET_NAME=po_webnet">> .env | ||
echo "OPENFOODFACTS_API_URL=${{ env.OPENFOODFACTS_API_URL }}" >> .env | ||
# This secret is to be generated using htpasswd, see .env file | ||
# use simple quotes to avoid interpolation of $apr1$ ! | ||
echo 'NGINX_BASIC_AUTH_USER_PASSWD=${{ secrets.NGINX_BASIC_AUTH_USER_PASSWD }}' >> .env | ||
echo "SENTRY_DNS=${{ secrets.SENTRY_DSN }}" >> .env | ||
echo "CONFIG_PATH=data/config/openfoodfacts.yml" >> .env | ||
echo "ENVIRONMENT=${{ env.ENVIRONMENT }}" >> .env | ||
# Expose API on port 9010 | ||
echo "API_EXPOSE=0.0.0.0:9010" >> .env | ||
- name: Create Docker volumes | ||
uses: appleboy/ssh-action@master | ||
|
@@ -152,8 +144,11 @@ jobs: | |
script_stop: false | ||
script: | | ||
cd ${{ matrix.env }} | ||
docker-compose down | ||
docker-compose up -d --remove-orphans 2>&1 | ||
make pull | ||
# Apply migrations | ||
make migrate-db | ||
# Launch new version | ||
make up | ||
- name: Check services are up | ||
uses: appleboy/ssh-action@master | ||
|
@@ -183,7 +178,7 @@ jobs: | |
script_stop: false | ||
script: | | ||
cd ${{ matrix.env }} | ||
docker system prune -af | ||
make prune | ||
- uses: frankie567/[email protected] | ||
if: ${{ always() }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from app.cli import main | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import typer | ||
|
||
app = typer.Typer() | ||
|
||
|
||
@app.command() | ||
def migrate_db(): | ||
"""Run unapplied DB migrations.""" | ||
from openfoodfacts.utils import get_logger | ||
|
||
from app.models import db, run_migration | ||
|
||
get_logger() | ||
|
||
with db.connection_context(): | ||
run_migration() | ||
|
||
|
||
@app.command() | ||
def add_revision( | ||
name: str = typer.Argument(..., help="name of the revision"), | ||
): | ||
"""Create a new migration file using peewee_migrate.""" | ||
from openfoodfacts.utils import get_logger | ||
|
||
from app.models import add_revision, db | ||
|
||
get_logger() | ||
|
||
with db.connection_context(): | ||
add_revision(name) | ||
|
||
|
||
def main() -> None: | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.