Skip to content

Commit

Permalink
Merge pull request #3950 from dev-hato/fix_fly
Browse files Browse the repository at this point in the history
fly.ioへのデプロイ処理修正
  • Loading branch information
massongit authored May 19, 2024
2 parents 60772ad + d8ce7f9 commit 9b84f7f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATABASE_URL=postgres://postgres:password@postgres:5432/
DATABASE_URL=postgres://postgres:password@postgres:5432/?sslmode=require
DISCORD_API_TOKEN=
MISSKEY_API_TOKEN=
MISSKEY_DOMAIN=
Expand Down
18 changes: 6 additions & 12 deletions flyio_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#!/usr/bin/env bash
set -x
set -xe -o pipefail

# この時点では必要な環境変数がセットされていないため、起動に失敗する (コマンドが異常終了する)
fly launch --copy-config --vm-memory=256mb -y

set -e
POSTGRES_APP_NAME="$(yq '.app' fly.toml)-db"
APP_NAME=$(yq '.app' fly.toml)
fly apps create --name="$APP_NAME"
grep -v DATABASE_URL .env | fly secrets import
POSTGRES_APP_NAME="${APP_NAME}-db"
fly postgres create --name="$POSTGRES_APP_NAME" --region="$(yq '.primary_region' fly.toml)" --initial-cluster-size=1 \
--vm-size="$(yq '.vm.[0].size' fly.toml)" --volume-size=1
fly postgres attach "$POSTGRES_APP_NAME"
sleep 60
grep -v DATABASE_URL .env | fly secrets import
sleep 60

# shellcheck disable=SC2046
fly machine start $(fly machine list --json | yq '.[].id' | tr "\n" ' ')
fly deploy --vm-memory=256
2 changes: 1 addition & 1 deletion library/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Database:

def __init__(self):
try:
self.conn = psycopg2.connect(conf.DB_URL, sslmode="require")
self.conn = psycopg2.connect(conf.DB_URL)
except psycopg2.Error as _e:
print("Can not connect to database.")
raise _e
Expand Down

0 comments on commit 9b84f7f

Please sign in to comment.