-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: use docker for python developement
- Loading branch information
1 parent
3518d71
commit 4cb7e4e
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |