Skip to content

Commit c82a127

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

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

.gitignore

+1
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

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
# NOTE: Forcefully delete optional private dependencies for now since Poetry
16+
# needs to fetch them in order to calculate the dependency tree.
17+
# See https://github.com/python-poetry/poetry/issues/4562
18+
# TODO: Improve management of enterprise features
19+
WORKDIR /tmp
20+
ARG POETRY_VERSION_CONSTRAINT
21+
ARG INSTALL_DEV
22+
COPY api/pyproject.toml .
23+
RUN \
24+
pip install --no-cache-dir poetry${POETRY_VERSION_CONSTRAINT:-} &&\
25+
poetry config virtualenvs.create false &&\
26+
poetry config cache-dir /var/cache/pypoetry &&\
27+
sed -ie '/tool.poetry.group.auth-controller/,+1d' pyproject.toml &&\
28+
sed -ie '/tool.poetry.group.saml/,+1d' pyproject.toml &&\
29+
sed -ie '/tool.poetry.group.ldap/,+1d' pyproject.toml &&\
30+
sed -ie '/tool.poetry.group.workflows/,+1d' pyproject.toml &&\
31+
sed -ie '/tool.poetry.group.licensing/,+1d' pyproject.toml &&\
32+
poetry install --no-root $([ "${INSTALL_DEV}" = "true" ] && echo --with dev)
33+
34+
# Prepare the app
35+
WORKDIR /app
36+
COPY api/ .
37+
EXPOSE 8000
38+
CMD ["flagsmith", "start", "api"]

docker/new/docker-compose.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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: true
10+
ssh:
11+
- default
12+
depends_on:
13+
database:
14+
condition: service_healthy
15+
environment:
16+
DEBUG: true
17+
DATABASE_URL: postgres://postgres@database:5432/postgres
18+
DJANGO_SETTINGS_MODULE: app.settings.local
19+
volumes:
20+
- ../../.local/pypoetry:/root/.config/poetry:rw # Poetry local cache
21+
- ../../api:/app:rw,cached # Application directory
22+
23+
services:
24+
api:
25+
<<: *app
26+
command: sh -c 'flagsmith migrate && flagsmith start --reload api'
27+
ports:
28+
- 8000:8000
29+
30+
# TODO
31+
# task-processor:
32+
# <<: *app
33+
# command: ...
34+
35+
database:
36+
image: postgres:15.5-alpine
37+
volumes:
38+
- ../../.local/database:/var/lib/postgresql/data:rw,cached
39+
environment:
40+
POSTGRES_HOST_AUTH_METHOD: trust
41+
healthcheck:
42+
test: pg_isready -Upostgres
43+
interval: 1s
44+
timeout: 30s

0 commit comments

Comments
 (0)