Skip to content

Instantly share code, notes, and snippets.

@saroar
Last active March 8, 2024 10:17
Show Gist options
  • Save saroar/8c2974328701a0e19377e7b507209fa2 to your computer and use it in GitHub Desktop.
Save saroar/8c2974328701a0e19377e7b507209fa2 to your computer and use it in GitHub Desktop.
# Use ARG to define the default application directory, allowing override if needed
ARG APP_DIR=/app1
FROM python:3.9.18-bullseye
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Use the ARG in WORKDIR, setting the working directory
WORKDIR $APP_DIR
# Install system dependencies
RUN apt-get update && apt-get install -y \
nano \
gcc \
libpq-dev \
libc6-dev \
--no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user (do not create /logs here to avoid permissions issue with Docker on macOS/Windows)
RUN groupadd -r alif && useradd -r -g alif alif --create-home
# Switch to that user before copying files and installing Python dependencies
USER alif
# Copy and install Python dependencies
COPY --chown=alif:alif requirements.txt ./
RUN pip install --upgrade pip && pip install --user -r requirements.txt
RUN pip install gunicorn gevent
# Adjust PATH to include the user's local bin for Python packages installed with --user
ENV PATH="/home/alif/.local/bin:${PATH}"
# Copy the application files
COPY --chown=alif:alif . .
# Copy the entrypoint script and adjust permissions
COPY --chown=alif:alif entrypoint-pro.sh /entrypoint-pro.sh
RUN chmod +x /entrypoint-pro.sh
RUN python manage.py collectstatic --noinput
# Use ENTRYPOINT to specify the entrypoint script
ENTRYPOINT ["/entrypoint-pro.sh"]
CMD ["gunicorn", "VisaGlobalWeb.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3", "--worker-class", "gevent"]
# Compose file
version: '3.8'
services:
web:
build:
context: .
dockerfile: ./app1/Dockerfile_pro
args:
APP_DIR: /app1
command: gunicorn VisaGlobalWeb.wsgi:application --bind 0.0.0.0:8000 --workers 3 --worker-class gevent
environment:
- DB_HOST=pg_db
- DB_NAME=faster_visa
- DB_USER=saroar
- DB_PASSWORD=password_vfs_@#
- DB_PORT=5432
- DJANGO_PORT=8000
volumes:
- .:/app1
- static_volume:/app1/static
- static_volume:/app1/staticfiles
- media_volume:/app1/media
- logs_volume:/app1/logs
ports:
- "8000:8000"
depends_on:
- pg_db
container_name: fastervisa_web
web2:
build:
context: .
dockerfile: ./app2/Dockerfile_pro
args:
APP_DIR: /app2
command: gunicorn VisaGlobalWeb.wsgi:application --bind 0.0.0.0:8001 --workers 3 --worker-class gevent
environment:
- DB_HOST=pg_db
- DB_NAME=faster_visa
- DB_USER=saroar
- DB_PASSWORD=password_vfs_@#
- DB_PORT=5432
- DJANGO_PORT=8001
volumes:
- .:/app2
- static_volume_2:/app2/static
- media_volume_2:/app2/media
- logs_volume_2:/app2/logs
ports:
- "8001:8000"
depends_on:
- pg_db
container_name: fastervisa_web2
pg_db:
image: postgres:16
environment:
- POSTGRES_DB=faster_visa
- POSTGRES_USER=saroar
- POSTGRES_PASSWORD=password_vfs_@#
volumes:
- postgres_data:/var/lib/postgresql/data
container_name: vfs_pg_db
# before
volumes:
logs_volume:
logs_volume_2:
postgres_data:
static_volume:
static_volume_2:
media_volume:
media_volume_2:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment