Skip to content

Commit

Permalink
Rework local dev container to Alpine + Poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Feb 23, 2024
1 parent dae0de7 commit a56490f
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Backend_run__ONCE_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Check_translations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Development_reset.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Fake_datasource.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Lock_migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Manage_py.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Migrate.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Test_MySQL.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Docker__Test_PostgreSQL.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/how-to/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Setting up a development environment using Docker

- Containers built? See if this command works::

docker exec -it dsmr-app poetry run /app/manage.py check
docker exec -it dsmr-app poetry run /usr/src/app/manage.py check

# Expected output: "System check identified no issues (0 silenced)"

Expand All @@ -76,7 +76,7 @@ To be honest, the best initial/fixture data is simply a backup of your own syste

After importing the backup of your production system, simply run::

docker exec -it dsmr-app poetry run /app/manage.py development_reset
docker exec -it dsmr-app poetry run /usr/src/app/manage.py development_reset

This will remove all API keys and other links to externals systems, as well as reset the admin user credentials to ``admin / admin`` (user / password).

Expand All @@ -100,13 +100,13 @@ Fake datalogger

There is a builtin command that can somewhat fake a datalogger::

docker exec -it dsmr-app poetry run /app/manage.py dsmr_fake_datasource --with-gas --with-electricity-returned
docker exec -it dsmr-app poetry run /usr/src/app/manage.py dsmr_fake_datasource --with-gas --with-electricity-returned

It will generate random data every second in a certain pattern and should be fine for basic testing.

Please note that it only inserts unprocessed readings, so you'll still have to run the following command to have the readings processed::

docker exec -it dsmr-app poetry run /app/manage.py dsmr_backend --run-once
docker exec -it dsmr-app poetry run /usr/src/app/manage.py dsmr_backend --run-once


Running DSMR-reader locally
Expand Down
65 changes: 27 additions & 38 deletions dsmrreader/provisioning/container/Containerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,44 @@

ARG PYTHON_VERSION="3.11"

### Base: OS + venv + base requirements
FROM python:${PYTHON_VERSION}-bullseye AS local-dsmrreader-base
WORKDIR /app
ENV PYTHONUNBUFFERED=1

RUN apt-get update && \
apt-get install -y \
python3 \
python3-psycopg2 \
python3-pip \
python3-venv

# Credits to: https://pythonspeed.com/articles/activate-virtualenv-dockerfile/
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
### OS + venv + dependencies
FROM python:${PYTHON_VERSION}-alpine AS local-dsmrreader-dev
WORKDIR /usr/src/app

COPY ./dsmrreader/provisioning/requirements/base.txt /app/dsmrreader/provisioning/requirements/
RUN pip3 install pip --upgrade && \
pip3 install -r dsmrreader/provisioning/requirements/base.txt


### Dev: Debug/dev tools + mysql client
FROM local-dsmrreader-base AS local-dsmrreader-dev
RUN apt-get install -y \
telnet \
cu \
ENV PYTHONUNBUFFERED=1
RUN apk add --update \
build-base \
gcc \
libffi-dev

### Debug/dev tools
RUN apk add --update \
inetutils-telnet \
gettext \
libmariadb-dev \
libopenjp2-7-dev \
openjpeg \
mariadb-dev \
postgresql-client

COPY ./dsmrreader/provisioning/requirements/dev.txt /app/dsmrreader/provisioning/requirements/
RUN pip3 install -r dsmrreader/provisioning/requirements/dev.txt
ENV POETRY_VIRTUALENVS_IN_PROJECT=false
COPY ./pyproject.toml ./poetry.lock /usr/src/app/
RUN pip install poetry
RUN poetry self add poetry-plugin-export
RUN poetry install --no-root --with dev



### Runserver instance
### Dev: Runserver instance
FROM local-dsmrreader-dev AS local-dsmrreader-app
WORKDIR /app
ENTRYPOINT python3 manage.py runserver 0.0.0.0:8000
WORKDIR /usr/src/app
ENTRYPOINT poetry run python manage.py runserver 0.0.0.0:8000



### Docs instance(s) - Language parameter does not seem to be supported dynamically...
### Dev: Docs instance(s) - Language parameter does not seem to be supported dynamically...
FROM local-dsmrreader-dev AS local-dsmrreader-docs-en
WORKDIR /app/docs
ENTRYPOINT sphinx-autobuild . /var/tmp/_build/html --host 0.0.0.0 --port 10000 -D language=en
WORKDIR /usr/src/app/docs
ENTRYPOINT poetry run sphinx-autobuild . /var/tmp/_build/html --host 0.0.0.0 --port 10000 -D language=en

FROM local-dsmrreader-dev AS local-dsmrreader-docs-nl
WORKDIR /app/docs
ENTRYPOINT sphinx-autobuild . /var/tmp/_build/html --host 0.0.0.0 --port 10000 -D language=nl
WORKDIR /usr/src/app/docs
ENTRYPOINT poetry run sphinx-autobuild . /var/tmp/_build/html --host 0.0.0.0 --port 10000 -D language=nl
8 changes: 4 additions & 4 deletions dsmrreader/provisioning/container/compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
args:
- PYTHON_VERSION=3.11
volumes:
- .:/app
- .:/usr/src/app
ports:
- '8000:8000'
depends_on:
Expand Down Expand Up @@ -60,7 +60,7 @@ services:
dockerfile: Containerfile
target: local-dsmrreader-docs-en
volumes:
- .:/app
- .:/usr/src/app
ports:
- '10000:10000'

Expand All @@ -72,7 +72,7 @@ services:
dockerfile: Containerfile
target: local-dsmrreader-docs-nl
volumes:
- .:/app
- .:/usr/src/app
ports:
- '10001:10000'

Expand All @@ -88,7 +88,7 @@ services:
timeout: 5s
retries: 10
# # Only use for restoring DB-backups when developing.
# # E.g. in container: psql -U dsmrreader -f /var/run/host/Desktop/dsmrreader-postgresql-backup-Saturday.sql dsmrreader
# # E.g. in container: psql -U dsmrreader -f /run/host/Desktop/dsmrreader-postgresql-backup-Friday.sql dsmrreader
# volumes:
# - ~/Desktop:/run/host/Desktop/
environment:
Expand Down

0 comments on commit a56490f

Please sign in to comment.