-
Notifications
You must be signed in to change notification settings - Fork 1
Use postgres as default session service #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
48ffa8b
Adds asyncpg to conform to new req for db connections to be async
falquaddoomi 5e4bdaf
Adds asyncpg to db connection string
falquaddoomi 74dc5e9
Adds postgres vars to env template
falquaddoomi 5279258
README: adds docker-compose.with-pg.yml to instructions on bringing u…
falquaddoomi 081ced8
Adds run_stack.sh helper as possible replacement for docker cmds in R…
falquaddoomi 8ba0a1a
Makes some changes to the script suggested by shellcheck (thanks, DB)
falquaddoomi f9e512f
Changes instructions to use the run_stack.sh script for launching dev…
falquaddoomi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # this script manages compose configurations for different environments | ||
| # and ensures the necessary environment variables are set up correctly. | ||
|
|
||
| # invoke it like so: | ||
| # | ||
| # ./run_stack.sh [dev|prod] [docker-compose command options] | ||
| # | ||
| # - the first argument is the environment (default: dev) if the first arg isn't | ||
| # provided or doesn't match 'dev' or 'prod', it defaults to 'dev'. | ||
| # - the remainder of the arguments are passed to the `docker compose` command. | ||
| # if no arguments are provided, it defaults to an environment-specific | ||
| # command, e.g. `docker compose up --build` for dev or `docker compose up | ||
| # --build -d` for prod. | ||
|
|
||
| # ------------------------------------ | ||
| # --- preamble: .env file validation, sourcing | ||
| # ------------------------------------ | ||
|
|
||
| # check if `.env` is present, and if not copy it from `.env.TEMPLATE` | ||
| # and fill in passwords with random values | ||
| if [ ! -f .env ]; then | ||
| echo ".env file not found, copying from .env.TEMPLATE" | ||
| cp .env.TEMPLATE .env | ||
| fi | ||
|
|
||
| # ensure a value for the postgres db's password exists, and if not, generate a random one | ||
| RANDOM_PG_PASSWORD=$(openssl rand -base64 32 | tr -d '/=') | ||
| perl -i -pe"s/^POSTGRES_PASSWORD=$/POSTGRES_PASSWORD=\"${RANDOM_PG_PASSWORD}\"/g" .env | ||
|
|
||
| # source the .env file and export its contents to the environment | ||
| set -a | ||
| source .env | ||
| set +a | ||
|
|
||
| # ------------------------------------ | ||
| # --- environment resolution | ||
| # ------------------------------------ | ||
|
|
||
| # sets the default environment to 'dev' if not specified via DEFAULT_ENV | ||
| DEFAULT_ENV=${DEFAULT_ENV:-dev} | ||
| # defaults to a no-op command to run after docker compose | ||
| POST_COMMAND=":" | ||
|
|
||
| if [ -z "$1" ] || [[ ! "$1" =~ ^(dev|prod)$ ]]; then | ||
| echo "No environment specified, using default: $DEFAULT_ENV" | ||
| export ENV=$DEFAULT_ENV | ||
| else | ||
| # use the first argument as the environment | ||
| export ENV="$1"; shift | ||
| echo "Using specified environment: $ENV" | ||
| fi | ||
|
|
||
| # set up compose files and commands based on the environment | ||
| case $ENV in | ||
| dev) | ||
| COMPOSE_FILES="-f docker-compose.yml -f docker-compose.override.yml" | ||
| COMPOSE_CMD="up --build" | ||
| ;; | ||
| prod) | ||
| COMPOSE_FILES="-f docker-compose.yml -f docker-compose.with-pg.yml -f docker-compose.prod.yml" | ||
| COMPOSE_CMD="up --build -d" | ||
| # tail all container logs in production | ||
| POST_COMMAND="docker compose ${COMPOSE_FILES} logs -f" | ||
| ;; | ||
| *) | ||
| echo "Unknown environment: $ENV, aborting" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
|
|
||
| # ------------------------------------ | ||
| # --- execute docker compose command | ||
| # ------------------------------------ | ||
|
|
||
| # if we have any remaining arguments, override the compose command with them | ||
| if [ $# -gt 0 ]; then | ||
| echo "Overriding compose command with: $@" | ||
| COMPOSE_CMD="$@" | ||
| fi | ||
|
|
||
| docker compose ${COMPOSE_FILES} ${COMPOSE_CMD} && \ | ||
| ${POST_COMMAND} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be worth a quick check with
shellcheck. I don't see anything especially dangerous but it might provide some good feedback for string composition.