Skip to content

Commit fa78adf

Browse files
author
Alan Christie
committed
Merge branch 'staging' into m2ms-1291
2 parents e93eb1e + f496abe commit fa78adf

File tree

5 files changed

+26
-49
lines changed

5 files changed

+26
-49
lines changed

.github/workflows/build-dev.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ jobs:
8080
run: |
8181
pip install --requirement build-requirements.txt
8282
pre-commit run --all-files
83-
- name: Compile requirements.txt
84-
# We need to put the file in $HOME
85-
# - a simple way to ensure it's
86-
# available between steps in the same job.
87-
run: |
88-
pip install --upgrade pip
89-
pip install poetry==1.7.1
90-
poetry export --without-hashes --without dev --output requirements.txt
9183
- name: Docker build
9284
uses: docker/build-push-action@v4
9385
with:

.github/workflows/build-production.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ jobs:
127127
run: |
128128
pip install --requirement build-requirements.txt
129129
pre-commit run --all-files
130-
- name: Compile requirements.txt
131-
run: |
132-
pip install --upgrade pip
133-
pip install poetry==1.7.1
134-
poetry export --without-hashes --without dev --output requirements.txt
135130
- name: Build
136131
uses: docker/build-push-action@v4
137132
with:

.github/workflows/build-staging.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ jobs:
149149
run: |
150150
pip install --requirement build-requirements.txt
151151
pre-commit run --all-files
152-
- name: Compile requirements.txt
153-
run: |
154-
pip install --upgrade pip
155-
pip install poetry==1.7.1
156-
poetry export --without-hashes --without dev --output requirements.txt
157152
- name: Docker build
158153
uses: docker/build-push-action@v4
159154
with:

Dockerfile

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
FROM python:3.11.7-slim-bullseye
2-
3-
# We rely on the presence of a requirements.txt file in project root.
4-
# This is achieved prior to a container build using poetry
5-
# and is the responsibility of the developer or CI process: -
6-
#
7-
# poetry export --without-hashes --without dev --output requirements.txt
1+
FROM python:3.11.7-slim-bullseye AS python-base
82

93
ENV PYTHONUNBUFFERED 1
104
ENV PYTHONDONTWRITEBYTECODE 1
@@ -23,14 +17,33 @@ RUN apt-get update -y && \
2317
apt-get clean && \
2418
rm -rf /var/lib/apt/lists/*
2519

20+
# another stage for poetry installation. this ensures poetry won't end
21+
# up in final image where it's not needed
22+
FROM python-base AS poetry-base
23+
24+
ARG POETRY_VERSION=1.7.1
25+
RUN pip install --no-cache-dir poetry==${POETRY_VERSION}
26+
27+
WORKDIR /
28+
COPY poetry.lock pyproject.toml /
29+
30+
# POETRY_VIRTUALENVS_IN_PROJECT tells poetry to create the venv to
31+
# project's directory (.venv). This way the location is predictable
32+
RUN POETRY_VIRTUALENVS_IN_PROJECT=true poetry install --no-root --only main --no-directory
33+
34+
# final stage. only copy the venv with installed packages and point
35+
# paths to it
36+
FROM python-base as final
37+
38+
COPY --from=poetry-base /.venv /.venv
39+
40+
ENV PYTHONPATH="${PYTHONPATH}:/.venv/lib/python3.11/site-packages/"
41+
ENV PATH=/.venv/bin:$PATH
42+
2643
WORKDIR /srv/logs
2744
WORKDIR /code/logs
2845
WORKDIR /code
2946

30-
COPY requirements.txt ./
31-
RUN pip install --no-cache-dir --upgrade pip && \
32-
pip install --no-cache-dir --requirement requirements.txt
33-
3447
COPY nginx.conf /etc/nginx/nginx.conf
3548
COPY django_nginx.conf /etc/nginx/sites-available/default.conf
3649
COPY proxy_params /etc/nginx/frag_proxy_params

README.md

+2-20
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,13 @@ installs/updates new packages to local venv. It's equivalent to running
6666
`poetry lock && poetry install`, so if you're not interested in local environment and
6767
just want to update the lockfile, you can run just `poetry lock`.
6868

69-
> **TODO**: at the time of writing (2023-07-21), this project is still on Python 3.7,
70-
which means some packages that are needed for development (specifically `pre-commit`),
71-
have not been added to `pyproject.toml` due to version conflict. Once Python has
72-
been updated to more recent version they can be added to project requirements where
73-
they belong; until that time, instructions in section [Pre-commit](#pre-commit)
74-
are still relevant.
7569

7670
## Building and running (local)
77-
The backend is a Docker container image and can be build and deployed locally using
78-
`docker-compose`.
79-
80-
The build relies on a legacy `requirements.txt` file (to avoid polluting the run-time
81-
container with material and packages it does not need), and you need to create this
82-
file using `poetry`. After any package dependency changes, and before any container
83-
image build you must **export** the poetry environment as a requirements.txt file
84-
using its `export` command. For example: -
85-
86-
poetry export --without-hashes --without dev --output requirements.txt
87-
88-
This is done automatically in the CI process but you need to do it at least once
89-
prior to building locally. Once done you can then build the container image
90-
with `docker-compose``: -
71+
The backend is a Docker container image and can be build and deployed locally using `docker-compose`: -
9172

9273
docker-compose build
9374

75+
9476
To run the application (which wil include deployment of the postgres and neo4j databases)
9577
run: -
9678

0 commit comments

Comments
 (0)