Skip to content

Commit

Permalink
♻️ Add support for Python 3.12 (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo authored Sep 8, 2024
1 parent 30c8ad0 commit 1bc9081
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ jobs:
matrix:
image:
- name: latest
python_version: "3.11"
python_version: "3.12"
- name: python3.12
python_version: "3.12"
- name: python3.11
python_version: "3.11"
- name: python3.10
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
matrix:
image:
- name: latest
python_version: "3.11"
python_version: "3.12"
- name: python3.12
python_version: "3.12"
- name: python3.11
python_version: "3.11"
- name: python3.10
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Supported tags and respective `Dockerfile` links

* [`python3.11`, `latest` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/docker-images/python3.11.dockerfile)
* [`python3.12`, `latest` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/docker-images/python3.12.dockerfile)
* [`python3.11`, _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/docker-images/python3.11.dockerfile)
* [`python3.10`, _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/docker-images/python3.10.dockerfile)
* [`python3.9`, _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/docker-images/python3.9.dockerfile)
* [`python3.8` _(Dockerfile)_](https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/docker-images/python3.8.dockerfile)
Expand Down Expand Up @@ -141,7 +142,7 @@ You can use this image as a base image for other images.
Assuming you have a file `requirements.txt`, you could have a `Dockerfile` like this:

```Dockerfile
FROM tiangolo/uwsgi-nginx:python3.11
FROM tiangolo/uwsgi-nginx:python3.12

COPY ./requirements.txt /app/requirements.txt

Expand All @@ -167,7 +168,7 @@ If you need to use a directory for your app different than `/app`, you can overr
For example, if you needed to have your application directory in `/application` instead of `/app`, your `Dockerfile` would look like:

```Dockerfile
FROM tiangolo/uwsgi-nginx:python3.11
FROM tiangolo/uwsgi-nginx:python3.12

ENV UWSGI_INI /application/uwsgi.ini

Expand Down Expand Up @@ -199,7 +200,7 @@ Have in mind that `UWSGI_CHEAPER` must be lower than `UWSGI_PROCESSES`.
So, if, for example, you need to start with 4 processes and grow to a maximum of 64, your `Dockerfile` could look like:

```Dockerfile
FROM tiangolo/uwsgi-nginx:python3.11
FROM tiangolo/uwsgi-nginx:python3.12

ENV UWSGI_CHEAPER 4
ENV UWSGI_PROCESSES 64
Expand All @@ -218,7 +219,7 @@ For example, if you wanted to set the maximum upload file size to 1 MB (the defa
So, your `Dockerfile` would look something like:

```Dockerfile
FROM tiangolo/uwsgi-nginx:python3.11
FROM tiangolo/uwsgi-nginx:python3.12

ENV NGINX_MAX_UPLOAD 1m

Expand All @@ -236,7 +237,7 @@ You might also need to create the respective `EXPOSE` Docker instruction.
You can do that in your `Dockerfile`, it would look something like:

```Dockerfile
FROM tiangolo/uwsgi-nginx:python3.11
FROM tiangolo/uwsgi-nginx:python3.12

ENV LISTEN_PORT 8080

Expand Down Expand Up @@ -290,7 +291,7 @@ or you can set it to the keyword `auto` and it will try to autodetect the number
For example, using `auto`, your Dockerfile could look like:

```Dockerfile
FROM tiangolo/uwsgi-nginx:python3.11
FROM tiangolo/uwsgi-nginx:python3.12

ENV NGINX_WORKER_PROCESSES auto

Expand Down
70 changes: 70 additions & 0 deletions docker-images/python3.12.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
FROM python:3.12-bullseye

LABEL maintainer="Sebastian Ramirez <[email protected]>"

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

COPY install-nginx-debian.sh /

RUN bash /install-nginx-debian.sh

# Install requirements
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt

# Remove default configuration from Nginx
RUN rm /etc/nginx/conf.d/default.conf
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
COPY uwsgi.ini /etc/uwsgi/

# Install Supervisord
RUN apt-get update && apt-get install -y supervisor \
&& rm -rf /var/lib/apt/lists/*
# Custom Supervisord config
COPY supervisord-debian.conf /etc/supervisor/conf.d/supervisord.conf

# Copy stop-supervisor.sh to kill the supervisor and substasks on app failure
COPY stop-supervisor.sh /etc/supervisor/stop-supervisor.sh
RUN chmod +x /etc/supervisor/stop-supervisor.sh

# Which uWSGI .ini file should be used, to make it customizable
ENV UWSGI_INI /app/uwsgi.ini

Check warning on line 32 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (latest, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 32 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (python3.12, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# By default, run 2 processes
ENV UWSGI_CHEAPER 2

Check warning on line 35 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (latest, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 35 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (python3.12, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# By default, when on demand, run up to 16 processes
ENV UWSGI_PROCESSES 16

Check warning on line 38 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (latest, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 38 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (python3.12, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# By default, allow unlimited file sizes, modify it to limit the file sizes
# To have a maximum of 1 MB (Nginx's default) change the line to:
# ENV NGINX_MAX_UPLOAD 1m
ENV NGINX_MAX_UPLOAD 0

Check warning on line 43 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (latest, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 43 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (python3.12, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# By default, Nginx will run a single worker process, setting it to auto
# will create a worker for each CPU core
ENV NGINX_WORKER_PROCESSES 1

Check warning on line 47 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (latest, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 47 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (python3.12, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# By default, Nginx listens on port 80.
# To modify this, change LISTEN_PORT environment variable.
# (in a Dockerfile or with an option for `docker run`)
ENV LISTEN_PORT 80

Check warning on line 52 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (latest, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 52 in docker-images/python3.12.dockerfile

View workflow job for this annotation

GitHub Actions / deploy (python3.12, 3.12)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app
COPY start.sh /start.sh
RUN chmod +x /start.sh

# Copy the entrypoint that will generate Nginx additional configs
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

# Add demo app
COPY ./app /app
WORKDIR /app

# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations)
# And then will start Supervisor, which in turn will start Nginx and uWSGI
CMD ["/start.sh"]
3 changes: 2 additions & 1 deletion scripts/process_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys

environments = [
{"NAME": "latest", "PYTHON_VERSION": "3.11"},
{"NAME": "latest", "PYTHON_VERSION": "3.12"},
{"NAME": "python3.12", "PYTHON_VERSION": "3.12"},
{"NAME": "python3.11", "PYTHON_VERSION": "3.11"},
{"NAME": "python3.10", "PYTHON_VERSION": "3.10"},
{"NAME": "python3.9", "PYTHON_VERSION": "3.9"},
Expand Down

0 comments on commit 1bc9081

Please sign in to comment.