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:
+67
@@ -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
|
||||
Reference in New Issue
Block a user