Skip to content
Merged
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
117 changes: 117 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,120 @@ jobs:
- name: Stop deployment stack
if: always()
run: docker compose down --volumes --remove-orphans

deploy-stack:
name: Production deploy stack with HTTPS
runs-on: ubuntu-latest
env:
COMPOSE_FILE: deploy/docker-compose.yml

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Build the image the stack deploys
shell: bash
run: |
test "$(grep -c '^FROM python:' Dockerfile)" -eq 1
tag="$(sed -n 's|^FROM python:\([^ ]*\).*|\1|p' Dockerfile)"
base="$(.github/scripts/pull-official-image.sh "python:$tag")"
mirror_file="$RUNNER_TEMP/Dockerfile.deploy"
sed "s|^FROM python:$tag|FROM $base|" Dockerfile > "$mirror_file"
docker build --pull=false --file "$mirror_file" --tag agentloop:local .

- name: Pull Postgres and Caddy through the mirror fallback
shell: bash
run: |
echo "POSTGRES_IMAGE=$(.github/scripts/pull-official-image.sh postgres:16-alpine)" >> "$GITHUB_ENV"
echo "CADDY_IMAGE=$(.github/scripts/pull-official-image.sh caddy:2)" >> "$GITHUB_ENV"

- name: Configure synthetic production settings
shell: bash
run: |
dashboard_password="dash-$(openssl rand -hex 16)"
admin_key="ci-admin-$(openssl rand -hex 24)"
db_password="db-$(openssl rand -hex 16)"
echo "::add-mask::$dashboard_password"
echo "::add-mask::$admin_key"
echo "::add-mask::$db_password"
hash="$(docker run --rm "$CADDY_IMAGE" caddy hash-password --plaintext "$dashboard_password")"
{
echo "AGENTLOOP_IMAGE=agentloop:local"
echo "AGENTLOOP_API_DOMAIN=api.localhost"
echo "AGENTLOOP_DASHBOARD_DOMAIN=dashboard.localhost"
echo "AGENTLOOP_ADMIN_API_KEY=$admin_key"
echo "AGENTLOOP_DASHBOARD_USER=operator"
echo "AGENTLOOP_DASHBOARD_PASSWORD_HASH='$hash'"
echo "POSTGRES_PASSWORD=$db_password"
echo "POSTGRES_IMAGE=$POSTGRES_IMAGE"
echo "CADDY_IMAGE=$CADDY_IMAGE"
} > deploy/.env
echo "DASHBOARD_PASSWORD=$dashboard_password" >> "$GITHUB_ENV"
echo "AGENTLOOP_ADMIN_API_KEY=$admin_key" >> "$GITHUB_ENV"
echo "127.0.0.1 api.localhost dashboard.localhost" | sudo tee -a /etc/hosts

- name: Validate production Compose configuration without rendering secrets
run: docker compose config --quiet

- name: Start production stack
run: docker compose up --detach

- name: Wait for HTTPS through Caddy
shell: bash
run: |
for attempt in $(seq 1 60); do
if docker compose exec -T caddy cat /data/caddy/pki/authorities/local/root.crt > caddy-root.crt 2>/dev/null \
&& curl --fail --silent --show-error --cacert caddy-root.crt https://api.localhost/readyz > /dev/null; then
exit 0
fi
sleep 3
done
echo "The API did not become ready over HTTPS" >&2
exit 1

- name: Verify the API over HTTPS
shell: bash
run: |
SSL_CERT_FILE="$PWD/caddy-root.crt" AGENTLOOP_API_URL=https://api.localhost python3 scripts/smoke_api.py
status="$(curl --silent --output /dev/null --write-out '%{http_code}' http://api.localhost/v1/health)"
test "$status" = 308
head -c 17000000 /dev/zero | tr '\0' 'a' > oversized.json
status="$(curl --silent --output /dev/null --write-out '%{http_code}' --cacert caddy-root.crt \
--header 'Content-Type: application/json' --data-binary @oversized.json https://api.localhost/v1/traces)"
test "$status" = 413

