✨ Add support for deploying multiple environments (staging, production) to the same server (#1128)
This commit is contained in:

committed by
GitHub

parent
4c8837c2a6
commit
f03db728e7
5
.github/workflows/deploy-production.yml
vendored
5
.github/workflows/deploy-production.yml
vendored
@@ -13,6 +13,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
ENVIRONMENT: production
|
ENVIRONMENT: production
|
||||||
DOMAIN: ${{ secrets.DOMAIN_PRODUCTION }}
|
DOMAIN: ${{ secrets.DOMAIN_PRODUCTION }}
|
||||||
|
STACK_NAME: ${{ secrets.STACK_NAME_PRODUCTION }}
|
||||||
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
||||||
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}
|
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}
|
||||||
FIRST_SUPERUSER_PASSWORD: ${{ secrets.FIRST_SUPERUSER_PASSWORD }}
|
FIRST_SUPERUSER_PASSWORD: ${{ secrets.FIRST_SUPERUSER_PASSWORD }}
|
||||||
@@ -25,5 +26,5 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- run: docker compose -f docker-compose.yml build
|
- run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_PRODUCTION }} build
|
||||||
- run: docker compose -f docker-compose.yml up -d
|
- run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_PRODUCTION }} up -d
|
||||||
|
5
.github/workflows/deploy-staging.yml
vendored
5
.github/workflows/deploy-staging.yml
vendored
@@ -13,6 +13,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
ENVIRONMENT: staging
|
ENVIRONMENT: staging
|
||||||
DOMAIN: ${{ secrets.DOMAIN_STAGING }}
|
DOMAIN: ${{ secrets.DOMAIN_STAGING }}
|
||||||
|
STACK_NAME: ${{ secrets.STACK_NAME_STAGING }}
|
||||||
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
SECRET_KEY: ${{ secrets.SECRET_KEY }}
|
||||||
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}
|
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}
|
||||||
FIRST_SUPERUSER_PASSWORD: ${{ secrets.FIRST_SUPERUSER_PASSWORD }}
|
FIRST_SUPERUSER_PASSWORD: ${{ secrets.FIRST_SUPERUSER_PASSWORD }}
|
||||||
@@ -25,5 +26,5 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- run: docker compose -f docker-compose.yml build
|
- run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_STAGING }} build
|
||||||
- run: docker compose -f docker-compose.yml up -d
|
- run: docker compose -f docker-compose.yml --project-name ${{ secrets.STACK_NAME_STAGING }} up -d
|
||||||
|
@@ -135,6 +135,10 @@ Before deploying it, make sure you change at least the values for:
|
|||||||
- `FIRST_SUPERUSER_PASSWORD`
|
- `FIRST_SUPERUSER_PASSWORD`
|
||||||
- `POSTGRES_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
|
### Generate Secret Keys
|
||||||
|
|
||||||
Some environment variables in the `.env` file have a default value of `changethis`.
|
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:
|
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).
|
- `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.
|
- `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`: (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).
|
- `first_superuser_password`: (default: `"changethis"`) The password of the first superuser (in .env).
|
||||||
|
@@ -127,6 +127,8 @@ export DOMAIN=fastapi-project.example.com
|
|||||||
|
|
||||||
You can set several variables, like:
|
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.
|
* `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.
|
* `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.
|
* `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_PRODUCTION`
|
||||||
* `DOMAIN_STAGING`
|
* `DOMAIN_STAGING`
|
||||||
|
* `STACK_NAME_PRODUCTION`
|
||||||
|
* `STACK_NAME_STAGING`
|
||||||
* `EMAILS_FROM_EMAIL`
|
* `EMAILS_FROM_EMAIL`
|
||||||
* `FIRST_SUPERUSER`
|
* `FIRST_SUPERUSER`
|
||||||
* `FIRST_SUPERUSER_PASSWORD`
|
* `FIRST_SUPERUSER_PASSWORD`
|
||||||
* `POSTGRES_PASSWORD`
|
* `POSTGRES_PASSWORD`
|
||||||
* `SECRET_KEY`
|
* `SECRET_KEY`
|
||||||
|
* `LATEST_CHANGES`
|
||||||
|
* `SMOKESHOW_AUTH_KEY`
|
||||||
|
|
||||||
## GitHub Action Deployment Workflows
|
## GitHub Action Deployment Workflows
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user