Skip to content

Commit a1bf935

Browse files
committed
feat: Introduce a new local Docker env
1 parent 9974494 commit a1bf935

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ checkstyle.txt
1414
.envrc
1515
.tool-versions
1616
.elasticbeanstalk/
17+
.local/
1718

1819
# These get baked into the docker container on build
1920
src/CI_COMMIT_SHA

api/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# NOTE: Why not Alpine? Because Alpine demands installation of OS software
2+
# prior to running app code, which leads to maintenance work and a larger image
3+
# size compared to Debian — considering Debian layers are shared across images.
4+
FROM python:3.12
5+
6+
# Prevent Python from buffering stdout and stderr
7+
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED
8+
ENV PYTHONUNBUFFERED=1
9+
10+
# Prevent Python from writing .pyc files to disk
11+
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE
12+
ENV PYTHONDONTWRITEBYTECODE=1
13+
14+
# Install Python packages
15+
WORKDIR /tmp
16+
ARG POETRY_VERSION_CONSTRAINT
17+
ARG INSTALL_DEV_DEPENDENCIES
18+
COPY api/pyproject.toml api/poetry.lock ./
19+
RUN \
20+
pip install -q poetry${POETRY_VERSION_CONSTRAINT:-} &&\
21+
poetry config virtualenvs.create false &&\
22+
poetry config cache-dir /var/cache/pypoetry &&\
23+
###
24+
# NOTE: Forcefully delete optional private dependencies for now since
25+
# Poetry needs to fetch them in order to calculate the dependency tree. See
26+
# https://github.com/python-poetry/poetry/issues/4562
27+
# TODO: Improve management of enterprise features
28+
sed -ie '/tool.poetry.group.auth-controller/,+1d' pyproject.toml &&\
29+
sed -ie '/tool.poetry.group.saml/,+1d' pyproject.toml &&\
30+
sed -ie '/tool.poetry.group.ldap/,+1d' pyproject.toml &&\
31+
sed -ie '/tool.poetry.group.workflows/,+1d' pyproject.toml &&\
32+
sed -ie '/tool.poetry.group.licensing/,+1d' pyproject.toml &&\
33+
poetry lock &&\
34+
###
35+
poetry install --no-root $([ "$INSTALL_DEV_DEPENDENCIES" != "true" ] && echo "--without dev") &&\
36+
rm -rf /var/cache/pypoetry &&\
37+
rm -rf /tmp/*
38+
39+
# Prepare the app
40+
WORKDIR /opt/app
41+
COPY api/ .
42+
EXPOSE 8000
43+
CMD ["flagsmith", "start", "api"]

api/poetry.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/new/docker-compose.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Reusable app definition
2+
x-app: &app
3+
image: ${DOCKER_IMAGE:-local/flagsmith/flagsmith}:${DOCKER_TAG:-latest}
4+
build:
5+
context: ../../
6+
dockerfile: api/Dockerfile
7+
args:
8+
POETRY_VERSION_CONSTRAINT: ==2.1.2
9+
INSTALL_DEV_DEPENDENCIES: true
10+
depends_on:
11+
database:
12+
condition: service_healthy
13+
environment:
14+
DEBUG: true
15+
DATABASE_URL: postgres://postgres@database:5432/postgres
16+
DJANGO_SETTINGS_MODULE: app.settings.local
17+
volumes:
18+
- ../../.local/pypoetry:/root/.config/poetry:rw # Poetry local cache
19+
- ../../:/opt/app:rw,cached # Application directory
20+
21+
services:
22+
api:
23+
<<: *app
24+
command: sh -c 'cd api; flagsmith migrate && flagsmith start --reload api'
25+
ports:
26+
- 8000:8000
27+
28+
# TODO
29+
# task-processor:
30+
# <<: *app
31+
# command: ...
32+
33+
database:
34+
image: postgres:15.5-alpine
35+
volumes:
36+
- ../../.local/database:/var/lib/postgresql/data:rw,cached
37+
environment:
38+
POSTGRES_HOST_AUTH_METHOD: trust
39+
healthcheck:
40+
test: pg_isready -Upostgres
41+
interval: 1s
42+
timeout: 30s

0 commit comments

Comments
 (0)