Skip to content

Commit

Permalink
Merge pull request #9 from JoshuaConcon/master
Browse files Browse the repository at this point in the history
FOOD-2: Backend Initialization (+ Docker)
solves #2
  • Loading branch information
Fides Linga authored Jul 24, 2019
2 parents 264348e + db0434a commit 6333841
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 27 deletions.
20 changes: 20 additions & 0 deletions utscfood-api/Dockerfile
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"]
6 changes: 0 additions & 6 deletions utscfood-api/README.md
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`

12 changes: 0 additions & 12 deletions utscfood-api/api.py

This file was deleted.

24 changes: 24 additions & 0 deletions utscfood-api/app.py
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)
4 changes: 0 additions & 4 deletions utscfood-api/environment.yml

This file was deleted.

2 changes: 2 additions & 0 deletions utscfood-api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask
Redis
5 changes: 0 additions & 5 deletions utscfood-api/sql.py

This file was deleted.

8 changes: 8 additions & 0 deletions utscfood-api/start.sh
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}

0 comments on commit 6333841

Please sign in to comment.