Dockerfile for automated docker deployment (#1)

* Initial Dockerfile

* Dockerfile: install without caching in production

* dockerfile: added ARG/ENV for deployment dir

* dockerfile: removed unnecessary tinkering with PYTHONPATH

* dockerfile: added ARG/ENV for listening port

* dockerfile: added cleanup of tests and makefile

* dockerfile: added health check
This commit is contained in:
Kai Fabian
2018-10-21 19:22:15 +02:00
committed by f4lco
parent e0b88bbc87
commit 0653c75e43
2 changed files with 71 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
ARG DEPLOY_DIR=/opt/om-parser-stw-potsdam-v2
ARG LISTEN_PORT=3080
# Build & test container
FROM python:2.7-alpine as buildsys
ARG DEPLOY_DIR
# Install required dependencies
RUN apk add make
RUN pip install pipenv
# Add app user
RUN adduser -D flaskd
# Create app folder
RUN mkdir -p ${DEPLOY_DIR}
WORKDIR ${DEPLOY_DIR}
# Copy app folder contents
COPY stw_potsdam/ ./stw_potsdam
COPY tests ./tests
COPY Makefile .
COPY Pipfile .
COPY Pipfile.lock .
# Apply app user to app folder
RUN chown -R flaskd:flaskd .
# Prepare environment
USER flaskd
# Install environment
RUN pipenv install --two --dev
# Run tests
RUN make test
# Executable container
FROM python:2.7-alpine
ARG DEPLOY_DIR
ARG LISTEN_PORT
ENV LISTEN_PORT=$LISTEN_PORT
ENV LISTEN=0.0.0.0:$LISTEN_PORT
RUN apk add --no-cache uwsgi uwsgi-python curl
RUN pip install pipenv
RUN adduser -D flaskd
COPY --from=buildsys ${DEPLOY_DIR} ${DEPLOY_DIR}
WORKDIR ${DEPLOY_DIR}
RUN rm -rf ./tests ./Makefile
RUN chown -R flaskd:flaskd .
USER flaskd
ENV PIPENV_VENV_IN_PROJECT=1
RUN pipenv install --two --deploy
EXPOSE $LISTEN_PORT
CMD pipenv run uwsgi --master --http11-socket $LISTEN --plugins python --protocol uwsgi --wsgi stw_potsdam.views:app --virtualenv ./.venv
HEALTHCHECK --interval=15s --timeout=3s CMD curl -f http://127.0.0.1:$LISTEN_PORT/health_check || exit 1
+4
View File
@@ -54,3 +54,7 @@ def canteen_feed(canteen_name):
canteen = config[canteen_name] canteen = config[canteen_name]
menu = get_menu_cached(canteen) menu = get_menu_cached(canteen)
return canteen_feed_xml(canteen, menu) return canteen_feed_xml(canteen, menu)
@app.route('/health_check')
def health_check():
return make_response("OK", 200)