From a241dfc0c0c2d03ac9e0f0b7547d17a90dd81a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Wed, 27 Jan 2021 19:55:52 +0100 Subject: [PATCH] refactor(docker-compose and db init): rewrote docker-compose to work purely with env variables It is possible to rename the default db in a postgres container instance via an env variable. This renders the initdb script useless. The only shortcoming is that the app now uses the db root user which is not ideal but its fine for a dev environment. --- .dockerignore | 2 +- docker-compose.yaml | 23 +++++++++-------------- initdb/10-init-db.sh | 10 ---------- 3 files changed, 10 insertions(+), 25 deletions(-) delete mode 100755 initdb/10-init-db.sh diff --git a/.dockerignore b/.dockerignore index 9c25c76e3..aef45340d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,7 +6,7 @@ test-queries Contributing.md ISSUE_TEMPLATE.md lerna.json -.env +**/.env .env.example .eslintrc.json .mocharc.js diff --git a/docker-compose.yaml b/docker-compose.yaml index dd2b86e0e..2c20ae878 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,5 @@ version: "3" services: - - # this could be enabled once the server container is added server: build: . @@ -11,41 +9,38 @@ services: ports: - "3000:3000" environment: - DEBUG: "speckle:*" + DEBUG: "speckle:*" env_file: - .env database: - image: "postgres" # use latest official postgres version - env_file: - - .env # configure postgres + image: "postgres:13.1-alpine" # use the current alpine version for smaller image + environment: + POSTGRES_DB: + POSTGRES_USER: + POSTGRES_PASSWORD: volumes: # persist data even if container shuts down - speckle-postgres-data:/var/lib/postgresql/data/ - # this mounts the initdb folder to the db container - # .sql .sh files are executed from this folder in alphabetical order - - ./initdb:/docker-entrypoint-initdb.d ports: - "5432:5432" pgadmin: image: dpage/pgadmin4 environment: - PGADMIN_DEFAULT_EMAIL: "${PGADMIN_EMAIL}" - PGADMIN_DEFAULT_PASSWORD: "${PGADMIN_PASSWORD}" + PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL} + PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD} ports: - "16543:80" depends_on: - database redis: - image: "redis" + image: "redis:6.0-alpine" ports: - "6379:6379" # It is not neccesary to expose the reddis port if running the app with compose volumes: - redis_volume_data:/data - # - ./redis.conf:/tmp/redis.conf - # command: [ "redis-server", "/tmp/redis.conf"] redis_insight: image: redislabs/redisinsight:latest diff --git a/initdb/10-init-db.sh b/initdb/10-init-db.sh deleted file mode 100755 index 89358cbb5..000000000 --- a/initdb/10-init-db.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -echo Running Speckle Server initial database setup - -psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL - CREATE USER $SPECKLE_DB_USER WITH PASSWORD '$SPECKLE_DB_PASSWORD'; - CREATE DATABASE $SPECKLE_DB_NAME; - GRANT ALL PRIVILEGES ON DATABASE $SPECKLE_DB_NAME TO $SPECKLE_DB_USER; -EOSQL \ No newline at end of file