Skip to content
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

fix(docker-compose): fix volumes paths for rabbitmq #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
docker.env

.DS_Store
.idea

.vscode

.DS_Store
docker.env
docker.env.*
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"
services:
app:
container_name: basedash-app
Expand All @@ -10,20 +10,20 @@ services:
condition: service_healthy
env_file: ./docker.env
ports:
- "5000:5000"
- 5000:5000
restart: unless-stopped
rabbitmq:
image: rabbitmq:3.8-management-alpine
container_name: 'rabbitmq'
container_name: rabbitmq
ports:
- 5672:5672
- 15672:15672
# A stable hostname is important to prevent the volume from continually growing on
# every restart. See issue described here: https://stackoverflow.com/questions/63115192/stale-rabbitmq-data-queue-files-eating-up-disk
hostname: 'rabbitmq'
hostname: rabbitmq
volumes:
- rabbitmq-data/:/var/lib/rabbitmq/
- rabbitmq-logs/:/var/log/rabbitmq
- rabbitmq-data:/var/lib/rabbitmq/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most essential part of the fix, to play nice with more recent versions of docker-compose.

- rabbitmq-logs:/var/log/rabbitmq
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 30s
Expand All @@ -34,12 +34,12 @@ services:
image: postgres:12.2
restart: always
ports:
- '5432:5432'
- 5432:5432
env_file: ./docker.env
volumes:
- db:/var/lib/postgresql/data
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
Expand All @@ -48,8 +48,8 @@ services:
container_name: nginx
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- 80:80
- 443:443
volumes:
- ./nginx:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
Expand Down
29 changes: 20 additions & 9 deletions docker_setup.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
#!/bin/bash

postgresPassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)
jwtKey=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 256 | head -n 1)
cryptoKey=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
publicIpAddress=$(dig +short myip.opendns.com @resolver1.opendns.com)
export LC_CTYPE=C
# :alnum: regex character class includes all Alphanumeric characters
POSTGRESPASSWORD=$(cat /dev/urandom | tr -cd '[[:alnum:]]' | fold -w 64 | head -n 1)
JWTKEY=$(cat /dev/urandom | tr -cd '[[:alnum:]]' | fold -w 256 | head -n 1)
CRYPTOKEY=$(cat /dev/urandom | tr -cd '[[:alnum:]]' | fold -w 32 | head -n 1)

echo "Generating random values for some environment variables..."
# TODO This appears to be unused
# publicIpAddress=$(dig +short myip.opendns.com @resolver1.opendns.com)

echo "Generating random values for necessary environment variables..."

if [ -f ./docker.env ]; then
echo "Backing up current docker.env file"
mv docker.env docker.env.$(date +"%Y-%m-%d_%H-%M-%S")
fi

cp template.docker.env docker.env

sed -i "s/JWT_KEY=.*/JWT_KEY=$jwtKey/" docker.env
sed -i "s/CRYPTO_KEY=.*/CRYPTO_KEY=$cryptoKey/" docker.env
sed -i "s/POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$postgresPassword/" docker.env
sed -i "s/POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$postgresPassword/" docker.env
# accommodate different behavior by `sed` on MacOS
SPACER=""
if [[ "$OSTYPE" == "darwin"* ]]; then
SPACER="''"
fi

sed -i $SPACER "s/JWT_KEY=.*$/JWT_KEY=$JWTKEY/" docker.env
sed -i $SPACER "s/CRYPTO_KEY=.*$/CRYPTO_KEY=$CRYPTOKEY/" docker.env
sed -i $SPACER "s/POSTGRES_PASSWORD=.*$/POSTGRES_PASSWORD=$POSTGRESPASSWORD/" docker.env
Comment on lines +21 to +29
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!


echo "Cool! Now fill in any missing environment variables in docker.env then run docker-compose up to launch Basedash."