redone the docker for testing

test
Jukoga 2024-08-12 23:18:42 +02:00
parent 32c5a88f1c
commit 230e85d3d0
2 changed files with 29 additions and 42 deletions

View File

@ -1,34 +1,15 @@
# Use an official Python runtime as a parent image
FROM python:3.11-slim
# Use the official MariaDB base image
FROM mariadb:latest
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV MARIADB_ROOT_PASSWORD=DB_ROOTPW
ENV MARIADB_ROOT_HOST=%
ENV MARIADB_DATABASE=DBNAME
ENV MARIADB_USER=DB_USER
ENV MARIADB_PASSWORD=DB_PASSWORD
# Set working directory
WORKDIR /app
# Expose the MariaDB port
EXPOSE 3306
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
default-libmysqlclient-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install gunicorn
# Copy project files
COPY . /app/
# Expose the port on which the application will run
EXPOSE 3030
# Define environment variable for Gunicorn
ENV GUNICORN_CMD_ARGS="--bind 0.0.0.0:3030"
# Run Gunicorn server with your Django application
CMD ["gunicorn", "BH.wsgi:application"]
# Start the MariaDB service
CMD ["mysqld"]

View File

@ -1,15 +1,21 @@
version: '3.8'
services:
django:
mariadb:
build: .
env_file:
- .env
volumes:
- .:/app
container_name: mariadb
restart: unless-stopped
environment:
MARIADB_ROOT_PASSWORD: 'DB_ROOTPW'
MARIADB_ROOT_HOST: '%'
MARIADB_DATABASE: 'DBNAME'
MARIADB_USER: 'DB_USER'
MARIADB_PASSWORD: 'DB_PASSWORD'
ports:
- "3030:3030"
network_mode: "host"
command: >
sh -c "python manage.py makemigrations blog --noinput &&
python manage.py migrate --noinput &&
python manage.py collectstatic --noinput &&
gunicorn BH.wsgi:application --bind 0.0.0.0:3030 --workers ${GUNICORN_WORKERS:-3}"
- "3306:3306"
volumes:
- mariadb_data:/var/lib/mysql
volumes:
mariadb_data: