Skip to content

Commit

Permalink
Add docker support;
Browse files Browse the repository at this point in the history
  • Loading branch information
arkanister committed Jul 24, 2021
1 parent f3a86c9 commit 99f3c4f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules/
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3.4'
services:
backend:
build:
context: .
dockerfile: ./dockerfiles/backend/Dockerfile
env_file: frontend/.env
ports:
- '5000:5000'
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/healthy"]
interval: 1s
timeout: 3s
retries: 10
frontend:
build:
context: .
dockerfile: ./dockerfiles/frontend/Dockerfile
env_file: backend/.env
ports:
- '8080:8080'
depends_on:
- backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/"]
interval: 1s
timeout: 3s
retries: 10
21 changes: 21 additions & 0 deletions dockerfiles/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.9-slim
ENV PYTHONUNBUFFERED 1

MAINTAINER arkanister "[email protected]"

WORKDIR /app

COPY backend/src/ .

ADD ./backend/requirements.pip /
ADD ./dockerfiles/backend/gunicorn.py /

# required for healthy check
RUN apt update && apt install curl -y

# install requirements
RUN pip install gunicorn==20.0 && \
pip install -r /requirements.pip

ENTRYPOINT ["gunicorn", "-c", "/gunicorn.py", "wsgi:application"]
EXPOSE 5000
40 changes: 40 additions & 0 deletions dockerfiles/backend/gunicorn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Application Configuration File
https://docs.gunicorn.org/en/stable/settings.html#settings
"""
import os
import multiprocessing


# Chdir to specified directory before apps loading.
# https://docs.gunicorn.org/en/stable/settings.html#chdir
chdir = '/app/'

# Bind the application on localhost both on ipv6 and ipv4 interfaces.
# https://docs.gunicorn.org/en/stable/settings.html#bind
bind = '0.0.0.0:5000'


####################
# Worker Processes #
####################

# The number of worker processes for handling requests.
# https://docs.gunicorn.org/en/stable/settings.html#workers
workers = multiprocessing.cpu_count() * 2 + 1

# The number of worker threads for handling requests.
# https://docs.gunicorn.org/en/stable/settings.html#threads
threads = 2 * multiprocessing.cpu_count()

# The maximum number of requests a worker will process before restarting.
# https://docs.gunicorn.org/en/stable/settings.html#max-requests
max_requests = os.getenv('GUNICORN_WORKER_MAX_REQUESTS', default=2400)

# The maximum jitter to add to the max_requests setting.
# https://docs.gunicorn.org/en/stable/settings.html#max-requests-jitter
max_requests_jitter = os.getenv('GUNICORN_WORKER_MAX_REQUESTS_JITTER', default=50)

# Workers silent for more than this many seconds are killed and restarted.
# https://docs.gunicorn.org/en/stable/settings.html#timeout
timeout = os.getenv('GUNICORN_WORKER_TIMEOUT', default=30)
20 changes: 20 additions & 0 deletions dockerfiles/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:lts-alpine

MAINTAINER arkanister "[email protected]"

# install simple http server for serving static content
RUN npm install -g http-server

WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
COPY frontend/ .

# install project dependencies
RUN npm install

# build app for production with minification
RUN npm run build

ENTRYPOINT ["http-server", "dist"]
EXPOSE 8080

0 comments on commit 99f3c4f

Please sign in to comment.