Skip to content

Commit be73e1c

Browse files
committed
Resolve deploy-staging.yml and deploy-production.yml
1 parent 34bf070 commit be73e1c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.github/workflows/deploy-production.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ on:
55
types:
66
- published
77

8+
permissions: {}
9+
810
jobs:
911
deploy:
12+
environment: production
1013
# Do not deploy in the main repository, only in user projects
1114
if: github.repository_owner != 'fastapi'
1215
runs-on:
@@ -28,5 +31,7 @@ jobs:
2831
steps:
2932
- name: Checkout
3033
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
34+
with:
35+
persist-credentials: false
3136
- run: docker compose -f compose.yml --project-name ${{ secrets.STACK_NAME_PRODUCTION }} build
3237
- run: docker compose -f compose.yml --project-name ${{ secrets.STACK_NAME_PRODUCTION }} up -d

.github/workflows/deploy-staging.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ on:
55
branches:
66
- master
77

8+
permissions: {}
9+
810
jobs:
911
deploy:
12+
environment: staging
1013
# Do not deploy in the main repository, only in user projects
1114
if: github.repository_owner != 'fastapi'
1215
runs-on:
@@ -28,5 +31,7 @@ jobs:
2831
steps:
2932
- name: Checkout
3033
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
34+
with:
35+
persist-credentials: false
3136
- run: docker compose -f compose.yml --project-name ${{ secrets.STACK_NAME_STAGING }} build
3237
- run: docker compose -f compose.yml --project-name ${{ secrets.STACK_NAME_STAGING }} up -d

deployment.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,15 @@ cd /home/github/actions-runner
288288

289289
You can read more about it in the official guide: [Configuring the self-hosted runner application as a service](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/configuring-the-self-hosted-runner-application-as-a-service).
290290

291+
### Configure GitHub Environments
292+
293+
The deployment workflows use [GitHub Environments](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment) for `staging` and `production`. This enables environment-specific secrets, deployment protection rules (e.g. required reviewers, wait timers), and deployment status tracking.
294+
295+
To configure them, go to your repository's **Settings** > **Environments** and create the `staging` and `production` environments.
296+
291297
### Set Secrets
292298

293-
On your repository, configure secrets for the environment variables you need, the same ones described above, including `SECRET_KEY`, etc. Follow the [official GitHub guide for setting repository secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository).
299+
For each GitHub Environment (`staging` and `production`), configure the required secrets as [environment secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-an-environment). Environment secrets are preferred over [repository secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) because they are scoped to the specific environment, reducing exposure and aligning with any protection rules you configure.
294300

295301
The current Github Actions workflows expect these secrets:
296302

@@ -313,6 +319,8 @@ There are GitHub Action workflows in the `.github/workflows` directory already c
313319
* `staging`: after pushing (or merging) to the branch `master`.
314320
* `production`: after publishing a release.
315321

322+
Both workflows are associated with their respective GitHub Environments, so deployments will be visible in the repository's **Environments** section and will respect any protection rules you configure.
323+
316324
If you need to add extra environments you could use those as a starting point.
317325

318326
## URLs

0 commit comments

Comments
 (0)