Skip to content

Commit f0395e2

Browse files
authored
Merge pull request #27 from rafsaf/update-dockerfile-move-to-uvicorn
Update dockerfile to use uvicorn instead of nginx unit for python 3.1…
2 parents 83f60c5 + 9c618c4 commit f0395e2

File tree

5 files changed

+908
-710
lines changed

5 files changed

+908
-710
lines changed
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
# See https://unit.nginx.org/installation/#docker-images
2-
3-
FROM nginx/unit:1.28.0-python3.10
1+
FROM python:3.11.1-slim-bullseye
42

53
ENV PYTHONUNBUFFERED 1
6-
7-
RUN apt-get update && apt-get install -y python3-pip
8-
9-
# Build folder for our app, only stuff that matters copied.
10-
RUN mkdir build
114
WORKDIR /build
125

13-
# Update, install requirements and then cleanup.
14-
COPY ./requirements.txt .
6+
# Create venv, add it to path and install requirements
7+
RUN python -m venv /venv
8+
ENV PATH="/venv/bin:$PATH"
159

10+
COPY requirements.txt .
1611
RUN pip install -r requirements.txt
1712

18-
RUN apt-get remove -y python3-pip \
19-
&& apt-get autoremove --purge -y \
20-
&& rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/*.list
13+
# Install uvicorn server
14+
RUN pip install uvicorn[standard]
2115

2216
# Copy the rest of app
23-
COPY app ./app
24-
COPY alembic ./alembic
17+
COPY app app
18+
COPY alembic alembic
2519
COPY alembic.ini .
2620
COPY pyproject.toml .
21+
COPY init.sh .
22+
23+
# Create new user to run app process as unprivilaged user
24+
RUN addgroup --gid 1001 --system uvicorn && \
25+
adduser --gid 1001 --shell /bin/false --disabled-password --uid 1001 uvicorn
2726

28-
# Nginx unit config and init.sh will be consumed at container startup.
29-
COPY init.sh /docker-entrypoint.d/init.sh
30-
COPY nginx-unit-config.json /docker-entrypoint.d/config.json
31-
RUN chmod a+x /docker-entrypoint.d/init.sh
27+
# Run init.sh script then start uvicorn
28+
RUN chown -R uvicorn:uvicorn /build
29+
CMD bash init.sh && \
30+
runuser -u uvicorn -- /venv/bin/uvicorn app.main:app --app-dir /build --host 0.0.0.0 --port 8000 --workers 2 --loop uvloop
31+
EXPOSE 8000

{{cookiecutter.project_name}}/docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
- DEFAULT_DATABASE_HOSTNAME=postgres
3131
- DEFAULT_DATABASE_PORT=5432
3232
ports:
33-
- 80:80
33+
- 80:8000
3434

3535
volumes:
3636
postgres_data:

{{cookiecutter.project_name}}/nginx-unit-config.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)