Skip to content

Commit

Permalink
Add pipenv example
Browse files Browse the repository at this point in the history
  • Loading branch information
pmac committed Feb 15, 2019
1 parent cb26977 commit d0cab10
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 3 deletions.
64 changes: 64 additions & 0 deletions Dockerfile-pipenv
@@ -0,0 +1,64 @@
# This is the same idea as Dockerfile, but this one uses pipenv with the Pipfile
# and Pipfile.lock instead of requirements.txt.
#
########
# Python dependencies builder
#
FROM python:3-stretch AS builder

# Always set a working directory
WORKDIR /app
# Sets utf-8 encoding for Python
ENV LANG=C.UTF-8
# Turns off writing .pyc files. Superfluous on an ephemeral container.
ENV PYTHONDONTWRITEBYTECODE=1
# Seems to speed things up
ENV PYTHONUNBUFFERED=1

# Ensures that the python and pip executables used
# in the image will be those from our virtualenv.
ENV PATH="/venv/bin:$PATH"

# Install OS package dependencies.
# Do all of this in one RUN to limit final image size.
RUN apt-get update && \
apt-get install -y --no-install-recommends gettext build-essential && \
rm -rf /var/lib/apt/lists/*

# Setup the virtualenv
RUN python -m venv /venv

# Install Python deps
RUN pip install pipenv
COPY Pipfile Pipfile.lock ./
RUN pipenv install --system --deploy


########
# slim app container
#
FROM python:3-slim-stretch AS app

# Extra python env
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PATH="/venv/bin:$PATH"
ENV PORT=8000

# add non-priviledged user
RUN adduser --uid 1000 --disabled-password --gecos '' --no-create-home webdev

WORKDIR /app
EXPOSE 8000
CMD ["python", "app.py"]

# copy in Python environment
COPY --from=builder /venv /venv

COPY ./static ./static
COPY ./templates ./templates
COPY ./app.py ./

RUN chown webdev.webdev -R .
USER webdev
12 changes: 12 additions & 0 deletions Pipfile
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
responder = "*"

[requires]
python_version = "3.7"

0 comments on commit d0cab10

Please sign in to comment.