Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions .env.TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ FLAGEMBEDDING_CACHE_DIR="/opt/model_cache/"

# Ollama API host, running on the host machine
OLLAMA_API_BASE="http://localhost:11434"

POSTGRES_USER="postgres"
POSTGRES_PASSWORD=
POSTGRES_HOST="db"
POSTGRES_PORT="5432"
POSTGRES_DB="manufold"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ MANUGENAI_FIGURE_MODEL_NAME="ollama/gemma3:4b"
Run the following command:

```bash
docker compose up --build
docker compose -f docker-compose.yml -f docker-compose.with-pg.yml -f docker-compose.override.yml up --build
```

This will build the Docker images and start the application.
Expand Down Expand Up @@ -257,15 +257,15 @@ The production configuration differs from the development configuration in a few
To launch the production version of the app, you can run the following command:

```bash
docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build -d
docker compose -f docker-compose.yml -f docker-compose.with-pg.yml -f docker-compose.prod.yml up --build -d
```

This will build the production images and start the application in detached mode.

To tail the container logs, you can run:

```bash
docker compose -f docker-compose.yml -f docker-compose.prod.yml logs -f
docker compose -f docker-compose.yml -f docker-compose.with-pg.yml -f docker-compose.prod.yml logs -f
```

- *For project members: [internal planning doc](https://olucdenver.sharepoint.com/:w:/r/sites/CenterforHealthAI939-SoftwareEngineering/Shared%20Documents/Software%20Engineering/Projects/PivLab%20-%20ADK%20Hackathon/Agent%20Development%20Kit%20Hackathon%20with%20Google%20Cloud.docx?d=w0cfff935f2754c3492489ef5b15fe2f4&csf=1&web=1&e=NRM3en)*
Expand Down
1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dependencies = [
"asyncpg>=0.31",
"fastapi>=0.104",
"manufold",
"uvicorn[standard]>=0.24",
Expand Down
18 changes: 18 additions & 0 deletions backend/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker-compose.with-pg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
backend:
environment:
# yamllint disable-line rule:line-length
- "SESSION_DB_CONN_STRING=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
- "SESSION_DB_CONN_STRING=postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
depends_on:
- db

Expand Down
85 changes: 85 additions & 0 deletions run_stack.sh
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be worth a quick check with shellcheck. I don't see anything especially dangerous but it might provide some good feedback for string composition.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

# this script manages compose configurations for different environments
# and ensures the necessary environment variables are set up correctly.

# invoke it like so:
#
# ./run_stack.sh [dev|prod] [docker-compose command options]
#
# - the first argument is the environment (default: dev) if the first arg isn't
# provided or doesn't match 'dev' or 'prod', it defaults to 'dev'.
# - the remainder of the arguments are passed to the `docker compose` command.
# if no arguments are provided, it defaults to an environment-specific
# command, e.g. `docker compose up --build` for dev or `docker compose up
# --build -d` for prod.

# ------------------------------------
# --- preamble: .env file validation, sourcing
# ------------------------------------

# check if `.env` is present, and if not copy it from `.env.TEMPLATE`
# and fill in passwords with random values
if [ ! -f .env ]; then
echo ".env file not found, copying from .env.TEMPLATE"
cp .env.TEMPLATE .env
fi

# ensure a value for the postgres db's password exists, and if not, generate a random one
RANDOM_PG_PASSWORD=$(openssl rand -base64 32 | tr -d '/=')
perl -i -pe"s/^POSTGRES_PASSWORD=$/POSTGRES_PASSWORD=\"${RANDOM_PG_PASSWORD}\"/g" .env

# source the .env file and export its contents to the environment
set -a
source .env
set +a

# ------------------------------------
# --- environment resolution
# ------------------------------------

# sets the default environment to 'dev' if not specified via DEFAULT_ENV
DEFAULT_ENV=${DEFAULT_ENV:-dev}
# defaults to a no-op command to run after docker compose
POST_COMMAND=":"

if [ -z "$1" ] || [[ ! "$1" =~ ^(dev|prod)$ ]]; then
echo "No environment specified, using default: $DEFAULT_ENV"
export ENV=$DEFAULT_ENV
else
# use the first argument as the environment
export ENV="$1"; shift
echo "Using specified environment: $ENV"
fi

# set up compose files and commands based on the environment
case $ENV in
dev)
COMPOSE_FILES="-f docker-compose.yml -f docker-compose.override.yml"
COMPOSE_CMD="up --build"
;;
prod)
COMPOSE_FILES="-f docker-compose.yml -f docker-compose.with-pg.yml -f docker-compose.prod.yml"
COMPOSE_CMD="up --build -d"
# tail all container logs in production
POST_COMMAND="docker compose ${COMPOSE_FILES} logs -f"
;;
*)
echo "Unknown environment: $ENV, aborting"
exit 1
;;
esac


# ------------------------------------
# --- execute docker compose command
# ------------------------------------

# if we have any remaining arguments, override the compose command with them
if [ $# -gt 0 ]; then
echo "Overriding compose command with: $@"
COMPOSE_CMD="$@"
fi

docker compose ${COMPOSE_FILES} ${COMPOSE_CMD} && \
${POST_COMMAND}
Loading