Skip to content

Commit

Permalink
Merge pull request #2 from fsinfuhh/feat/devDocker
Browse files Browse the repository at this point in the history
add dev docker
  • Loading branch information
MarkusNeblung authored Apr 25, 2024
2 parents 5b9b32f + 71a9cc4 commit 1b6bc63
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 3 deletions.
6 changes: 3 additions & 3 deletions {{ cookiecutter.project_slug }}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ FROM docker.io/debian:bookworm as final
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update &&\
apt-get install -y --no-install-recommends nodejs python3 python-is-python3 pipenv nginx gunicorn xz-utils supervisor
COPY docker/supervisord.conf /etc/supervisor/supervisord.conf
COPY docker/start_backend.sh docker/start_frontend.sh docker/start_nginx.sh /usr/local/bin/
COPY docker/prod/supervisord.conf /etc/supervisor/supervisord.conf
COPY docker/prod/start_backend.sh docker/prod/start_frontend.sh docker/prod/start_nginx.sh /usr/local/bin/
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

# install django server
Expand All @@ -32,7 +32,7 @@ ADD Pipfile Pipfile.lock ./
RUN pipenv install --system --deploy
ADD LICENSE README.md ./
ADD src/ ./src/
ADD docker/nginx.conf /etc/nginx/sites-enabled/default
ADD docker/prod/nginx.conf /etc/nginx/sites-enabled/default

# add built frontend sources
COPY --from=gui_build /usr/local/src/{{ cookiecutter.project_slug }}_gui/.output ./src/{{ cookiecutter.project_slug }}_gui/dist/
Expand Down
12 changes: 12 additions & 0 deletions {{ cookiecutter.project_slug }}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ The following variables are defined:
| `NUXT_PUBLIC_OPENID_ISSUER` | *mafiasi-identity* | no | The openid issuer which the frontend uses for authentication (should be the same as the one in configured for django) |

For the configuration of these variables in `dev` mode, see the configuration in [.env.dev](./.env.dev).

## Docker Setup

This project contains two different docker setup. One is for production, one for development.

### Production Setup

The Docker Setup for production consists of the `Dockerfile` in the root of this project. The required assets are in the `/docker/prod` directory.

### Development Setup

The Docker Setup for development is based on the `compose.yaml` in the root of this project. All Dockerfiles and other files required for this are in the `/docker/dev` directory.
33 changes: 33 additions & 0 deletions {{ cookiecutter.project_slug }}/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
database:
image: postgres
volumes:
- ./dev_db:/var/lib/postgresql/data
environment:
- POSTGRES_USER={{ cookiecutter.project_slug }}
- POSTGRES_PASSWORD={{ cookiecutter.project_slug }}
- POSTGRES_DB={{ cookiecutter.project_slug }}

backend:
build:
context: ./
dockerfile: ./docker/dev/backend/Dockerfile
volumes:
- ./:/app/backend
depends_on:
- database

frontend:
build: docker/dev/frontend
volumes:
- ./src/{{ cookiecutter.project_slug }}_gui:/app/frontend

webserver:
build: docker/dev/webserver
depends_on:
- backend
- frontend
- database
ports:
- 8000:8000
- 3000:3000
21 changes: 21 additions & 0 deletions {{ cookiecutter.project_slug }}/docker/dev/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.11-slim

# Install normal dependencies
RUN apt-get update && apt-get -y --no-install-recommends install build-essential nginx && rm -rf /var/lib/apt/lists/*

# Add project code to container
VOLUME /app/backend
WORKDIR /app/backend

# Install Python dependencies
RUN pip3 install pipenv==v2022.4.20

RUN usermod -u 2009 -g 33 -d /app/backend www-data

ADD ./docker/dev/backend/env.dev.local /app/config/.env.dev.local

EXPOSE 8000

#USER www-data:www-data
ADD ./docker/dev/backend/start.sh /usr/local/bin/start.sh
CMD ["bash", "/usr/local/bin/start.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DJANGO_DB=postgres://{{ cookiecutter.project_slug }}:{{ cookiecutter.project_slug }}@database:5432/{{ cookiecutter.project_slug }}
8 changes: 8 additions & 0 deletions {{ cookiecutter.project_slug }}/docker/dev/backend/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

ln -sf /app/config/.env.dev.local /app/backend/.env.dev.local

pipenv install --dev --system --ignore-pipfile

python3 src/manage.py migrate
python3 src/manage.py runserver 0.0.0.0:8000
15 changes: 15 additions & 0 deletions {{ cookiecutter.project_slug }}/docker/dev/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:21-slim

VOLUME /app/frontend
WORKDIR /app/frontend

ADD ./start.sh /usr/local/bin/start.sh

RUN npm install -g pnpm

RUN chmod 774 /usr/local/bin/start.sh

USER 1000
EXPOSE 3000

CMD ["bash", "/usr/local/bin/start.sh"]
4 changes: 4 additions & 0 deletions {{ cookiecutter.project_slug }}/docker/dev/frontend/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

pnpm install
npm run dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:stable

ADD nginx.conf /etc/nginx/nginx.conf

EXPOSE 8000
58 changes: 58 additions & 0 deletions {{ cookiecutter.project_slug }}/docker/dev/webserver/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" ';

access_log /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 65;

server {
listen 8000;
server_name default_server;

location ~* ^/(django-static|api|admin|media).* {
proxy_pass http://backend:8000;
proxy_hide_header Upgrade;
client_max_body_size 0;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location / {
proxy_pass http://frontend:3000/;
proxy_hide_header Upgrade;
client_max_body_size 0;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /_nuxt {
proxy_pass http://frontend:3000/_nuxt;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
}

0 comments on commit 1b6bc63

Please sign in to comment.