From f03db728e7fb3b7fb4269ba5ebb8dcd1874f04c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 25 Mar 2024 16:55:24 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20deploying=20m?= =?UTF-8?q?ultiple=20environments=20(staging,=20production)=20to=20the=20s?= =?UTF-8?q?ame=20server=20(#1128)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-production.yml | 5 +++-- .github/workflows/deploy-staging.yml | 5 +++-- README.md | 6 +++++- deployment.md | 6 ++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index 6e2ecf1..3625726 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -13,6 +13,7 @@ jobs: env: ENVIRONMENT: production DOMAIN: ${{ secrets.DOMAIN_PRODUCTION }} + STACK_NAME: ${{ secrets.STACK_NAME_PRODUCTION }} SECRET_KEY: ${{ secrets.SECRET_KEY }} FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }} FIRST_SUPERUSER_PASSWORD: ${{ secrets.FIRST_SUPERUSER_PASSWORD }} @@ -25,5 +26,5 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - run: docker compose -f docker-compose.yml build - - run: docker compose -f docker-compose.yml up -d + - run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_PRODUCTION }} build + - run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_PRODUCTION }} up -d diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index cdac269..dd7bf83 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -13,6 +13,7 @@ jobs: env: ENVIRONMENT: staging DOMAIN: ${{ secrets.DOMAIN_STAGING }} + STACK_NAME: ${{ secrets.STACK_NAME_STAGING }} SECRET_KEY: ${{ secrets.SECRET_KEY }} FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }} FIRST_SUPERUSER_PASSWORD: ${{ secrets.FIRST_SUPERUSER_PASSWORD }} @@ -25,5 +26,5 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - run: docker compose -f docker-compose.yml build - - run: docker compose -f docker-compose.yml up -d + - run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_STAGING }} build + - run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_STAGING }} up -d diff --git a/README.md b/README.md index 2dfc69f..fce0bbb 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,10 @@ Before deploying it, make sure you change at least the values for: - `FIRST_SUPERUSER_PASSWORD` - `POSTGRES_PASSWORD` +You can (and should) pass these as environment variables from secrets. + +Read the [deployment.md](./deployment.md) docs for more details. + ### Generate Secret Keys Some environment variables in the `.env` file have a default value of `changethis`. @@ -196,7 +200,7 @@ But don't worry, you can just update any of that in the `.env` files afterwards. The input variables, with their default values (some auto generated) are: - `project_name`: (default: `"FastAPI Project"`) The name of the project, shown to API users (in .env). -- `stack_name`: (default: `"fastapi-project"`) The name of the stack used for Docker Compose labels (no spaces) (in .env). +- `stack_name`: (default: `"fastapi-project"`) The name of the stack used for Docker Compose labels and project name (no spaces, no periods) (in .env). - `secret_key`: (default: `"changethis"`) The secret key for the project, used for security, stored in .env, you can generate one with the method above. - `first_superuser`: (default: `"admin@example.com"`) The email of the first superuser (in .env). - `first_superuser_password`: (default: `"changethis"`) The password of the first superuser (in .env). diff --git a/deployment.md b/deployment.md index 6727d29..c749b16 100644 --- a/deployment.md +++ b/deployment.md @@ -127,6 +127,8 @@ export DOMAIN=fastapi-project.example.com You can set several variables, like: +* `PROJECT_NAME`: The name of the project, used in the API for the docs and emails. +* `STACK_NAME`: The name of the stack used for Docker Compose labels and project name, this should be different for `staging`, `production`, etc. You could use the same domain replacing dots with dashes, e.g. `fastapi-project-example-com` and `staging-fastapi-project-example-com`. * `BACKEND_CORS_ORIGINS`: A list of allowed CORS origins separated by commas. * `SECRET_KEY`: The secret key for the FastAPI project, used to sign tokens. * `FIRST_SUPERUSER`: The email of the first superuser, this superuser will be the one that can create new users. @@ -254,11 +256,15 @@ The current Github Actions workflows expect these secrets: * `DOMAIN_PRODUCTION` * `DOMAIN_STAGING` +* `STACK_NAME_PRODUCTION` +* `STACK_NAME_STAGING` * `EMAILS_FROM_EMAIL` * `FIRST_SUPERUSER` * `FIRST_SUPERUSER_PASSWORD` * `POSTGRES_PASSWORD` * `SECRET_KEY` +* `LATEST_CHANGES` +* `SMOKESHOW_AUTH_KEY` ## GitHub Action Deployment Workflows