Skip to content

Commit 0930bcf

Browse files
committed
Update script which deploys to SQLite DB setup
- Includes hacky fix in script to patch the fly.toml file because a new one is generated by flyctyl launch
1 parent b8ac07d commit 0930bcf

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ fly.toml
22
.git/
33
*.sqlite3
44
venv
5+
.tmp/
56

67
server/.env
78
server/static

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.swp
2+
.tmp/
23

34
venv/
45
__pycache__/

scripts/configs/fly-sqlite.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ console_command = '/code/manage.py shell'
1010
[build]
1111

1212
[deploy]
13-
# Run the database migration manually after deploy if using volume storage, since release_command does not have access to fly.io storage volumes
13+
# NOTE: Run database migrations manually after deploy if using volume storage, since release_command does not have access to fly.io storage volumes
1414
# Reference: https://community.fly.io/t/using-sqlite-from-persistent-volume-for-django-application/16206/3
1515
# release_command = 'python manage.py migrate --noinput'
1616

scripts/deploy-fly.io-sqlite.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
#!/usr/bin/env bash
22

3+
4+
# Specify the target fly.toml configuration file
5+
function specify_target_fly_toml() {
6+
# Move currently active fly.toml configuration file to local tmp directory
7+
if [ -f fly.toml ]; then
8+
mkdir -p .tmp
9+
mv fly.toml .tmp/fly.toml
10+
fi
11+
12+
# Copy target fly.toml configuration file to project root directory
13+
cp -p ./scripts/configs/fly-sqlite.toml fly.toml
14+
}
15+
specify_target_fly_toml
16+
17+
318
# Create app without launching
419
yes n | fly launch --vm-memory 512 --ha=false --no-db --now --copy-config --build-only
520

621
# Set database location
722
flyctl secrets set DATABASE_URL=sqlite:////data/db.sqlite3
823

24+
# Use gsed on macOS
25+
SED_CMD="sed"
26+
if [[ "$OSTYPE" == "darwin"* ]]; then
27+
SED_CMD="gsed"
28+
fi
29+
30+
# HACKY FIX: flyctl will override this change that we manually made in the fly.toml file :/.
31+
# Update fly.toml to disable release_command and migrate in a separate step
32+
# NOTE: Run database migrations manually after deploy if using volume storage, since release_command does not have access to fly.io storage volumes
33+
# Reference: https://community.fly.io/t/using-sqlite-from-persistent-volume-for-django-application/16206/3
34+
$SED_CMD -i "s| release_command = 'python manage.py migrate --noinput'|# release_command = 'python manage.py migrate --noinput'|g" fly.toml
35+
36+
937
# Launch app
1038
fly deploy
1139

1240
# Run migrations
1341
fly ssh console -C 'python manage.py migrate'
42+
43+
# Restore existing fly.toml
44+
mv .tmp/fly.toml fly.toml

0 commit comments

Comments
 (0)