Skip to content

Commit

Permalink
add dev docker
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusNeblung committed Apr 20, 2024
1 parent 5b9b32f commit d954dc6
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
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/backend/Dockerfile
volumes:
- ./:/app/backend
depends_on:
- database

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

webserver:
build: docker/webserver
depends_on:
- backend
- frontend
- database
ports:
- 8000:8000
- 3000:3000
21 changes: 21 additions & 0 deletions {{ cookiecutter.project_slug }}/docker/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/backend/env.dev.local /app/config/.env.dev.local

EXPOSE 8000

#USER www-data:www-data
ADD ./docker/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/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/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/frontend/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

pnpm install
npm run dev
5 changes: 5 additions & 0 deletions {{ cookiecutter.project_slug }}/docker/webserver/Dockerfile
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/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 d954dc6

Please sign in to comment.