Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
python-flask: Avoid permission errors when building dependencies (#834)
Browse files Browse the repository at this point in the history
* Avoid clashing UIDs

* increment stack version

* Add additional debug

* Ensure permission settings work on Linux & macOS

* fix typo in comment
  • Loading branch information
henrynash authored Jun 16, 2020
1 parent f240fc2 commit fe8e2b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions incubator/python-flask/image/Dockerfile-stack
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ ENV PATH=/home/worker/.local/bin:$PATH

ENV APPSODY_MOUNTS=/:/project/userapp
ENV APPSODY_DEPS=/project/deps
ENV APPSODY_USER_RUN_AS_LOCAL=true
# This (and the project) Dockerfile already ensure we run as worker, rather than root - so don't enable running as the local
# user, since this would cause a clash of two different UIDs
ENV APPSODY_USER_RUN_AS_LOCAL=false

ENV APPSODY_WATCH_DIR=/project/userapp
ENV APPSODY_WATCH_REGEX="^.*.py$"

ENV APPSODY_PREP="cd /project/userapp;pipenv lock -r > requirements.txt;python -m pip install -r requirements.txt -t /project/deps"
ENV APPSODY_PREP="cd /project/userapp;pipenv lock -r > ../requirements-additional.txt;python -m pip install -r ../requirements-additional.txt -t /project/deps"

ENV APPSODY_RUN="python -m flask run --host=0.0.0.0 --port=8080"
ENV APPSODY_RUN_ON_CHANGE=$APPSODY_RUN
Expand Down
8 changes: 6 additions & 2 deletions incubator/python-flask/image/project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ FROM python:3.7
RUN pip install --upgrade pip

RUN useradd -m worker
USER worker
WORKDIR /project
# It is a real shame that WORKDIR doesn't honor the current user (or even take a chown option), so.....
RUN chown worker:worker /project
USER worker

RUN pip install --upgrade --user pipenv
ENV PATH=/home/worker/.local/bin:$PATH

COPY --chown=worker:worker . ./

# First we get the dependencies for the stack itself
RUN pipenv lock -r > requirements.txt
# Now add in any for the app, that the developer has added (there seems to be
# no easy way of specifying a different location for the Pipfile, so have to
# change the working directory!)
WORKDIR /project/userapp
RUN pipenv lock -r > ../requirements.txt
RUN pipenv lock -r > ../requirements-additional.txt
# Now process the combined requirements
WORKDIR /project
RUN python -m pip install -r requirements.txt -t /project/deps
RUN python -m pip install -r requirements-additional.txt -t /project/deps

ENV PYTHONPATH=/project/deps
ENV FLASK_APP=server/__init__.py
Expand Down
2 changes: 1 addition & 1 deletion incubator/python-flask/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Python Flask
version: 0.2.3
version: 0.2.4
description: Flask web Framework for Python
language: python
maintainers:
Expand Down

0 comments on commit fe8e2b8

Please sign in to comment.