Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use 1Password op cli tool to set fly app secrets #101

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- A `.env.prod` template to be used with 1Password's `op` CLI tool.

### Changed

- Now using 1Password's `op` CLI tool for managing and injecting secrets when deploying to Fly.io.

## [2024.12]

### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/django_twc_project/.env.prod.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DATABASE_URL={{ postgres_uri_scheme }}://{{"{{"}} op://crunchy/{{ fly_app_name | replace("-","_") }}/username {{"}}"}}:{{"{{"}} op://crunchy/{{ fly_app_name | replace("-","_") }}/password {{"}}"}}@{{"{{"}} op://crunchy/westerveltco-db-pg{{ postgres_docker_version }}/tailscale/ip {{"}}"}}:{{"{{"}} op://crunchy/westerveltco-db-pg{{ postgres_docker_version }}/pgbouncer_port {{"}}"}}/{{"{{"}} op://crunchy/{{ fly_app_name | replace("-","_") }}/database {{"}}"}}
EMAIL_RELAY_DATABASE_URL=postgres://{{"{{"}} op://crunchy/email_relay/username {{"}}"}}:{{"{{"}} op://crunchy/email_relay/password {{"}}"}}@{{"{{"}} op://crunchy/westerveltco-db-pg{{ postgres_docker_version }}/tailscale/ip {{"}}"}}:{{"{{"}} op://crunchy/westerveltco-db-pg{{ postgres_docker_version }}/pgbouncer_port {{"}}"}}/{{"{{"}} op://crunchy/email_relay/database {{"}}"}}
SECRET_KEY={{"{{"}} op://fly/{{ fly_app_name }}/secret_key {{"}}"}}
TAILSCALE_AUTHKEY={{"{{"}} op://tailscale/flyio/secret {{"}}"}}
21 changes: 14 additions & 7 deletions src/django_twc_project/.github/workflows/deploy.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,26 @@ jobs:
runs-on: ubuntu-latest
needs: bumpver
environment: production
env:
OP_SERVICE_ACCOUNT_TOKEN: {% raw %}${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}{% endraw %}
steps:
- uses: actions/checkout@v4

- uses: 1password/load-secrets-action@v2
with:
export-env: true
env:
OP_SERVICE_ACCOUNT_TOKEN: {% raw %}${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}{% endraw %}
FLY_API_TOKEN: "op://GitHub Actions/{{ op_vault }}/FLY_API_TOKEN"
- uses: 1password/install-cli-action@v1

- uses: superfly/flyctl-actions/setup-flyctl@master

- run: flyctl deploy --remote-only
- name: Set Fly.io deployment API token
run: |
echo "FLY_API_TOKEN={{"{{"}} op://fly/{{ fly_app_name }}/fly/api_token {{"}}"}}" | op inject >> $GITHUB_ENV

- name: Stage Fly.io secrets
run: |
op inject -i .env.prod | xargs flyctl secrets set --stage

- name: Deploy to Fly.io
run: |
flyctl deploy --remote-only

sentry:
runs-on: ubuntu-latest
Expand Down