Skip to content

Commit

Permalink
Add two environement variable for read and write db (#16)
Browse files Browse the repository at this point in the history
We will need to use two different variables for READ and WRITE DB URL so
this PR adds them both. Alongside the old `DATABASE_URL` to avoid having
bugs during the transition.
  • Loading branch information
Fenntasy authored Apr 6, 2023
1 parent ee2a875 commit 4e0a537
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

- name: Deploy
id: deploy
uses: fewlinesco/fly-io-review-apps@v3.4
uses: fewlinesco/fly-io-review-apps@v3.5
```
## Cleaning up GitHub environments
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Deploy app
id: deploy
uses: fewlinesco/fly-io-review-apps@v3.4
uses: fewlinesco/fly-io-review-apps@v3.5
- name: Clean up GitHub environment
uses: strumwolf/delete-deployment-environment@v2
Expand All @@ -111,7 +111,7 @@ steps:
- name: Deploy app
id: deploy
uses: fewlinesco/fly-io-review-apps@v3.4
uses: fewlinesco/fly-io-review-apps@v3.5
with:
postgres: true
```
Expand All @@ -125,7 +125,7 @@ steps:
- name: Deploy app
id: deploy
uses: fewlinesco/fly-io-review-apps@v3.4
uses: fewlinesco/fly-io-review-apps@v3.5
with:
postgres: true
region: cdg
Expand All @@ -146,7 +146,7 @@ steps:
- uses: actions/checkout@v3
- name: Deploy redis
uses: fewlinesco/fly-io-review-apps@v3.4
uses: fewlinesco/fly-io-review-apps@v3.5
with:
update: false # Don't need to re-deploy redis when the PR is updated
path: redis # Keep fly.toml in a subdirectory to avoid confusing flyctl
Expand All @@ -155,7 +155,7 @@ steps:
- name: Deploy app
id: deploy
uses: fewlinesco/ffly-io-review-apps@v3.4
uses: fewlinesco/ffly-io-review-apps@v3.5
with:
name: pr-${{ github.event.number }}-myapp-app
```
7 changes: 4 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ if ! flyctl status --app "$app"; then
# Fix until Prisma can deal with IPv6 or Fly gives us something else
# see https://github.com/prisma/prisma/issues/18079
connection_string=$(echo $db_output | sed -e 's/[[:space:]]*DATABASE_URL=//g')
new_connection_string=$(echo $connection_string | sed -e "s/\.flycast/.internal/g")
bash -c "flyctl deploy --app "\""$app"\"" --image "\""$image"\"" --region "\""$region"\"" --env DATABASE_URL="\""$new_connection_string"\"" $(for secret in $(echo $INPUT_SECRETS | tr ";" "\n") ; do
database_url_write=$(echo $connection_string | sed -e "s/\.flycast/.internal/g")
database_url_read=$(echo $connection_string | sed -e "s/5432/5433/g")
bash -c "flyctl deploy --app "\""$app"\"" --image "\""$image"\"" --region "\""$region"\"" --env DATABASE_URL="\""$database_url_write"\"" --env DATABASE_URL_WRITE="\""$database_url_write"\"" --env DATABASE_URL_READ="\""$database_url_read"\"" $(for secret in $(echo $INPUT_SECRETS | tr ";" "\n") ; do
value="${secret}"
echo -n "--env $secret='${!value}' "
done)"
Expand All @@ -77,7 +78,7 @@ if ! flyctl status --app "$app"; then
fi

# Set current secrets for future deployments as they are not persisted when used with --env above
bash -c "flyctl secrets set --app "\""$app"\"" DATABASE_URL="\""$new_connection_string"\"" $(for secret in $(echo $INPUT_SECRETS | tr ";" "\n") ; do
bash -c "flyctl secrets set --app "\""$app"\"" DATABASE_URL="\""$database_url_write"\"" DATABASE_URL_WRITE="\""$database_url_write"\"" DATABASE_URL_READ="\""$database_url_read"\"" $(for secret in $(echo $INPUT_SECRETS | tr ";" "\n") ; do
value="${secret}"
echo -n " $secret='${!value}' "
done) || true"
Expand Down

0 comments on commit 4e0a537

Please sign in to comment.