-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from JoshuaConcon/master
FOOD-2: Backend Initialization (+ Docker) solves #2
- Loading branch information
Showing
8 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.7-slim | ||
|
||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . /app | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install --trusted-host pypi.python.org -r requirements.txt | ||
|
||
# Make port 80 available to the world outside this container | ||
EXPOSE 80 | ||
|
||
# Define environment variable | ||
ENV NAME World | ||
|
||
# Run app.py when the container launches | ||
CMD ["python", "app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
# utscfood-api | ||
|
||
## Installation | ||
|
||
1. create the conda environment with `conda env create -f environment.yml` | ||
2. activate the conda environment with `conda activate utscfood` | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from flask import Flask | ||
from redis import Redis, RedisError | ||
import os | ||
import socket | ||
|
||
# Connect to Redis | ||
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2) | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def hello(): | ||
try: | ||
visits = redis.incr("counter") | ||
except RedisError: | ||
visits = "<i>cannot connect to Redis, counter disabled</i>" | ||
|
||
html = "<h3>Hello {name}!</h3>" \ | ||
"<b>Hostname:</b> {hostname}<br/>" \ | ||
"<b>Visits:</b> {visits}" | ||
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits) | ||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', port=80) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Flask | ||
Redis |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# !/bin/sh | ||
|
||
# runs on port 4000 | ||
readonly HOST_PORT=4000 | ||
readonly CONTAINER_NAME=utscfood | ||
|
||
docker build --tag=${CONTAINER_NAME} . | ||
docker run -p ${HOST_PORT}:80 ${CONTAINER_NAME} |