diff --git a/docker-compose-dev.yaml b/docker-compose-dev.yaml deleted file mode 100644 index a7f0ebf4e3..0000000000 --- a/docker-compose-dev.yaml +++ /dev/null @@ -1,76 +0,0 @@ -version: '3.5' - -x-environment-vars: &environment-vars - DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB} - ELASTICSEARCH_HOST: elastic:9200 - REDIS_URL: redis://redis:6379/0 - ADMIN_EMAIL: "@{ADMIN_EMAIL}" - ADMIN_PASSWORD: "@{ADMIN_PASSWORD}" - -x-defaults: &defaults - build: . - restart: unless-stopped - environment: - <<: *environment-vars - depends_on: - - postgres - - redis - - elastic - links: - - postgres:postgres - - redis:redis - - elastic:elastic - volumes: - - ./static:/data/app/static - -services: - - postgres: - image: postgres:10-alpine - container_name: opev-postgres - restart: unless-stopped - volumes: - - pg:/var/lib/postgresql/data - environment: - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_DB: ${POSTGRES_DB} - - redis: - image: redis:3-alpine - container_name: opev-redis - restart: unless-stopped - command: redis-server - volumes: - - rd:/var/lib/redis/data - - elastic: - image: elasticsearch:5.6.12-alpine - container_name: opev-elastic-search - restart: unless-stopped - environment: - - discovery.type=single-node - volumes: - - es:/usr/share/elasticsearch/data - ports: - - 9200:9200 - - 9300:9300 - - web: - <<: *defaults - container_name: opev-web - ports: - - 8080:8080 - - celery: - <<: *defaults - container_name: opev-celery - environment: - <<: *environment-vars - DEPLOYMENT: celery - C_FORCE_ROOT: "true" - -volumes: - pg: - rd: - es: diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 0000000000..67c8c0867d --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,8 @@ +version: '3.5' + +services: + web: + build: . + + celery: + build: . diff --git a/docker-compose.yml b/docker-compose.yml index a7f0ebf4e3..4e5d2489d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,25 +1,20 @@ version: '3.5' x-environment-vars: &environment-vars + POSTGRES_HOST: postgres DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB} - ELASTICSEARCH_HOST: elastic:9200 REDIS_URL: redis://redis:6379/0 ADMIN_EMAIL: "@{ADMIN_EMAIL}" ADMIN_PASSWORD: "@{ADMIN_PASSWORD}" x-defaults: &defaults - build: . + image: eventyay/open-event-server restart: unless-stopped environment: <<: *environment-vars depends_on: - postgres - redis - - elastic - links: - - postgres:postgres - - redis:redis - - elastic:elastic volumes: - ./static:/data/app/static @@ -44,18 +39,6 @@ services: volumes: - rd:/var/lib/redis/data - elastic: - image: elasticsearch:5.6.12-alpine - container_name: opev-elastic-search - restart: unless-stopped - environment: - - discovery.type=single-node - volumes: - - es:/usr/share/elasticsearch/data - ports: - - 9200:9200 - - 9300:9300 - web: <<: *defaults container_name: opev-web @@ -73,4 +56,3 @@ services: volumes: pg: rd: - es: diff --git a/postgres-initdb.d/create_db.sql b/postgres-initdb.d/create_db.sql deleted file mode 100644 index 3f7bf4ef2b..0000000000 --- a/postgres-initdb.d/create_db.sql +++ /dev/null @@ -1,6 +0,0 @@ --- Open Event database -CREATE USER open_event_user WITH PASSWORD 'opev_pass'; -CREATE DATABASE open_event WITH OWNER open_event_user; - --- Test database -CREATE DATABASE opev_test WITH OWNER open_event_user; diff --git a/scripts/container_start.sh b/scripts/container_start.sh index 89a597b78f..508de6e026 100644 --- a/scripts/container_start.sh +++ b/scripts/container_start.sh @@ -7,6 +7,7 @@ echo "[LOG] Using redis: ${REDIS_URL}" if [ "$DEPLOYMENT" == "api" ] then + echo "[LOG] Waiting for Database" && ./scripts/wait-for.sh ${POSTGRES_HOST}:5432 --timeout=60 -- echo "[LOG] Database Up" echo "[LOG] Preparing database" python manage.py prepare_kubernetes_db echo "[LOG] Running migrations" diff --git a/scripts/wait-for.sh b/scripts/wait-for.sh new file mode 100755 index 0000000000..b1e34c1c0d --- /dev/null +++ b/scripts/wait-for.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +TIMEOUT=15 +QUIET=0 + +echoerr() { + if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi +} + +usage() { + exitcode="$1" + cat << USAGE >&2 +Usage: + $cmdname host:port [-t timeout] [-- command args] + -q | --quiet Do not output any status messages + -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit "$exitcode" +} + +wait_for() { + for i in `seq $TIMEOUT` ; do + nc -z "$HOST" "$PORT" > /dev/null 2>&1 + + result=$? + if [ $result -eq 0 ] ; then + if [ $# -gt 0 ] ; then + exec "$@" + fi + exit 0 + fi + sleep 1 + done + echo "Operation timed out" >&2 + exit 1 +} + +while [ $# -gt 0 ] +do + case "$1" in + *:* ) + HOST=$(printf "%s\n" "$1"| cut -d : -f 1) + PORT=$(printf "%s\n" "$1"| cut -d : -f 2) + shift 1 + ;; + -q | --quiet) + QUIET=1 + shift 1 + ;; + -t) + TIMEOUT="$2" + if [ "$TIMEOUT" = "" ]; then break; fi + shift 2 + ;; + --timeout=*) + TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + break + ;; + --help) + usage 0 + ;; + *) + echoerr "Unknown argument: $1" + usage 1 + ;; + esac +done + +if [ "$HOST" = "" -o "$PORT" = "" ]; then + echoerr "Error: you need to provide a host and port to test." + usage 2 +fi + +wait_for "$@" \ No newline at end of file