- name: Verify the dashboard requires a login
shell: bash
run: |
status="$(curl --silent --output /dev/null --write-out '%{http_code}' --cacert caddy-root.crt https://dashboard.localhost/)"
test "$status" = 401
status="$(curl --silent --output /dev/null --write-out '%{http_code}' --cacert caddy-root.crt \
--user "operator:wrong-password" https://dashboard.localhost/)"
test "$status" = 401
for attempt in $(seq 1 40); do
if curl --fail --silent --output /dev/null --cacert caddy-root.crt \
--user "operator:$DASHBOARD_PASSWORD" https://dashboard.localhost/_stcore/health; then
break
fi
sleep 3
done
curl --fail --silent --output /dev/null --cacert caddy-root.crt \
--user "operator:$DASHBOARD_PASSWORD" https://dashboard.localhost/

- name: Verify only the proxy is published
shell: bash
run: |
for port in 8000 8501 5432; do
if curl --silent --max-time 3 "http://127.0.0.1:$port/" > /dev/null; then
echo "Port $port must not be published on the host" >&2
exit 1
fi
done

- name: Show container logs on failure
if: failure()
run: docker compose logs --no-color --tail=200

- name: Stop production stack
if: always()
run: docker compose down --volumes --remove-orphans
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,52 @@ jobs:
- name: Publish distribution
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3

publish-image:
name: Publish container image
needs: [guard, validate]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Build image from the validated tag
shell: bash
run: |
version="${GITHUB_REF_NAME#v}"
image="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/agentloop"
test "$(grep -c '^FROM python:' Dockerfile)" -eq 1
tag="$(sed -n 's|^FROM python:\([^ ]*\).*|\1|p' Dockerfile)"
base="$(.github/scripts/pull-official-image.sh "python:$tag")"
mirror_file="$RUNNER_TEMP/Dockerfile.release"
sed "s|^FROM python:$tag|FROM $base|" Dockerfile > "$mirror_file"
docker build --pull=false --file "$mirror_file" \
--label "org.opencontainers.image.version=$version" \
--label "org.opencontainers.image.revision=$GITHUB_SHA" \
--tag "$image:$version" --tag "$image:latest" .
echo "IMAGE=$image" >> "$GITHUB_ENV"
echo "VERSION=$version" >> "$GITHUB_ENV"

- name: Check the image runs the released version
shell: bash
run: |
actual="$(docker run --rm "$IMAGE:$VERSION" python -c 'import agentloop; print(agentloop.__version__)')"
test "$actual" = "$VERSION"
docker run --rm "$IMAGE:$VERSION" sh -c 'test "$(id -u)" -ne 0'

- name: Push to GitHub Container Registry
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
printf '%s' "$GH_TOKEN" | docker login ghcr.io --username "$GITHUB_ACTOR" --password-stdin
docker push "$IMAGE:$VERSION"
docker push "$IMAGE:latest"
docker logout ghcr.io

publish-github:
name: Publish GitHub release
needs: [guard, validate]
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ trace, study, receipt, API and database schema versions.

### Added

- Cloud deployment. Releases publish a container image to
`ghcr.io/dipeshbabu/agentloop` (version and `latest` tags), built from the
validated tag and checked to report the release version as a non-root user.
`deploy/` adds a production Compose stack for one Linux server: Postgres, the
API, the dashboard behind a login, and Caddy with automatic HTTPS, publishing
only ports 80 and 443. CI runs the stack over HTTPS and checks API key use,
HTTPS redirects, the upload limit, the dashboard login and unpublished
internal ports. `docs/CLOUD_DEPLOY.md` covers single-server and managed
platform deployments.
- `agentloop improve init --language node` generates a Node.js adapter
(`agentloop_runner.mjs`) for the guided workflow. It imports an agent from a
relative `.mjs`, `.js` or `.cjs` module, calls it as `answer(input, trace)`
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM python:3.15-slim

