Skip to content

Update Python and Flask usage in Compose tutorial #8609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 23, 2019
Merged

Update Python and Flask usage in Compose tutorial #8609

merged 4 commits into from
May 23, 2019

Conversation

davidism
Copy link
Contributor

@davidism davidism commented Apr 7, 2019

  • Uses the modern Python 3.7 image, as 3.4 is EOL.
  • Use COPY instead of ADD, since behavior of ADD is not used, as recommended in the Dockerfile reference.
  • Separates copying and installing requirements from copying project, to make rebuilds more efficient if no requirements change.
  • Uses the recommended flask run command. This is especially needed on Windows, where app.py incorrectly looks like an executable file when copying into Docker. 0.15.0 causes OSError: [Errno 8] Exec format error: in Docker for Windows pallets/werkzeug#1482
  • Uses the FLASK_ENV env var to control development mode (debugger, reloader). This is only set when demonstrating the volumes option for live updating files, as it should not be used in production. Note that the development server (flask run, app.run()) should not be used in production either, but I think that's outside the scope of this change.
  • Install gcc and dev headers so simple C extensions such as MarkupSafe and SQLAlchemy speedups can compile on Alpine (wheels on pypi are only built for glibc).

davidism added 2 commits April 7, 2019 02:02

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* Uses the modern Python 3.7 image, as 3.4 is EOL.
* Separates copying and installing requirements from copying
  project, to make rebuilds more efficient.
* Uses the recommended `flask run` command. This is especially
  needed on Windows, where `app.py` incorrectly looks like an
  executable file when copying into Docker.
* Uses the `FLASK_ENV` env var to control development mode.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This is not needed when using the recommended `flask run`
command to run the development server.
@GordonTheTurtle
Copy link

Deploy preview for docsdocker ready!

Built with commit 86f7166

https://deploy-preview-8609--docsdocker.netlify.com

@GordonTheTurtle
Copy link

GordonTheTurtle commented Apr 7, 2019

Deploy preview for docsdocker ready!

Built with commit f5da7af

https://deploy-preview-8609--docsdocker.netlify.com

@davidism davidism changed the title Update Python and Flask usage in Dockerfile Update Python and Flask usage in Compose tutorial Apr 7, 2019
@bermudezmt bermudezmt added the area/compose Relates to docker-compose.yml spec or docker-compose binary label Apr 8, 2019
Copy link
Member

@chris-crone chris-crone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @davidism!

Just a couple of minor changes.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Member

@chris-crone chris-crone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit but otherwise LGTM

* Install the Python dependencies.
* Set the default command for the container to `python app.py`.
* Set environment variables used by the `flask` command.
* Install gcc so Python packages such as MarkupSafe and SQLAlchemy can compile speedups.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since this is just a Compose get started guide, I'm not sure we need to include Python optimisations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is one of two official Docker documents introducing devs to using Flask with Docker, I'd rather they get a reasonable experience without having to discover it later, especially since it's non-obvious that speedups are not compiled. Overall I think the focus is still on Compose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you agree, or would you like me to change something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is that we're conflating getting started with Compose and optimising a Python app. That might overload new users with too much information.

I did LGTM the PR though as it's net better than what we have currently.

@usha-mandya is there anything else we need?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't think of anything else, @chris-crone. Thanks.

@usha-mandya usha-mandya self-requested a review April 25, 2019 09:44
Copy link
Member

@usha-mandya usha-mandya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@usha-mandya usha-mandya merged commit ac09901 into docker:master May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/compose Relates to docker-compose.yml spec or docker-compose binary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants