Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19801fd

Browse files
chore: refactored test job
1 parent 0de2a52 commit 19801fd

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

‎.github/workflows/general.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
# Set environment variables for the service container
2727
env:
2828
POSTGRES_USER: postgres
29-
POSTGRES_PASSWORD: postgres
29+
POSTGRES_PASSWORD: password
3030
POSTGRES_DB: postgres
3131
# Set health checks to wait until the service is ready
3232
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

‎scripts/init_db.sh

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,47 @@ set -x
33
set -eo pipefail
44

55
if ! [ -x "$(command -v psql)" ]; then
6-
echo >&2 "Error: psql is not installed."
7-
exit 1
6+
echo >&2 "Error: psql is not installed."
7+
exit 1
88
fi
9-
109
if ! [ -x "$(command -v sqlx)" ]; then
11-
echo >&2 "Error: sqlx is not installed."
12-
echo >&2 "Use:"
13-
echo >&2 " cargo install --version='~0.6' sqlx-cli --no-default-features --features rustls,postgres"
14-
echo >&2 "to install it."
15-
exit 1
10+
echo >&2 "Error: sqlx is not installed."
11+
echo >&2 "Use:"
12+
echo >&2 " cargo install --version=0.5.7 sqlx-cli --no-default-features --features postgres"
13+
echo >&2 "to install it."
14+
exit 1
1615
fi
1716

1817
# Check if a custom user has been set, otherwise default to 'postgres'
19-
DB_USER="${POSTGRES_USER:=postgres}"
18+
DB_USER=${POSTGRES_USER:=postgres}
2019
# Check if a custom password has been set, otherwise default to 'password'
2120
DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
2221
# Check if a custom database name has been set, otherwise default to 'newsletter'
2322
DB_NAME="${POSTGRES_DB:=newsletter}"
2423
# Check if a custom port has been set, otherwise default to '5432'
2524
DB_PORT="${POSTGRES_PORT:=5432}"
26-
# Check if a custom host has been set, otherwise default to 'localhost'
27-
DB_HOST="${POSTGRES_HOST:=localhost}"
28-
29-
# Allow to skip Docker if a dockerized Postgres database is already running
30-
if [[ -z "${SKIP_DOCKER}" ]]
31-
then
32-
# if a postgres container is running, print instructions to kill it and exit
33-
RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}')
34-
if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then
35-
echo >&2 "there is a postgres container already running, kill it with"
36-
echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
37-
exit 1
38-
fi
39-
# Launch postgres using Docker
40-
docker run \
41-
-e POSTGRES_USER=${DB_USER} \
42-
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
43-
-e POSTGRES_DB=${DB_NAME} \
44-
-p "${DB_PORT}":5432 \
45-
-d \
46-
--name "postgres_$(date '+%s')" \
47-
postgres -N 1000
48-
# ^ Increased maximum number of connections for testing purposes
49-
fi
50-
25+
# stop postgres if it's already running
26+
sudo systemctl stop postgresql
27+
# Launch postgres using Docker
28+
docker run \
29+
-e POSTGRES_USER=${DB_USER} \
30+
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
31+
-e POSTGRES_DB=${DB_NAME} \
32+
-p "${DB_PORT}":5432 \
33+
-d postgres \
34+
postgres -N 1000
35+
# ^ Increased maximum number of connections for testing purposes
5136
# Keep pinging Postgres until it's ready to accept commands
52-
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
53-
>&2 echo "Postgres is still unavailable - sleeping"
54-
sleep 1
37+
export PGPASSWORD="${DB_PASSWORD}"
38+
until psql -h "localhost" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
39+
>&2 echo "Postgres is still unavailable - sleeping"
40+
sleep 1
5541
done
5642

57-
>&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations now!"
43+
>&2 echo "Postgres is up and running on port ${DB_PORT}!"
5844

59-
export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
45+
export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}
6046
sqlx database create
6147
sqlx migrate run
6248

63-
>&2 echo "Postgres has been migrated, ready to go!"
49+
>&2 echo "Postgres has been migrated, ready to go!"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /