Skip to content

Commit

Permalink
docker: Add startup script
Browse files Browse the repository at this point in the history
Add docker script to run `alembic upgrade head` before running application. Will be useful for making CI work when changes to Data Structures are needed.
  • Loading branch information
pablo authored Feb 23, 2022
1 parent 96a9b01 commit 0e0e438
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ __pycache__
venv/
.venv
.vscode
env
env
.idea/
9 changes: 4 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

# Copy startup script
COPY docker/startup.sh .

# Copy application
COPY . .

Expand All @@ -27,10 +30,6 @@ ENV CONTAINER_PORT=5000 \

EXPOSE ${CONTAINER_PORT}

# Setup Database

RUN alembic upgrade head

# run gunicorn
CMD ["sh", "-c", "gunicorn --bind ${BIND_INTERFACE}:${CONTAINER_PORT} --graceful-timeout ${GRACEFUL_TIMEOUT} --timeout ${TIMEOUT} --worker-class=uvicorn.workers.UvicornWorker --worker-connections ${WORKER_CONNECTIONS} --workers ${WORKERS} wsgi-service:app"]
CMD ["sh", "./startup.sh"]

24 changes: 24 additions & 0 deletions docker/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# rald-server startup script

check_env_variable() {
if [ -z $1 ]; then
echo "$2 environment variable not set";
exit 1
fi
echo "$2 -> $1"
}

echo "staring up rald-server..."

echo "Checking environment variales:"
check_env_variable $BIND_INTERFACE "BIND_INTERFACE"
check_env_variable $CONTAINER_PORT "CONTAINER_PORT"
check_env_variable $GRACEFUL_TIMEOUT "GRACEFUL_TIMEOUT"
check_env_variable $TIMEOUT "TIMEOUT"
check_env_variable $WORKER_CONNECTIONS "WORKER_CONNECTIONS"
check_env_variable $WORKERS "WORKERS"

cd /app
alembic upgrade head
gunicorn --bind ${BIND_INTERFACE}:${CONTAINER_PORT} --graceful-timeout ${GRACEFUL_TIMEOUT} --timeout ${TIMEOUT} --worker-class=uvicorn.workers.UvicornWorker --worker-connections ${WORKER_CONNECTIONS} --workers ${WORKERS} wsgi-service:app

0 comments on commit 0e0e438

Please sign in to comment.