Don't require the user to have psql installed

This commit is contained in:
Luca Palmieri 2024-08-30 11:28:12 +02:00
parent 4e803865f3
commit 2b4666d4fb
2 changed files with 14 additions and 18 deletions

View file

@ -62,8 +62,6 @@ jobs:
# The --locked flag can be used to force Cargo to use the packaged Cargo.lock file if it is available.
# This may be useful for ensuring reproducible builds, to use the exact same set of dependencies that were available when the package was published.
# It may also be useful if a newer version of a dependency is published that no longer builds on your system, or has other problems
- name: Install postgresql-client
run: sudo apt-get update && sudo apt-get install postgresql-client -y
- name: Migrate database
run: |
sudo apt-get install libpq-dev -y
@ -111,8 +109,6 @@ jobs:
--features ${{ env.SQLX_FEATURES }}
--no-default-features
--locked
- name: Install postgresql-client
run: sudo apt-get update && sudo apt-get install postgresql-client -y
- name: Migrate database
run: |
sudo apt-get install libpq-dev -y
@ -140,8 +136,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Install libpq
run: sudo apt-get update && sudo apt-get install postgresql-client -y
- uses: Swatinem/rust-cache@v2
with:
key: sqlx-${{ env.SQLX_VERSION }}

View file

@ -2,11 +2,6 @@
set -x
set -eo pipefail
if ! [ -x "$(command -v psql)" ]; then
echo >&2 "Error: psql is not installed."
exit 1
fi
if ! [ -x "$(command -v sqlx)" ]; then
echo >&2 "Error: sqlx is not installed."
echo >&2 "Use:"
@ -36,23 +31,30 @@ then
echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
exit 1
fi
CONTAINER_NAME="postgres_$(date '+%s')"
# Launch postgres using Docker
docker run \
-e POSTGRES_USER=${DB_USER} \
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
-e POSTGRES_DB=${DB_NAME} \
--health-cmd="pg_isready -U ${DB_USER} || exit 1" \
--health-interval=1s \
--health-timeout=5s \
--health-retries=5 \
-p "${DB_PORT}":5432 \
-d \
--name "postgres_$(date '+%s')" \
--name "${CONTAINER_NAME}" \
postgres -N 1000
# ^ Increased maximum number of connections for testing purposes
fi
# Keep pinging Postgres until it's ready to accept commands
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
until [ \
"$(docker inspect -f "{{.State.Health.Status}}" ${CONTAINER_NAME})" == \
"healthy" \
]; do
>&2 echo "Postgres is still unavailable - sleeping"
sleep 1
done
done
fi
>&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations now!"