Skip to content

Commit

Permalink
Merge pull request #21 from GatorEducator/feature/dockerfile
Browse files Browse the repository at this point in the history
Dockerfile
  • Loading branch information
Michionlion authored Apr 25, 2019
2 parents eb7a163 + 32515d3 commit 372c0fd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dockerfile
.dockerignore
.venv/
.git/
.gitignore
# possibly need to ignore database if using remote
# database.db
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.7.3-alpine
MAINTAINER gkapfham@allegheny.edu

ENV APP_DIR /quizagator
ENV FLASK_PORT 5000

EXPOSE ${FLASK_PORT}

# create and use the quizagator directory
WORKDIR ${APP_DIR}

# Copy the current folder to /quizagator in the image
# This should include Pipfile.lock
COPY . ${APP_DIR}

# install pipenv and dependencies into the image's system python
# (Don't use pipenv run to run things)
RUN set -ex && pip install pipenv && pipenv install --deploy --system

# the start command will run the production server
CMD python run.py --host 0.0.0.0 --port ${FLASK_PORT}
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pytest-sugar = "*"
allow_prereleases = true

[scripts]
server = "python3 run.py True"
server = "python run.py -d --port 5000 --host localhost"
test = "./scripts/test.sh"
cover = "./scripts/cover.sh"
lint = "./scripts/lint.sh"
create-image = "./scripts/create-docker-image.sh"
image = "./scripts/run-docker-image.sh"
34 changes: 30 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
"""Run this file to run the application"""

# imports everything from the application folder
import argparse

from application import app

app.secret_key = "$JLmL!eCQXyajbdu2LCJ&Vwqs2JGagg3B&FRfexCmKBV"

# starts the server, debug mode is on
app.debug = True
app.run()

parser = argparse.ArgumentParser()
parser.add_argument(
"-d, --debug",
dest="debug",
default=False,
action="store_true",
help="set debug mode",
)
parser.add_argument(
"--port",
dest="port",
type=int,
default=5000,
help="port to listen on (default: 5000)",
)
parser.add_argument(
"--host",
dest="host",
type=str,
default="0.0.0.0",
help="host to serve from (default: 0.0.0.0)",
)

args = parser.parse_args()

app.debug = args.debug
app.run(args.host, args.port)
13 changes: 13 additions & 0 deletions scripts/create-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

IMAGE_NAME="gatoreducator/quizagator"
TAG="latest"

NAME="$IMAGE_NAME"
if ! test -z "$TAG"; then
NAME="$NAME:$TAG"
fi

docker image rm --force "$NAME"

docker build -t "$NAME" .
12 changes: 12 additions & 0 deletions scripts/run-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

NAME="quizagator"
IMAGE="gatoreducator/quizagator:latest"
INNER_PORT="5000"
OUTER_PORT="4201"


docker stop "$NAME"
docker rm "$NAME"

docker run -d --name "$NAME" -p "${OUTER_PORT}:${INNER_PORT}" "$IMAGE"

0 comments on commit 372c0fd

Please sign in to comment.