Skip to content

Commit c999812

Browse files
committed
fix: update wrangler.toml generation to inject database_id from environment variable
1 parent 23cf945 commit c999812

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,14 @@ jobs:
3737
- name: Install dependencies
3838
run: pnpm install --frozen-lockfile
3939

40-
- name: Inject D1 database_id into API wrangler config
40+
- name: Copy wrangler.toml from example
41+
run: cp wrangler.toml.example wrangler.toml
42+
43+
- name: Generate API wrangler.toml from example
4144
working-directory: apps/api
4245
run: |
43-
set -eu
44-
if grep -q 'database_name\s*=\s*"tabitabi"' wrangler.toml; then
45-
if ! grep -q 'database_id' wrangler.toml; then
46-
echo "Injecting database_id into apps/api/wrangler.toml"
47-
awk 'BEGIN{added=0} {
48-
print;
49-
if ($0 ~ /database_name\s*=\s*"tabitabi"/ && added==0) {
50-
printf("database_id = \"%s\"\n", ENVIRON["CLOUDFLARE_DATABASE_ID"]);
51-
added=1;
52-
}
53-
}' wrangler.toml > wrangler.toml.tmp && mv wrangler.toml.tmp wrangler.toml
54-
fi
55-
fi
46+
cp wrangler.toml.example wrangler.toml
47+
sed -i "s/PLACEHOLDER_DATABASE_ID/${CLOUDFLARE_DATABASE_ID}/g" wrangler.toml
5648
5749
- name: Build all packages
5850
run: pnpm run build

apps/api/wrangler.toml.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,17 @@ enabled = true
88
[[d1_databases]]
99
binding = "DB"
1010
database_name = "tabitabi"
11+
database_id = "PLACEHOLDER_DATABASE_ID"
12+
migrations_dir = "../../migrations"
13+
14+
[env.production]
15+
name = "tabitabi-api"
1116

17+
[env.production.observability]
18+
enabled = true
19+
20+
[[env.production.d1_databases]]
21+
binding = "DB"
22+
database_name = "tabitabi"
23+
database_id = "PLACEHOLDER_DATABASE_ID"
1224
migrations_dir = "../../migrations"

0 commit comments

Comments
 (0)