From e9dc3e046a461bca50e99ba530a27b8b997cdbcb Mon Sep 17 00:00:00 2001 From: Mourad Maatoug Date: Mon, 5 Mar 2018 12:42:23 +0100 Subject: [PATCH 1/4] add docker entrypoint to make the image more parameterizable. --- Dockerfile | 4 +++- entrypoint.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index d73127a..d574268 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,10 @@ RUN pip install --no-cache-dir -r requirements.txt RUN apk del deps COPY . /usr/src/app -RUN chown -R app:app /usr/src/app +RUN chown -R app:app /usr/src/app && chmod +x /usr/src/app/entrypoint.sh USER app EXPOSE 8080 + +ENTRYPOINT ["/bin/sh", "./entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2ecfbf8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# Set the default variables values +# Service to launch +COMPONENT=${COMPONENT:-websocket} +HUEY_CONCURRENCY=${HUEY_CONCURRENCY:-3} +MIGRATION=${2:-head} + +if [ "$COMPONENT" = "websocket" ]; then + echo "[$0] Starting $COMPONENT service !" + python3 -m app.services.websocket_server + +elif [ "$COMPONENT" = "contract_observer" ]; then + if [ "$1" = "migrate" ]; then + echo "[$0] Starting DB migration !" + + alembic upgrade ${MIGRATION} + else + echo "[$0] Starting $COMPONENT service !" + python3 -m app.services.contract_observer + fi + + +elif [ "$COMPONENT" = "etherdelta_observer" ]; then + echo "[$0] Starting $COMPONENT service !" + python3 -m app.services.etherdelta_observer + +elif [ "$COMPONENT" = "huey_consumer" ]; then + echo "[$0] Starting $COMPONENT service !" + huey_consumer.py app.services.huey_consumer.huey -w ${HUEY_CONCURRENCY} -k greenlet + +elif [ "$COMPONENT" = "ticker" ]; then + echo "[$0] Starting $COMPONENT service !" + python3 -m app.services.ticker +else + echo "[$0] Service [$COMPONENT] is not valid !" + exit -1 +fi \ No newline at end of file From 0ec65452d089fd4e00e54d3c5750dc3d2dba268d Mon Sep 17 00:00:00 2001 From: Mourad Maatoug Date: Mon, 5 Mar 2018 13:02:09 +0100 Subject: [PATCH 2/4] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c6f4f5..f43b043 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Setup: 3. Copy `default.env` file to `.env` in root. 4. Uncomment the `COMPOSE_FILE=` line in `.env` to enable mounting of working copy code into the containers. 4. Build a Docker image containing our backend code: `docker-compose build contract_observer` -5. Create the database and migrate it to the latest schema: `docker-compose run contract_observer alembic upgrade head` +5. Create the database and migrate it to the latest schema: `docker-compose run contract_observer migrate head` 6. Run the backend systems: `docker-compose up`. You can shut everything down with Ctrl+C at any time. Tips: From 72c8ef3109073d0fa15827ee72d7f9a9afb2508d Mon Sep 17 00:00:00 2001 From: Mourad Maatoug Date: Mon, 5 Mar 2018 14:27:07 +0100 Subject: [PATCH 3/4] Use entrypoint instead of command --- docker-compose.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a3f9a50..3ba03bf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,11 +12,11 @@ services: POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} HTTP_PROVIDER_URL: ${HTTP_PROVIDER_URL} WS_PROVIDER_URL: ${WS_PROVIDER_URL} + COMPONENT: contract_observer + MIGRATION: head links: - postgres - redis - command: > - python3 -m app.services.contract_observer etherdelta_observer: image: forkdelta/backend @@ -29,11 +29,10 @@ services: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} HTTP_PROVIDER_URL: ${HTTP_PROVIDER_URL} + COMPONENT: etherdelta_observer links: - postgres - redis - command: > - python3 -m app.services.etherdelta_observer huey_consumer: image: forkdelta/backend @@ -46,11 +45,11 @@ services: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} HTTP_PROVIDER_URL: ${HTTP_PROVIDER_URL} + HUEY_CONCURRENCY: ${HUEY_CONCURRENCY} + COMPONENT: huey_consumer links: - postgres - redis - command: > - huey_consumer.py app.services.huey_consumer.huey -w ${HUEY_CONCURRENCY} -k greenlet ticker: image: forkdelta/backend @@ -62,10 +61,9 @@ services: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} HTTP_PROVIDER_URL: ${HTTP_PROVIDER_URL} + COMPONENT: ticker links: - postgres - command: > - python3 -m app.services.ticker websocket_server: image: forkdelta/backend @@ -78,14 +76,15 @@ services: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} HTTP_PROVIDER_URL: ${HTTP_PROVIDER_URL} + COMPONENT: websocket_server links: - postgres - redis - command: > - python3 -m app.services.websocket_server postgres: image: postgres:10-alpine + ports: + - 5431:5432 environment: POSTGRES_DB: ${POSTGRES_DB} POSTGRES_USER: ${POSTGRES_USER} From 2290c2d054e95bc5414ea04f63a1b80066103647 Mon Sep 17 00:00:00 2001 From: Mourad Maatoug Date: Mon, 5 Mar 2018 16:08:55 +0100 Subject: [PATCH 4/4] fix typo error "websocket_server" to "websocket" in docker-compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3ba03bf..392dcd7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -76,7 +76,7 @@ services: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} HTTP_PROVIDER_URL: ${HTTP_PROVIDER_URL} - COMPONENT: websocket_server + COMPONENT: websocket links: - postgres - redis