Skip to content

Commit

Permalink
Dockerize front-end API
Browse files Browse the repository at this point in the history
- Change URL of dependent services to env variables instead
    - Allow host names and ports to be specified dynamically on container creation
- Update requirements.txt with full list of packages
- Add Dockerfile
- Add API to docker-compose.yml as a new service
  • Loading branch information
gabrielwong159 committed Oct 19, 2021
1 parent 2e3b78d commit 9fa9867
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
8 changes: 8 additions & 0 deletions apis/front/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# docker build -t evs-front-api .
FROM python:3.9-alpine3.12

COPY app.py requirements.txt demo.json ./
RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:app"]
9 changes: 5 additions & 4 deletions apis/front/app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import logging
import json
import os
import requests
from flask import Flask, request
from flask_cors import CORS
from operator import itemgetter

DB_API_HOST = 'localhost'
DB_API_PORT = 8001
DB_API_HOST = os.environ.get('DB_API_HOST', 'localhost')
DB_API_PORT = os.environ.get('DB_API_PORT', 8001)

WEB_API_HOST = 'localhost'
WEB_API_PORT = 5000
WEB_API_HOST = os.environ.get('WEB_API_HOST', 'localhost')
WEB_API_PORT = os.environ.get('WEB_API_PORT', 5000)

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
Expand Down
2 changes: 2 additions & 0 deletions apis/front/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
flask
flask-cors
gunicorn
requests
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ services:
container_name: evs_web_api
ports:
- "${WEB_API_PORT}:8080"
restart: "on-failure"

frontend_api:
depends_on:
- db_api
- web_api
build: apis/front
image: evs-front-api:latest
container_name: evs_front_api
ports:
- "${FRONTEND_API_PORT}:8080"
environment:
DB_API_HOST: "db_api"
DB_API_PORT: "8080"
WEB_API_HOST: "web_api"
WEB_API_PORT: "8080"
restart: "on-failure"

telebot:
depends_on:
Expand Down

0 comments on commit 9fa9867

Please sign in to comment.