Skip to content

Commit 7b89021

Browse files
Fix(CI): (db env var issue)
1 parent 5761fd0 commit 7b89021

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

.cargo/config.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Scope down tracing, to filter out external lib tracing.
44
RUST_LOG="web_server=debug,lib_web=debug,services=debug"
55

6+
7+
## -- ConfigMap
8+
69
# This will be relative to Cargo.toml
710
# In deployed images, probably use absolute path.
8-
SERVICE_WEB_FOLDER="web"
11+
SERVICE_WEB_FOLDER="web/"

.github/workflows/general.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ jobs:
151151
--no-default-features
152152
--locked
153153
- name: Migrate database
154-
run: SKIP_DOCKER=true ./scripts/init_db.sh
154+
run: |
155+
SKIP_DOCKER=true \
156+
DB_HOST=localhost \
157+
DB_PORT=5432 \
158+
DB_USER=postgres \
159+
DB_PASSWORD=password \
160+
DB_NAME=postgres \
161+
./scripts/init_db.sh
155162
- name: Generate code coverage
156163
run: cargo install cargo-tarpaulin && cargo tarpaulin --verbose --workspace

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dev-watch:
3535
echo "Starting web server with watching..."
3636
# Use multiple terminals or a terminal multiplexer like tmux for this
3737
# This particular command should be run in a separate terminal
38-
cargo watch -q -c -w crates/lib/services/web_server/src/ -x "run -p web_server"
38+
cargo watch -q -c -w .cargo -w crates/lib/services/web_server/src/ -x "run -p web_server"
3939

4040

4141
# Initialize the database using Docker

scripts/init_db.sh

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
#!/usr/bin/env bash
22

33
if ! [ -x "$(command -v psql)" ]; then
4-
echo >&2 "Error: psql is not installed."
5-
exit 1
4+
echo >&2 "Error: psql is not installed."
5+
exit 1
66
fi
77
if ! [ -x "$(command -v sqlx)" ]; then
8-
echo >&2 "Error: sqlx is not installed."
9-
echo >&2 "Use:"
10-
echo >&2 " cargo install --version='~0.7' sqlx-cli \
8+
echo >&2 "Error: sqlx is not installed."
9+
echo >&2 "Use:"
10+
echo >&2 " cargo install --version='~0.7' sqlx-cli \
1111
--no-default-features --features rustls,postgres"
12-
echo >&2 "to install it."
12+
echo >&2 "to install it."
1313
exit 1
1414
fi
1515

1616
# The rest of the script
1717
set -x
1818
set -eo pipefail
1919

20+
# Default settings
21+
DB_HOST="${DB_HOST:=localhost}"
2022
DB_PORT="${DB_PORT:=5432}"
23+
DB_USER="${DB_USER:=postgres}"
24+
DB_PASSWORD="${DB_PASSWORD:=password}"
25+
DB_NAME="${DB_NAME:=postgres}"
2126
SUPERUSER="${SUPERUSER:=postgres}"
2227
SUPERUSER_PWD="${SUPERUSER_PWD:=welcome}"
2328
APP_USER="${APP_USER:=app}"
@@ -63,14 +68,25 @@ then
6368
# Grant create db privileges to the app user
6469
GRANT_QUERY="ALTER USER ${APP_USER} CREATEDB;"
6570
docker exec -it "${CONTAINER_NAME}" psql -U "${SUPERUSER}" -c "${GRANT_QUERY}"
71+
72+
# In this case we're running in docker, so let's use APP_USER for DB_USER later
73+
DB_USER="${APP_USER}"
74+
DB_PASSWORD="${APP_USER_PWD}"
75+
DB_NAME="${APP_DB_NAME}"
76+
else
77+
# We're skipping docker, so we need to ensure the DB variables are set
78+
# In CI, these should match the GitHub Actions postgres service settings
79+
echo "Using existing PostgreSQL instance at ${DB_HOST}:${DB_PORT}"
6680
fi
6781

68-
>&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations now!"
82+
# Debug info - print connection details
83+
echo "Connecting with: host=${DB_HOST}, port=${DB_PORT}, user=${DB_USER}, db=${DB_NAME}"
84+
6985
# Keep pinging Postgres until it's ready to accept commands
7086
export PGPASSWORD="${DB_PASSWORD}"
7187
until psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
72-
>&2 echo "Postgres is still unavailable - sleeping"
73-
sleep 1
88+
>&2 echo "Postgres is still unavailable - sleeping"
89+
sleep 1
7490
done
7591
>&2 echo "Postgres is up and running on port ${DB_PORT}!"
7692

0 commit comments

Comments
 (0)