LABEL org.opencontainers.image.title="AgentLoop" \
org.opencontainers.image.description="AgentLoop API and dashboard for agent traces and reports" \
org.opencontainers.image.source="https://github.com/dipeshbabu/agentloop" \
org.opencontainers.image.licenses="Apache-2.0"

COPY --from=ghcr.io/astral-sh/uv:0.13.7 /uv /uvx /bin/

ENV PYTHONDONTWRITEBYTECODE=1 \
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<a href="#record-your-own-run">Trace your code</a> ·
<a href="#compare-before-and-after">Compare runs</a> ·
<a href="#framework-integrations">Integrations</a> ·
<a href="#deploy-to-the-cloud">Deploy</a> ·
<a href="https://dipeshbabu.github.io/agentloop/FIRST_USE/">Guide</a>
</p>

Expand Down Expand Up @@ -409,6 +410,24 @@ code changes.

</details>

## Deploy to the cloud

Run a shared AgentLoop server for your team on any cloud. From 0.2.7 each release
publishes a container image, `ghcr.io/dipeshbabu/agentloop`, and `deploy/`
contains a production stack for one Linux server: Postgres, the API, the
dashboard behind a login, and Caddy for automatic HTTPS. Only ports 80 and 443
are exposed.

```bash
cp deploy/.env.example deploy/.env # set the image, domains and secrets
docker compose -f deploy/docker-compose.yml up --detach
```

CI runs this exact stack over HTTPS on every change. The
[cloud deployment guide](https://dipeshbabu.github.io/agentloop/CLOUD_DEPLOY/)
covers server setup, API keys, upgrades, backups, and managed platforms such as
Cloud Run, App Runner, ECS and Azure Container Apps.

## Dashboard and persistence

From a [source checkout](#source-checkout), load the synthetic example and start
Expand Down
26 changes: 26 additions & 0 deletions deploy/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copy to deploy/.env and replace every placeholder before starting the stack.
# Keep deploy/.env out of version control; it holds production secrets.

# Container image. Pin an exact release instead of "latest".
AGENTLOOP_IMAGE=ghcr.io/dipeshbabu/agentloop:0.2.7

# Public hostnames. Point both DNS records (A/AAAA) at this host first.
AGENTLOOP_API_DOMAIN=agentloop-api.example.com
AGENTLOOP_DASHBOARD_DOMAIN=agentloop.example.com

# Admin secret for creating project API keys. Generate with: openssl rand -hex 32
AGENTLOOP_ADMIN_API_KEY=replace-with-a-long-random-admin-secret

# Dashboard login. Create the bcrypt hash with:
# docker run --rm caddy:2 caddy hash-password --plaintext 'your-password'
# Keep the single quotes so Compose does not expand the $ characters in the hash.
AGENTLOOP_DASHBOARD_USER=admin
AGENTLOOP_DASHBOARD_PASSWORD_HASH='replace-with-a-bcrypt-hash'

# Database. Mounted as a Compose secret; never embedded in a URL.
POSTGRES_DB=agentloop
POSTGRES_USER=agentloop
POSTGRES_PASSWORD=replace-with-a-long-random-db-password

# Largest trace upload the proxy accepts.
AGENTLOOP_MAX_UPLOAD=16MB
31 changes: 31 additions & 0 deletions deploy/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# HTTPS reverse proxy for the AgentLoop production stack.
# Caddy obtains and renews certificates for both domains automatically once
# their DNS records point at this host and ports 80 and 443 are reachable.

{$AGENTLOOP_API_DOMAIN} {
encode zstd gzip
request_body {
max_size {$AGENTLOOP_MAX_UPLOAD}
}
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options "nosniff"
-Server
}
reverse_proxy api:8000
}

# The dashboard has no login of its own, so Caddy requires one.
{$AGENTLOOP_DASHBOARD_DOMAIN} {
encode zstd gzip
basic_auth {
{$AGENTLOOP_DASHBOARD_USER} {$AGENTLOOP_DASHBOARD_PASSWORD_HASH}
}
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
-Server
}
reverse_proxy dashboard:8501
}
Loading
Loading