Created
April 14, 2022 00:59
-
-
Save sean-m/5c5ca5efbc7e03093d440869055c33b2 to your computer and use it in GitHub Desktop.
Script to spin up a postgresql db for local development using podman.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
here=$(dirname "$0") | |
pushd "$here" > /dev/null | |
prep () | |
{ | |
if [ ! -d data ]; then | |
mkdir data | |
fi | |
} | |
start () | |
{ | |
if [ -z "$(podman ps | grep postgresql_database)" ]; then | |
podman rm postgresql_database | |
podman run --name postgresql_database \ | |
--memory 512M \ | |
-d \ | |
-e POSTGRESQL_USER=pguser \ | |
-e POSTGRES_PASSWORD=egm7DfeK \ | |
-e POSTGRESQL_DATABASE=db \ | |
-v "${here}/data":/var/lib/postgresql/data \ | |
-p 5432:5432 \ | |
docker.io/library/postgres:latest | |
else | |
echo "Postgresql already started" | |
fi | |
} | |
stop () | |
{ | |
podman stop postgresql_database > /dev/null | |
} | |
status () | |
{ | |
if [ -z "$(podman ps | grep postgresql_database)" ]; then | |
echo "> Database stopped" | |
else | |
echo "> Database running" | |
fi | |
} | |
prep | |
case "$1" in | |
"start" ) | |
start | |
;; | |
"stop" ) | |
stop | |
;; | |
* ) | |
echo 'Pass start or stop to start or stop the database.' | |
status | |
;; | |
esac | |
popd > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment