From 49178cd2a7190b72f09c84ee2448f006ecf92493 Mon Sep 17 00:00:00 2001 From: Sergey Sokolov Date: Sat, 2 Mar 2019 16:32:51 +0300 Subject: [PATCH] Add docker-compose --- docker-compose.yml | 44 ++++++++++++++++++++++ postpost/main/settings.py | 6 ++- wait-for.sh | 79 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml create mode 100644 wait-for.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d8117be --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +version: '3' + +services: + api: + container_name: postpost_api + image: piterpy/postpost:$TAG + restart: unless-stopped + ports: + - 8000:8000 + env_file: .env + volumes: + - /root/db.sqlite3:/app/postpost/db.sqlite3 + depends_on: + - celery + - redis + + redis: + image: redis:alpine + container_name: redis + volumes: + - redis_data:/data + + celery: + image: piterpy/postpost:$TAG + command: sh /app/wait-for.sh api:8000 -- pipenv run celery -A main worker -B + depends_on: + - redis + + frontend: + container_name: postpost_frontend + image: piterpy/postpost-frontend:$TAG + restart: unless-stopped + ports: + - 8043:8043 + env_file: .env + + watchtower: + image: v2tec/watchtower + volumes: + - /var/run/docker.sock:/var/run/docker.sock + command: --interval 30 + +volumes: + redis_data: diff --git a/postpost/main/settings.py b/postpost/main/settings.py index ce412f1..a31e762 100644 --- a/postpost/main/settings.py +++ b/postpost/main/settings.py @@ -125,7 +125,11 @@ # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' -CELERY_BROKER_URL = 'redis://localhost:6379/0' +CELERY_BROKER_URL = 'redis://redis:6379' +CELERY_RESULT_BACKEND = 'redis://redis:6379' +CELERY_ACCEPT_CONTENT = ['application/json'] +CELERY_TASK_SERIALIZER = 'json' +CELERY_RESULT_SERIALIZER = 'json' REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( diff --git a/wait-for.sh b/wait-for.sh new file mode 100644 index 0000000..539a01d --- /dev/null +++ b/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 "$@"