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
10 changes: 10 additions & 0 deletions .env.staging.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copy values into /srv/secrets/instalab-staging.env (do not commit secrets)
INSTALAB_DB_TYPE=postgres
INSTALAB_DB_HOST=apps-postgres
INSTALAB_DB_PORT=5432
INSTALAB_DB_NAME=instalab_staging
INSTALAB_DB_USER=instalab_staging
INSTALAB_DB_PASS=REPLACE_ME
INSTALAB_ENCRYPTION_KEY=REPLACE_WITH_32_BYTE_BASE64_URLSAFE_KEY
INSTALAB_SCRAPER_BACKEND=private
INSTALAB_PROXY_ENABLED=false
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ InstaLab is an operations console for Instagram snapshot runs (followers/followi

## Repo layout
- `docker-compose.yml` / `docker-compose.preview.yml`
- `docker-compose.staging.yml` (apps VM isolated staging stack)
- `docker-compose.local.yml` + `docker-compose.local-postgres.yml`
- `Dockerfile`
- `app/` (Flask API, Django UI, workers, scripts, UI build pipeline)
Expand Down Expand Up @@ -63,6 +64,21 @@ If you already have Postgres running, set the `INSTALAB_DB_*` values in `.env` a
- `dev`: active development
- `main`: stable / public-ready

## Apps VM staging isolation
Use the dedicated staging checkout and stack when building risky/new features (for example WhatsApp commands):
- Worktree: `/srv/apps/instalab-staging` (branch: `feature/whatsapp-commands`)
- Compose file: `/srv/apps/instalab-staging/docker-compose.staging.yml`
- API: `http://192.168.4.30:5100`
- UI direct: `http://127.0.0.1:8102`
- Secrets: `/srv/secrets/instalab-staging.env`
- Data: `/srv/data/instalab-staging`
- Database: `instalab_staging` (user: `instalab_staging`)

Helper commands:
- Up: `/srv/apps/instalab-staging/scripts/staging-up.sh`
- Status: `/srv/apps/instalab-staging/scripts/staging-status.sh`
- Down: `/srv/apps/instalab-staging/scripts/staging-down.sh`

## Release checklist
- Update version / changelog (if you keep one)
- Run UI build (`cd app && npm run build`)
Expand Down
95 changes: 95 additions & 0 deletions docker-compose.staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
services:
instalab-api-staging:
build:
context: /srv/apps/instalab-staging
container_name: instalab-api-staging
user: "1001:1003"
command: ddtrace-run python server.py
env_file:
- /srv/secrets/instalab-staging.env
environment:
INSTALAB_ENV: /srv/secrets/instalab-staging.env
INSTALAB_DB_HOST: apps-postgres
HOME: /data/instalab/home
DD_SERVICE: instalab-api-staging
DD_ENV: homelab-staging
DD_VERSION: "1"
DD_TRACE_ENABLED: "false"
DD_DYNAMIC_INSTRUMENTATION_ENABLED: "false"
DD_TRACE_EXCLUDED_URLS: "/api/health,/api/health/detail"
DD_EXCEPTION_REPLAY_ENABLED: "false"
DD_LOGS_INJECTION: "false"
DD_RUNTIME_METRICS_ENABLED: "false"
volumes:
- /srv/apps/instalab-staging/app:/app
- /srv/secrets/instalab-staging.env:/srv/secrets/instalab-staging.env:ro
- /srv/secrets/instalab-staging-logins.json:/srv/secrets/instalab-logins.json
- /srv/secrets/instalab-staging-cookies:/data/instalab/cookies
- /srv/secrets/instalab-staging-private:/data/instalab/private
- /srv/data/instalab-staging:/data/instalab
ports:
- "192.168.4.30:5100:5000"
Comment on lines +4 to +31

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This Docker Compose file contains hardcoded absolute paths (e.g., /srv/apps/instalab-staging, /srv/secrets/..., /srv/data/...) and a hardcoded IP address (192.168.4.30). This makes the configuration brittle and not portable, as it's tied to a specific host machine setup.

Consider using environment variables with default values to make these paths and the IP configurable. This would improve maintainability and reusability.

For example:

services:
  instalab-api-staging:
    build:
      context: ${APP_ROOT:-/srv/apps/instalab-staging}
    ...
    ports:
      - "${HOST_IP:-192.168.4.30}:5100:5000"
    volumes:
      - ${APP_ROOT:-/srv/apps/instalab-staging}/app:/app
      - ${SECRETS_ROOT:-/srv/secrets}/instalab-staging.env:/srv/secrets/instalab-staging.env:ro
      # ... and so on for other paths

These variables could then be defined in an .env file.

restart: unless-stopped
healthcheck:
test:
[
"CMD",
"python",
"-c",
"import urllib.request; urllib.request.urlopen('http://127.0.0.1:5000/api/health', timeout=5).read()",
]
interval: 30s
timeout: 5s
retries: 3
start_period: 20s
networks:
- apps-db

instalab-ui-staging:
build:
context: /srv/apps/instalab-staging
container_name: instalab-ui-staging
user: "1001:1003"
command: /app/scripts/start_ui.sh
env_file:
- /srv/secrets/instalab-staging.env
environment:
INSTALAB_ENV: /srv/secrets/instalab-staging.env
INSTALAB_API_BASE: http://instalab-api-staging:5000/
INSTALAB_DB_HOST: apps-postgres
DD_SERVICE: instalab-ui-staging
DD_ENV: homelab-staging
DD_VERSION: "1"
DD_TRACE_ENABLED: "false"
DD_DYNAMIC_INSTRUMENTATION_ENABLED: "false"
DD_TRACE_EXCLUDED_URLS: "/healthz/"
DD_EXCEPTION_REPLAY_ENABLED: "false"
DD_LOGS_INJECTION: "false"
DD_RUNTIME_METRICS_ENABLED: "false"
volumes:
- /srv/apps/instalab-staging/app:/app
- /srv/secrets/instalab-staging.env:/srv/secrets/instalab-staging.env:ro
ports:
- "127.0.0.1:8102:8000"
depends_on:
- instalab-api-staging
restart: unless-stopped
healthcheck:
test:
[
"CMD",
"python",
"-c",
"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz/', timeout=5).read()",
]
interval: 30s
timeout: 5s
retries: 3
start_period: 20s
networks:
- apps-db

networks:
apps-db:
external: true
name: apps-db
Comment on lines +1 to +95

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This file is almost a complete copy of docker-compose.yml, with only names, ports, and a few environment variables changed. This duplication can lead to maintenance issues, as changes to one service definition might need to be manually synchronized with the other.

To reduce duplication and improve maintainability, consider using Docker Compose's extends feature or YAML anchors and aliases. You could define a base service in a common file and then extend it in docker-compose.yml and docker-compose.staging.yml to apply environment-specific configurations.

4 changes: 4 additions & 0 deletions scripts/staging-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd /srv/apps/instalab-staging

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The script hardcodes the path /srv/apps/instalab-staging. This makes the script less portable and harder to use in different environments (e.g., local development). It's better to determine the project root relative to the script's location to make it runnable from anywhere.

Suggested change
cd /srv/apps/instalab-staging
cd "$(dirname "${BASH_SOURCE[0]}")/.."

docker compose -f docker-compose.staging.yml --project-name instalab-staging down
4 changes: 4 additions & 0 deletions scripts/staging-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd /srv/apps/instalab-staging

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The script hardcodes the path /srv/apps/instalab-staging. This makes the script less portable and harder to use in different environments (e.g., local development). It's better to determine the project root relative to the script's location to make it runnable from anywhere.

Suggested change
cd /srv/apps/instalab-staging
cd "$(dirname "${BASH_SOURCE[0]}")/.."

docker compose -f docker-compose.staging.yml --project-name instalab-staging ps
4 changes: 4 additions & 0 deletions scripts/staging-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd /srv/apps/instalab-staging

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The script hardcodes the path /srv/apps/instalab-staging. This makes the script less portable and harder to use in different environments (e.g., local development). It's better to determine the project root relative to the script's location to make it runnable from anywhere.

Suggested change
cd /srv/apps/instalab-staging
cd "$(dirname "${BASH_SOURCE[0]}")/.."

docker compose -f docker-compose.staging.yml --project-name instalab-staging up -d --build