diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..0aa29ce8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +*.env + +# Python +__pycache__ +*.pyc +coverage* +.coverage +htmlcov +.pytest_cache +*.egg-info/ +*.log + +# OS +.DS_Store +*.swp + +# editors / IDEs +/.idea/ +.vscode + +# Node +node_modules/ + +# Mac +.DS_Store +._* + +# other +public/ +data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..cb7163d7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +FROM python:3.11-slim-bullseye + +# Add user that will be used in the container +RUN groupadd zednews && \ + useradd --create-home --shell /bin/bash -g zednews zednews + +RUN mkdir -p /home/zednews/app && chown zednews:zednews /home/zednews/app + +# set work directory +WORKDIR /home/zednews/app + +# set environment variables +# - Force Python stdout and stderr streams to be unbuffered. +ENV PYTHONUNBUFFERED=1 \ + PYTHONHASHSEED=random \ + PYTHONPATH=/home/zednews/app + +# Set timezone to Africa/Lusaka +RUN ln -fs /usr/share/zoneinfo/Africa/Lusaka /etc/localtime \ + && dpkg-reconfigure --frontend noninteractive tzdata + +# Install system dependencies required by the project +RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \ + build-essential \ + curl \ + git \ + ffmpeg \ + libpq-dev \ + postgresql-client \ + && rm -rf /var/lib/apt/lists/* + +# Use user "zednews" to run the build commands below and the server itself. +USER zednews + +# set up virtual environment & install python dependencies +ARG DEVELOPMENT +ENV VIRTUAL_ENV=/home/zednews/venv \ + DEVELOPMENT=${DEVELOPMENT} +RUN python -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" +RUN pip install --upgrade pip +RUN pip install pip-tools +COPY --chown=zednews ./requirements.txt . +COPY --chown=zednews ./requirements-dev.txt . +RUN python -m pip install -r requirements.txt ${DEVELOPMENT:+-r requirements-dev.txt} + +# Copy the source code of the project into the container +COPY --chown=zednews:zednews . . + +# Runtime command that executes when "docker run" is called +# basically, do nothing ... we'll run commands ourselves +CMD tail -f /dev/null diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7dc21138 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: "3.8" + +services: + app: + build: + context: . + args: + DEVELOPMENT: 1 + command: tail -f /dev/null + volumes: + - ./:/home/zednews/app/ + env_file: + - .env + depends_on: + - db + + db: + image: postgres:15.3 + expose: + - 5432 + environment: + - POSTGRES_USER=zednews_dev_user + - POSTGRES_PASSWORD=zednews_dev_password + - POSTGRES_DB=zednews_dev_db + - PGUSER=zednews_dev_user + - PGPASSWORD=zednews_dev_password + - PGDATABASE=zednews_dev_db + - POSTGRES_HOST_AUTH_METHOD=trust + volumes: + - postgres_data:/var/lib/postgresql/data/ + +volumes: + postgres_data: