Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Add entrypoint for Dockerfile #67

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 9 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why the port change here?

environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
Expand Down
38 changes: 38 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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