Skip to content

Commit

Permalink
chore(docker): add postgresql service properly
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed May 25, 2022
1 parent d3ebf7d commit b0859f0
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 35 deletions.
1 change: 1 addition & 0 deletions .env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ANSIBLE_VAULT_KEY=${ANSIBLE_VAULT_KEY}
ENV=${ENV}
FLOWER_PORT=${FLOWER_PORT}
FLOWER_PASSWORD=${FLOWER_PASSWORD}
HOST_POSTGRES_DUMP=${HOST_POSTGRES_DUMP}
MAPBOX_API_KEY=${MAPBOX_API_KEY}
POSTGRES_HOST=${POSTGRES_HOST}
POSTGRES_PORT=${POSTGRES_PORT}
Expand Down
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ CONSOLE:=bash
DOCKER=docker-compose \
--env-file .env \
--project-name eph-$(ENV) \
--file docker/compose-base.yaml \
--file docker/compose-$(ENV).yaml
--file docker/compose.yaml

# DOCKER

Expand All @@ -21,22 +20,31 @@ docker-build:

.PHONY:docker-start
docker-start:
$(DOCKER) up -d ${SERVICES}
$(DOCKER) up --remove-orphans -d ${SERVICES}


.PHONY:docker-stop
docker-stop:
$(DOCKER) stop ${SERVICES}


.PHONY:docker-down
docker-down:
$(DOCKER) down --volumes


.PHONY:docker-restart
docker-restart: docker-stop docker-start
echo "[II] Docker services restarted!"


.PHONY:docker-logs-follow
docker-logs-follow:
$(DOCKER) logs --follow --tail 100 ${SERVICES}

.PHONY:docker-logs
docker-logs:
$(DOCKER) logs --follow --tail 100 ${SERVICES}
$(DOCKER) logs --tail 200 ${SERVICES}

.PHONY: docker-wait
docker-wait:
Expand Down
24 changes: 0 additions & 24 deletions docker/compose-dev.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions docker/compose-prod.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions docker/compose-base.yaml → docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:
ports:
- ${SUPERSET_PORT}:8088
depends_on:
- epigraphhub-db
- epigraphhub-redis
- epigraphhub-celery
- epigraphhub-celery-beat
Expand Down Expand Up @@ -136,6 +137,21 @@ services:
timeout: 10s
retries: 5
start_period: 40s # requires docker-compose 3.4
volumes:
- pgdata:/var/lib/postgresql/data/pgdata
- ${HOST_POSTGRES_DUMP}:/tmp/dump
ports:
- ${POSTGRES_PORT}:5432
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER}
PGDATA: /var/lib/postgresql/data/pgdata
healthcheck:
test: ["CMD-SHELL", "pg_isready -p ${POSTGRES_PORT} -U postgres"]
interval: 10s
timeout: 5s
retries: 10
command: -p ${POSTGRES_PORT}

epigraphhub-flower:
image: mher/flower:0.9.7
Expand All @@ -161,3 +177,4 @@ services:

volumes:
redis:
pgdata:
19 changes: 19 additions & 0 deletions docker/postgresql/dump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd ../.. && pwd )"

if [ -f ${PROJECT_DIR}/.env ]; then
# Load Environment Variables
export $(cat ${PROJECT_DIR}/.env | grep -v '#' | sed 's/\r$//' | awk '/=/ {print $1}' )
fi

HOST_POSTGRES_DUMP=${HOST_POSTGRES_DUMP:-/tmp/dump}
mkdir -p ${HOST_POSTGRES_DUMP}

set -ex

PGPASSWORD=${POSTGRES_PASSWORD} pg_dumpall \
--host ${POSTGRES_HOST} \
--port ${POSTGRES_PORT} \
--user ${POSTGRES_USER} \
> ${HOST_POSTGRES_DUMP}/$(date --iso-8601).dump
Empty file added docker/postgresql/restore.sh
Empty file.

0 comments on commit b0859f0

Please sign in to comment.