Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ checkstyle.txt
.envrc
.tool-versions
.elasticbeanstalk/
.local/

# These get baked into the docker container on build
src/CI_COMMIT_SHA
Expand Down
37 changes: 37 additions & 0 deletions api/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
set -e

# 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)

opts="--rm"

if [ $# -eq 0 ]; then
# Run default command, i.e. API server
opts="$opts --service-ports --use-aliases --workdir /opt/app/api"
else
PWD=$(pwd -P)
WORKING_DIR=$(echo "$PWD" | sed "s|$ROOT_DIR||")
if [ -n "${WORKING_DIR}" ]; then
opts="$opts --workdir /opt/app${WORKING_DIR}"
fi
fi

set -x
docker compose -f "${ROOT_DIR}/docker/new/docker-compose.yml" run $opts api "$@"
57 changes: 57 additions & 0 deletions docker/new/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Reusable app definition
x-app: &app
image: ${DOCKER_IMAGE:-local/flagsmith/flagsmith}:${DOCKER_TAG:-latest}
build:
context: ../../
target: oss-unified
args:
POETRY_VERSION: 2.1.1
INSTALL_DEV_DEPENDENCIES: true
depends_on:
default-database:
condition: service_healthy
task-processor-database:
condition: service_healthy
environment:
# LOG_LEVEL: DEBUG
DATABASE_URL: postgres://postgres@default-database:5432/postgres
DEBUG: true
DJANGO_SETTINGS_MODULE: app.settings.local
TASK_PROCESSOR_DATABASE_URL: postgres://postgres@task-processor-database:5432/postgres
TASK_PROCESSOR_DATABASES: task_processor
volumes:
# - ?:/app:rw,cached # Application directory

services:
api:
<<: *app
command: migrate-and-serve
ports:
- 8000:8000

# TODO
task-processor:
<<: *app
command: run-task-processor

default-database:
image: postgres:15.5-alpine
volumes:
- ../../.local/default-database:/var/lib/postgresql/data:rw,cached
environment:
POSTGRES_HOST_AUTH_METHOD: trust
healthcheck:
test: pg_isready -Upostgres
interval: 1s
timeout: 30s

task-processor-database:
image: postgres:15.5-alpine
volumes:
- ../../.local/task-processor-database:/var/lib/postgresql/data:rw,cached
environment:
POSTGRES_HOST_AUTH_METHOD: trust
healthcheck:
test: pg_isready -Upostgres
interval: 1s
timeout: 30s
Loading