Skip to content

Commit

Permalink
finalizing docker
Browse files Browse the repository at this point in the history
  • Loading branch information
iranzithierry committed May 19, 2024
1 parent ad228d7 commit 753bbb8
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 23 deletions.
16 changes: 16 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DJANGO_DEBUG=False # if in development ode
DJANGO_ADMIN_URL="admin/" # admin url
DJANGO_ALLOWED_HOSTS=["0.0.0.0"] #hosts allowe to render your app
DJANGO_SETTINGS_MODULE=config.settings.local #if in development else change local to production
DJANGO_SECRET_KEY=""
DJANGO_SECURE_SSL_REDIRECT=False # to prevent http to be redirected to https while you don't have ssl

CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP=True

REDIS_URL=redis://localhost:6379/0

AUTH_GITHUB_ID=""
AUTH_GITHUB_SECRET=""

APP_JWT_SIGNING_KEY=""
19 changes: 12 additions & 7 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Use an official Python runtime as a parent image
FROM python:3.11.6

ARG REQUIREMENTS_FILE
# Set the working directory in the container
WORKDIR /app

EXPOSE 8000
# Copy the requirements files before copying the rest of the application
COPY ./requirements/ ./requirements

CMD "gunicorn --bind 0.0.0.0:8000 -w 4 --limit-request-line 6094 --access-logfile - config.wsgi:application"
# Install dependencies
RUN pip install -r ./requirements/production.txt && \
pip install -r ./requirements/extra.txt

COPY ./requirements/ ./requirements
RUN pip install -r ./requirements/production.txt
RUN pip install -r ./requirements/extra.txt
# Copy the rest of the application code to the working directory
COPY . /app/

COPY . ./
# Inform Docker that the container listens on the specified port
EXPOSE 8000
16 changes: 9 additions & 7 deletions backend/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
APPS_DIR = BASE_DIR / "jeezy"
env = environ.Env()

READ_DOT_ENV_FILE = True # env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
if READ_DOT_ENV_FILE:
# OS environment variables take precedence over variables from .env
env.read_env(str(BASE_DIR / ".env"))
Expand Down Expand Up @@ -53,11 +53,11 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'jeezy',
'HOST': '127.0.0.1',
'PORT': '3306',
'USER': 'root',
'PASSWORD': '1234',
'NAME': env.str("DATABASE_NAME"),
'USER': env.str("DATABASE_USER"),
'PASSWORD': env.str("DATABASE_PASSWORD"),
'HOST': env.str("DATABASE_HOST"),
'PORT': env.str("DATABASE_PORT"),
'OPTIONS': {
'charset': 'utf8mb4',
}
Expand All @@ -84,7 +84,7 @@
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
# "django.contrib.staticfiles",
"django.contrib.staticfiles",
# "django.contrib.humanize", # Handy template tags
"django.contrib.admin",
]
Expand Down Expand Up @@ -310,3 +310,5 @@
"SIGNING_KEY": env("APP_JWT_SIGNING_KEY")
}
APPEND_SLASH = True

STATIC_ROOT = str(BASE_DIR / "staticfiles")
21 changes: 21 additions & 0 deletions delete-all-containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Ensure script is run with elevated privileges
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root. Try using sudo."
exit 1
fi

# Stop all running containers
docker stop $(docker ps -q)

# Remove all containers (including stopped ones)
docker rm $(docker ps -a -q)

# Remove all Docker images
docker rmi $(docker images -q)

# Remove dangling images
docker image prune -f

echo "All Docker containers and images have been removed."
19 changes: 15 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
services:
mysql:
image: mysql
ports:
- 3306:3306
container_name: jeezy_mariadb
volumes:
- data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 1234
MYSQL_DB: jeezy
MYSQL_DATABASE: jeezy
ports:
- 3306:3306
redis:
image: redis
ports:
Expand All @@ -16,9 +19,17 @@ services:
- mysql
ports:
- 8000:8000
container_name: jeezy_backend
env_file: backend/.env
command: "gunicorn --bind 0.0.0.0:8000 -w 4 --limit-request-line 6094 --access-logfile - config.wsgi:application"
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python manage.py runserver 0.0.0.0:8000"
# command: sh -c "python3 /app/manage.py runserver 0.0.0.0:8000"
networks:
- default
frontend:
image: iranzithierry/jeezy:frontend
ports:
- 3000:3000
depends_on:
- backend
volumes:
data:
43 changes: 38 additions & 5 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
FROM node:21.7.3
COPY package.json pnpm-lock.yaml* ./
RUN corepack enable pnpm && pnpm install
RUN corepack enable pnpm && pnpm run build
# Stage 1: Build the application
FROM node:21.7.3 AS builder

# Set working directory
WORKDIR /app

# Copy package management files first for caching
COPY package.json pnpm-lock.yaml ./

# Install dependencies using pnpm
RUN npm install -g pnpm \
&& pnpm install

# Copy the rest of the application code
COPY . .
RUN corepack enable pnpm && pnpm start

# Build the Next.js application
RUN pnpm run build

# Stage 2: Run the application
FROM node:21.7.3 AS runner

# Install pnpm
RUN npm install -g pnpm

# Set working directory
WORKDIR /app

# Copy the built application from the builder stage
COPY --from=builder /app ./

# Install only production dependencies
RUN pnpm install --prod

# Expose the port Next.js will run on
EXPOSE 3000

# Command to run the application
CMD ["pnpm", "start"]

1 comment on commit 753bbb8

@vercel
Copy link

@vercel vercel bot commented on 753bbb8 May 19, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.