how to use this project using docker
This commit is contained in:
parent
879366eb95
commit
172fe2f5bd
1 changed files with 13 additions and 69 deletions
82
README.md
82
README.md
|
@ -80,84 +80,28 @@ DEFAULT_FROM_EMAIL=os.getenv('DEFAULT_FROM_EMAIL')
|
||||||
CSRF_TRUSTED_ORIGINS=[os.getenv('CSRF_TRUSTED_ORIGINS')]
|
CSRF_TRUSTED_ORIGINS=[os.getenv('CSRF_TRUSTED_ORIGINS')]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Docker Stack
|
## How to use this project?
|
||||||
```docker
|
|
||||||
# docker-compose.yaml
|
|
||||||
version: '3.7'
|
|
||||||
|
|
||||||
services:
|
### Development
|
||||||
django_gunicorn:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
volumes:
|
|
||||||
- static:/static
|
|
||||||
- ./django_project:/app
|
|
||||||
restart: always
|
|
||||||
container_name: lvr_django
|
|
||||||
|
|
||||||
nginx:
|
Build the images and spin up the containers:
|
||||||
build: ./nginx
|
|
||||||
volumes:
|
|
||||||
- static:/static
|
|
||||||
depends_on:
|
|
||||||
- django_gunicorn
|
|
||||||
restart: always
|
|
||||||
container_name: lvr_nginx
|
|
||||||
labels:
|
|
||||||
- "traefik.enable=true"
|
|
||||||
- "traefik.http.routers.whoami-http.entrypoints=web"
|
|
||||||
- "traefik.http.routers.whoami-http.rule=Host(`${APP_URL}`)"
|
|
||||||
- "traefik.http.routers.whoami.rule=Host(`${APP_URL}`)"
|
|
||||||
- "traefik.http.routers.whoami.tls.certresolver=default"
|
|
||||||
- "traefik.http.routers.whoami.tls=true"
|
|
||||||
networks:
|
|
||||||
- traefik_proxy
|
|
||||||
- default
|
|
||||||
|
|
||||||
networks:
|
```sh
|
||||||
traefik_proxy:
|
$ docker-compose up -d --build
|
||||||
external:
|
|
||||||
name: traefik_proxy
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
static:
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Dockerfile
|
Test it out:
|
||||||
```
|
|
||||||
# Dockerfile
|
|
||||||
FROM python:3.10-alpine
|
|
||||||
|
|
||||||
RUN apk add --update --no-cache postgresql-client jpeg-dev
|
1. [http://django.localhost:8008/](http://django.localhost:8008/)
|
||||||
RUN apk add --update --no-cache --virtual .tmp-build-deps \
|
1. [http://django.localhost:8081/](http://django.localhost:8081/)
|
||||||
gcc libffi-dev libc-dev linux-headers postgresql-dev \
|
|
||||||
musl-dev zlib zlib-dev
|
|
||||||
|
|
||||||
RUN pip install --upgrade pip
|
### Production
|
||||||
|
|
||||||
COPY ./requirements.txt .
|
Update the domain in *docker-compose.prod.yml*, and add your email to *traefik.prod.toml*.
|
||||||
RUN pip install -r requirements.txt
|
|
||||||
|
|
||||||
# This is not installed by default
|
Build the images and run the containers:
|
||||||
RUN pip install tzdata
|
|
||||||
|
|
||||||
COPY ./django_project /app
|
```sh
|
||||||
|
$ docker-compose -f docker-compose.prod.yml up -d --build
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY ./entrypoint.sh /
|
|
||||||
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Entrypoint Shell Script
|
|
||||||
```
|
|
||||||
# entrypoint.sh
|
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
python manage.py migrate --no-input
|
|
||||||
python manage.py collectstatic --no-input
|
|
||||||
|
|
||||||
gunicorn core.wsgi:application --bind 0.0.0.0:8000
|
|
||||||
```
|
|
Loading…
Add table
Add a link
Reference in a new issue