-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from wildjames/dev
Fix deployment?
- Loading branch information
Showing
6 changed files
with
106 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,36 @@ services: | |
web: | ||
build: . | ||
ports: | ||
- "8000:8000" | ||
- "80:80" | ||
environment: | ||
EMAIL_HOST: smtp-mail.outlook.com | ||
EMAIL_PORT: 587 | ||
EMAIL_USE_TLS: "1" | ||
EMAIL_HOST_USER: [email protected] | ||
DEFAULT_FROM_EMAIL: [email protected] | ||
EMAIL_HOST_PASSWORD: password | ||
DEBUG: "0" | ||
EMAIL_HOST_USER: | ||
DEFAULT_FROM_EMAIL: | ||
EMAIL_HOST_PASSWORD: | ||
|
||
DJANGO_DEBUG: true | ||
DJANGO_LOGGING_LEVEL: debug | ||
|
||
DJANGO_HOST_PORT: "8000" | ||
DJANGO_DB_NAME: todoqueue | ||
DJANGO_DB_USER: root | ||
DJANGO_DB_PASSWORD: password | ||
DJANGO_DB_HOST: host.docker.internal | ||
DJANGO_DB_PORT: "3306" | ||
DJANGO_SUPERUSER_EMAIL: [email protected] | ||
DJANGO_SUPERUSER_USERNAME: James | ||
DJANGO_SUPERUSER_PASSWORD: password | ||
volumes: | ||
- .:/app | ||
DJANGO_DB_NAME: | ||
DJANGO_DB_USER: | ||
DJANGO_DB_PASSWORD: | ||
DJANGO_DB_HOST: | ||
DJANGO_DB_PORT: | ||
|
||
DJANGO_CACHE_BACKEND: "redis" | ||
DJANGO_CACHE_LOCATION: "redis://cache:8379/1" | ||
|
||
DJANGO_SUPERUSER_EMAIL: | ||
DJANGO_SUPERUSER_USERNAME: | ||
DJANGO_SUPERUSER_PASSWORD: | ||
depends_on: | ||
- cache | ||
|
||
cache: | ||
image: "redis:alpine" | ||
ports: | ||
- "8379:6379" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,45 @@ | ||
# Use an official Python runtime as base image | ||
FROM python:3.11-slim | ||
# Stage 1: Build the React frontend | ||
FROM node:21 as frontend-builder | ||
WORKDIR /app | ||
COPY todoqueue_frontend/package.json todoqueue_frontend/package-lock.json ./ | ||
RUN npm install | ||
COPY todoqueue_frontend ./ | ||
RUN npm run build | ||
|
||
|
||
# Stage 2: Build the Django backend | ||
FROM python:3.12-slim as backend-builder | ||
WORKDIR /app | ||
COPY todoqueue_backend/requirements.txt ./ | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends gcc libpq-dev python3-dev default-libmysqlclient-dev pkg-config \ | ||
&& pip install --upgrade pip \ | ||
&& pip install -r requirements.txt | ||
COPY todoqueue_backend todoqueue_backend | ||
RUN ls -alh | ||
|
||
|
||
# Install system dependencies | ||
# Stage 3: Setup Nginx and final image | ||
FROM python:3.12-slim | ||
# Install Nginx | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
gcc \ | ||
libpq-dev \ | ||
python3-dev \ | ||
default-libmysqlclient-dev \ | ||
pkg-config \ | ||
npm \ | ||
&& apt-get install -y --no-install-recommends nginx default-libmysqlclient-dev \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Python dependencies | ||
COPY ./todoqueue_backend/requirements.txt /app/ | ||
WORKDIR /app | ||
RUN pip install --upgrade pip \ | ||
&& pip install -r requirements.txt | ||
# Copy the built React static files from the frontend-builder stage | ||
COPY --from=frontend-builder /app/build /var/www/html | ||
|
||
# Copy Django application | ||
COPY todoqueue_backend /app/todoqueue_backend | ||
# Copy the installed dependencies from the backend-builder stage | ||
COPY --from=backend-builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages | ||
COPY --from=backend-builder /usr/local/bin /usr/local/bin | ||
|
||
# Copy frontend application, and build it | ||
COPY todoqueue_frontend /app/todoqueue_frontend | ||
WORKDIR /app/todoqueue_frontend | ||
RUN npm install | ||
RUN npm run build | ||
# Copy the Django application from the backend-builder stage | ||
WORKDIR /app | ||
COPY --from=backend-builder /app/todoqueue_backend /app/ | ||
|
||
WORKDIR /app/todoqueue_backend | ||
# Add Nginx configuration file | ||
COPY ./nginx.conf /etc/nginx/nginx.conf | ||
|
||
CMD ["./run_server.sh"] | ||
# Start Nginx and the Django application using the entrypoint script | ||
CMD ["./run_server.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
daemon off; | ||
|
||
events {} | ||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
|
||
# Set up the server | ||
server { | ||
listen 80; | ||
|
||
# Serve static files for the frontend | ||
location / { | ||
root /var/www/html; | ||
try_files $uri /index.html; | ||
} | ||
|
||
# Proxy requests to /api to the Django backend | ||
location /api { | ||
proxy_pass http://localhost:8000; | ||
proxy_set_header Host $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; | ||
} | ||
|
||
# Proxy requests to /api to the Django backend | ||
location /admin { | ||
proxy_pass http://localhost:8000; | ||
proxy_set_header Host $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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters