mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-11-25 02:01:03 +00:00
Don't require the user to have psql installed
This commit is contained in:
parent
4e803865f3
commit
2b4666d4fb
2 changed files with 14 additions and 18 deletions
6
.github/workflows/general.yml
vendored
6
.github/workflows/general.yml
vendored
|
@ -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.
|
# 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.
|
# 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
|
# 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
|
- name: Migrate database
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install libpq-dev -y
|
sudo apt-get install libpq-dev -y
|
||||||
|
@ -111,8 +109,6 @@ jobs:
|
||||||
--features ${{ env.SQLX_FEATURES }}
|
--features ${{ env.SQLX_FEATURES }}
|
||||||
--no-default-features
|
--no-default-features
|
||||||
--locked
|
--locked
|
||||||
- name: Install postgresql-client
|
|
||||||
run: sudo apt-get update && sudo apt-get install postgresql-client -y
|
|
||||||
- name: Migrate database
|
- name: Migrate database
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install libpq-dev -y
|
sudo apt-get install libpq-dev -y
|
||||||
|
@ -140,8 +136,6 @@ jobs:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- 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
|
- uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
key: sqlx-${{ env.SQLX_VERSION }}
|
key: sqlx-${{ env.SQLX_VERSION }}
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
set -x
|
set -x
|
||||||
set -eo pipefail
|
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
|
if ! [ -x "$(command -v sqlx)" ]; then
|
||||||
echo >&2 "Error: sqlx is not installed."
|
echo >&2 "Error: sqlx is not installed."
|
||||||
echo >&2 "Use:"
|
echo >&2 "Use:"
|
||||||
|
@ -36,23 +31,30 @@ then
|
||||||
echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
|
echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
CONTAINER_NAME="postgres_$(date '+%s')"
|
||||||
# Launch postgres using Docker
|
# Launch postgres using Docker
|
||||||
docker run \
|
docker run \
|
||||||
-e POSTGRES_USER=${DB_USER} \
|
-e POSTGRES_USER=${DB_USER} \
|
||||||
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
|
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
|
||||||
-e POSTGRES_DB=${DB_NAME} \
|
-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 \
|
-p "${DB_PORT}":5432 \
|
||||||
-d \
|
-d \
|
||||||
--name "postgres_$(date '+%s')" \
|
--name "${CONTAINER_NAME}" \
|
||||||
postgres -N 1000
|
postgres -N 1000
|
||||||
# ^ Increased maximum number of connections for testing purposes
|
# ^ Increased maximum number of connections for testing purposes
|
||||||
fi
|
|
||||||
|
|
||||||
# Keep pinging Postgres until it's ready to accept commands
|
until [ \
|
||||||
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
|
"$(docker inspect -f "{{.State.Health.Status}}" ${CONTAINER_NAME})" == \
|
||||||
|
"healthy" \
|
||||||
|
]; do
|
||||||
>&2 echo "Postgres is still unavailable - sleeping"
|
>&2 echo "Postgres is still unavailable - sleeping"
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
>&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations now!"
|
>&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations now!"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue