Skip to content

Commit

Permalink
build: use docker for python developement
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix committed May 31, 2023
1 parent 3518d71 commit 4cb7e4e
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 4cb7e4e

Please sign in to comment.