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/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: diff --git a/docker-compose.yml b/docker-compose.yml index a3f9a50..392dcd7 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 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} 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