Skip to content
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

Create prod Dockerimage from alpine base image #222

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.11-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install system dependencies
RUN apk update && \
apk add --no-cache netcat-openbsd gcc postgresql graphviz musl-dev libffi-dev

# install dependencies
RUN pip install --no-cache-dir pip~=21.3.1
COPY ./requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# # copy entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]

14 changes: 14 additions & 0 deletions app/prod/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
black~=22.3.0
Copy link
Member

Choose a reason for hiding this comment

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

I would remove black, drf-spectacular, pydot, and maybe django-linear-migrations from the production build. I don't think there's any use for them outside development.

cryptography~=37.0.2
Django~=4.0.1
django-extensions~=3.1.5
django-linear-migrations~=2.12.0
django-phonenumber-field[phonenumbers]~=6.3.0
django-timezone-field==5.0
djangorestframework~=3.13.1
drf-jwt~=1.19.2
drf-spectacular==0.22.1
psycopg2-binary~=2.9.3
pydot~=1.4.2
pytz==2022.1
tzdata==2022.1
27 changes: 27 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.8'

services:
db:
image: postgres:13.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=people_depot
- POSTGRES_PASSWORD=people_depot
- POSTGRES_DB=people_depot_dev
container_name: people_depot_db
Copy link
Member

Choose a reason for hiding this comment

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

Setting the container name might not be a good idea. I'll have to look up the reasoning for this again.

Copy link
Member

@fyliu fyliu Nov 2, 2023

Choose a reason for hiding this comment

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

Oh yeah, the container_name allows you to refer to it by name in a docker command. If you intend to refer to it using docker-compose, like docker-compose run db... then you only need to use the service name. Setting the container name also restricts docker-compose from generating multiple instances of it. I'm not sure if there's an advantage to that or not. So the reasoning for not setting it is really that it's not very useful in the docker-compose context.

web:
build: ./app/prod
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./app/:/usr/src/app/
ports:
- 8000:8000
env_file:
- ./.env.dev
Copy link
Member

Choose a reason for hiding this comment

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

Maybe have a separate .env or .env.prod file for production

container_name: people_depot_app_prod
depends_on:
- db
volumes:
postgres_data:

4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- 8000:8000
env_file:
- ./.env.dev
container_name: people_depot_dev
Copy link
Member

Choose a reason for hiding this comment

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

Same reasoning as above for not setting the container name. We're mainly referring to containers using docker-compose.

depends_on:
- db
db:
Expand All @@ -20,6 +21,7 @@ services:
- POSTGRES_USER=people_depot
- POSTGRES_PASSWORD=people_depot
- POSTGRES_DB=people_depot_dev

container_name: people_depot_db_dev
volumes:
postgres_data: