-
Notifications
You must be signed in to change notification settings - Fork 458
feat: Introduce a new Docker environment for development #5355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
a1bf935
51120a3
5e88b5b
8737ec2
9e40ddf
91d3d47
abaec12
eb3b37d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # NOTE: Why not Alpine? Because Alpine demands installation of OS software | ||
| # prior to running app code, which leads to maintenance work and a larger image | ||
| # size compared to Debian — considering Debian layers are shared across images. | ||
emyller marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FROM python:3.12 | ||
|
|
||
| # Prevent Python from buffering stdout and stderr | ||
| # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED | ||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| # Prevent Python from writing .pyc files to disk | ||
| # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
|
||
| # Install Python packages | ||
| WORKDIR /tmp | ||
| ARG POETRY_VERSION_CONSTRAINT | ||
| ARG INSTALL_DEV_DEPENDENCIES | ||
|
||
| COPY api/pyproject.toml api/poetry.lock ./ | ||
| RUN \ | ||
| pip install -q poetry${POETRY_VERSION_CONSTRAINT:-} &&\ | ||
| poetry config virtualenvs.create false &&\ | ||
| poetry config cache-dir /var/cache/pypoetry &&\ | ||
| ### | ||
| # NOTE: Forcefully delete optional private dependencies for now since | ||
| # Poetry needs to fetch them in order to calculate the dependency tree. See | ||
| # https://github.com/python-poetry/poetry/issues/4562 | ||
| # TODO: Improve management of enterprise features | ||
|
||
| sed -ie '/tool.poetry.group.auth-controller/,+1d' pyproject.toml &&\ | ||
| sed -ie '/tool.poetry.group.saml/,+1d' pyproject.toml &&\ | ||
| sed -ie '/tool.poetry.group.ldap/,+1d' pyproject.toml &&\ | ||
| sed -ie '/tool.poetry.group.workflows/,+1d' pyproject.toml &&\ | ||
| sed -ie '/tool.poetry.group.licensing/,+1d' pyproject.toml &&\ | ||
| poetry lock &&\ | ||
| ### | ||
| poetry install --no-root $([ "$INSTALL_DEV_DEPENDENCIES" != "true" ] && echo "--without dev") &&\ | ||
| rm -rf /var/cache/pypoetry &&\ | ||
| rm -rf /tmp/* | ||
|
||
|
|
||
| # Prepare the app | ||
| WORKDIR /opt/app | ||
| COPY api/ . | ||
| EXPOSE 8000 | ||
| CMD ["flagsmith", "start", "api"] | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Runs any command from within an `api` container. | ||
| # If no command is given, it runs the application's default command. | ||
|
|
||
| # NOTE: This script is intended as a one-command option to run Flagsmith code | ||
| # with no previous setup except from installing Docker. | ||
|
|
||
| # Requirements: | ||
| # - Docker | ||
|
|
||
| # Examples: | ||
| # - `./run` — runs pending migrations and starts the API HTTP server in dev mode. | ||
| # - `./run bash` — starts a bash shell in the API container. | ||
| # - `./run python manage.py makemigrations` — runs the command in the API container. | ||
| # - `./run flagsmith createsuperuser` — the Flagsmith CLI should be there too! | ||
| # - `./run pytest --sw --pdb tests/unit/test_my_feature.py` — you get it. | ||
|
|
||
| SCRIPT=$(readlink -f "$0") | ||
| SCRIPT_DIR=$(dirname "$SCRIPT") | ||
| ROOT_DIR=$(cd "$SCRIPT_DIR/.."; pwd -P) | ||
| PWD=$(pwd -P) | ||
| WORKING_DIR=$(echo "$PWD" | sed "s|$ROOT_DIR||") | ||
|
|
||
| docker compose -f "${ROOT_DIR}/docker/new/docker-compose.yml" run --rm \ | ||
| $([ $# -eq 0 ] && echo --service-ports --use-aliases) \ | ||
| $([ -n "${WORKING_DIR}" ] && echo --workdir /opt/app${WORKING_DIR}) \ | ||
| api "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Reusable app definition | ||
| x-app: &app | ||
| image: ${DOCKER_IMAGE:-local/flagsmith/flagsmith}:${DOCKER_TAG:-latest} | ||
| build: | ||
| context: ../../ | ||
| dockerfile: api/Dockerfile | ||
| args: | ||
| POETRY_VERSION_CONSTRAINT: ==2.1.2 | ||
|
||
| INSTALL_DEV_DEPENDENCIES: true | ||
| depends_on: | ||
| database: | ||
| condition: service_healthy | ||
| environment: | ||
| DEBUG: true | ||
| DATABASE_URL: postgres://postgres@database:5432/postgres | ||
| DJANGO_SETTINGS_MODULE: app.settings.local | ||
| volumes: | ||
| - ../../.local/pypoetry:/root/.config/poetry:rw # Poetry local cache | ||
| - ../../:/opt/app:rw,cached # Application directory | ||
|
|
||
| services: | ||
| api: | ||
| <<: *app | ||
| command: sh -c 'flagsmith migrate && flagsmith start --reload api' | ||
| ports: | ||
| - 8000:8000 | ||
|
|
||
| # TODO | ||
| # task-processor: | ||
| # <<: *app | ||
| # command: ... | ||
|
|
||
| database: | ||
| image: postgres:15.5-alpine | ||
| volumes: | ||
| - ../../.local/database:/var/lib/postgresql/data:rw,cached | ||
| environment: | ||
| POSTGRES_HOST_AUTH_METHOD: trust | ||
| healthcheck: | ||
| test: pg_isready -Upostgres | ||
| interval: 1s | ||
| timeout: 30s | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how having to maintain a new Dockerfile is a viable trade-off here. I'll prefer a unified build toolchain to a neater dev container image; I'd rather this file be a new target stage in the existing root Dockerfile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! For now this Dockerfile is only experimental. It aligns nicely with the proposal but it would have a long way to go before becoming an actual thing.