Skip to content

amp: Add Amp Orb project setup - #1497

Open
marcleblanc2 wants to merge 15 commits into
mainfrom
marc/amp-orb-setup
Open

marcleblanc2 wants to merge 15 commits into
mainfrom
marc/amp-orb-setup

Conversation

@marcleblanc2

@marcleblanc2 marcleblanc2 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Lets agents and people test changes to this repo's Docker Compose deployment in Amp orbs. A thread in the sourcegraph/deploy-sourcegraph-docker Amp project can start Sourcegraph, Jaeger, and an executor from the Compose files it's changing, behind a portal URL, with a site admin already created. To develop Sourcegraph itself, sg is still the tool.

Risk: none for customers. Nothing under docker-compose/ changes; the new files only take effect in an Amp orb.

Files

  • .agents/setup: starts Docker, installs the Compose plugin if missing, and adds orb guidance to the orb's AGENTS.md. Pulls no images, so the snapshot holds no build artifacts.
  • .amp/services.yaml: declares the sourcegraph service, its Executors and Jaeger portal links, and a health check that passes once the site admin exists.
  • .amp/sourcegraph.sh: starts the containers, creates the admin from the project env vars SOURCEGRAPH_ADMIN_USERNAME, SOURCEGRAPH_ADMIN_EMAIL, and SOURCEGRAPH_ADMIN_PASSWORD, sets five site config keys when it has no executor token, an older one, or another portal URL (externalURL, executors.accessToken, executors.frontendURL, codeIntelAutoIndexing.enabled, observability.tracing), prunes unused images when the deployment's images change, then follows the logs. It also uses docker-compose/docker-compose.override.yaml when it exists, and stops the containers when it fails or stops.
  • .amp/docker-compose.override.yaml: Caddy publishes Amp's port and port 80; the executor gets its token and all three queues; both zoekt services drop to 4 CPUs so a 4 vCPU orb works.
  • .amp/Caddyfile: caddy/builtins/http.Caddyfile minus Sec-Fetch-Dest and X-Frame-Options, so Sourcegraph loads in the Portal tab's iframe.

Worth a look

  • .amp/Caddyfile turns off Sourcegraph's clickjacking protection in the orb.
  • EXECUTOR_DOCKER_ADD_HOST_GATEWAY=true lets job containers reach the orb's ports; they need it to reach the frontend at http://host.docker.internal, since the portal URL is behind Amp's sign-in.
  • The admin password is a project env var, not a secret, so the agent can give it to the user. It also shows in the portal note. Only people who can open the thread can open its portal.
  • Writing the site config back drops its comments. That only happens on the first start, or when the executor token or portal URL changed.
  • The first start pulls 8.3 GB of images, in 54 to 66 s. Past Amp's 60 s port check, amp orb services ensure exits 1, but the service keeps going and a second ensure exits 0.

Checklist

  • All images have a valid tag and SHA256 sum (no image changes)

Test plan

In a 16 vCPU, 31 GB orb with the 8.2.0 images, from no containers, images, or volumes:

  • amp orb services ensure exits 0; 27 of 27 containers run, with no restarts.
  • The admin signs in through the portal, also inside a cross-origin iframe.
  • The executor is active on batches, batches-hooks, and codeintel. A server-side batch change and an auto-indexing job complete, and precise code navigation works on the index.
  • A search with ?trace=1 shows in Jaeger.
  • Restarts keep the admin, the site config ID, and settings added by hand. Removing the executor token puts it back.
  • Also works in an 8 vCPU orb, and in a 4 vCPU orb at an earlier commit with the same CPU change.
  • shellcheck is clean. Buildkite build 16951 passed.

Not tested: a batches-hooks job (needs published changesets), and a site config the script can't parse.

At b0c18d8, in a fresh 16 vCPU orb (thread), all of the above passed again, plus: a restart doesn't re-run site-init, rewrite the site config, or prune images, and the job images survive it; a failed start stops every container; deleting the executor token gets a new one into the site config; a changed image list prunes once, and docker-compose/docker-compose.override.yaml is picked up; an unused volume survives restarts; setup run 4 times leaves one guidance section. feebb26 fixes the two problems that run found, tested in the same orb: the health check waits for the site admin (/healthz passed about 2 s early), and a wrong password now logs sign-in's "Authentication failed".

Closes FE-600

@github-actions

Copy link
Copy Markdown

@marcleblanc2 marcleblanc2 changed the title Marc/amp orb setup amp: Add Amp Orb project setup Nov 11, 2026
@marcleblanc2
marcleblanc2 requested review from a team and bobheadxi November 13, 2026 01:33
@marcleblanc2
marcleblanc2 enabled auto-merge (squash) November 13, 2026 01:33

@michaellzc michaellzc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cool, but can you clarify the use case? I don't think the goal is to get a running sourcegraph (that's what sg/sg is for), but to assist with development the docker compose distro. you might want to put some wording around that in agents.md

Comment thread .agents/setup Resolved
@marcleblanc2

Copy link
Copy Markdown
Contributor Author

cool, but can you clarify the use case? I don't think the goal is to get a running sourcegraph (that's what sg/sg is for), but to assist with development the docker compose distro. you might want to put some wording around that in agents.md

@michaellzc yes, the use case is to test and verify changes to the Docker Compose deployment files, which requires a running Sourcegraph instance, Jaeger, and Executors to ensure that changes to the deployment files don't break anything, eg. ensuring a Precise auto-indexing job, and a Batch Change job can complete on the Executor.

Will add to the agents file.

marcleblanc2 and others added 10 commits November 12, 2026 21:15
Adds the Amp orb setup script, which installs Docker Compose and pulls the images, and a service that starts the Docker Compose deployment, creates the first site admin with a password made in the orb, and serves the frontend through a portal.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1c7a5-6b65-723b-980c-b85e1e9008b5
Co-authored-by: Amp <amp@ampcode.com>
Fixes found by running the service in an orb:

- Amp checks a service's port as a normal user, who cannot open port 80, and
  Amp's portal proxy in the orb listens on port 443, which Caddy also publishes.
  An override file now makes Caddy publish only the port Amp chooses.
- When the service process dies while the containers keep running, Amp chooses
  another free port and the script moves Caddy to it.
- The script removes its temporary files when it stops.

Adds the optional Jaeger and executor deployments. Each orb makes its own
executor token. On the first start, the script sets it as
executors.accessToken, and sets externalURL to the portal URL, which removes
the site admin warning about externalURL. Restarts do not change the site
configuration.

The Portal tab now shows the admin password in the note of the Sourcegraph
link, and links to the executors page and Jaeger.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1ccc1-035e-77c5-8b50-caa8352fd32d
The service wrote the site configuration only when /-/site-init had just
created the admin, so a first start that failed after that step left the
executor without a token for good. The script now reads the site
configuration and adds externalURL and executors.accessToken whenever the
token is missing, keeping the other settings, and leaves the configuration
alone on every other start.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1ccc1-035e-77c5-8b50-caa8352fd32d
Sets EXECUTOR_QUEUE_NAMES to batches, batches-hooks, and codeintel instead of
EXECUTOR_QUEUE_NAME=batches. The base executor file leaves EXECUTOR_QUEUE_NAME
empty, which the executor requires when EXECUTOR_QUEUE_NAMES is set.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1ccc1-035e-77c5-8b50-caa8352fd32d
…Jaeger

Found by running jobs in an orb. A server-side batch change already ran. An
auto-indexing job did not: Sourcegraph refused to queue it, and once queued,
its upload step got the portal URL, reached it from outside Amp's sign-in, and
received an HTML page. Sourcegraph also sent Jaeger no traces.

- Caddy also publishes port 80, and the executor sets
  EXECUTOR_DOCKER_ADD_HOST_GATEWAY, so the containers the executor starts
  reach Sourcegraph at http://host.docker.internal, which the script sets as
  executors.frontendURL.
- The script sets codeIntelAutoIndexing.enabled, which lets index jobs be
  queued. With the default policies, it indexes nothing on its own.
- The script sets observability.tracing. Sourcegraph exports the requests
  made with ?trace=1.
- externalURL no longer ends in a slash, which put "//" in trace links.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1c7a5-6b65-723b-980c-b85e1e9008b5
zoekt-indexserver-0 and zoekt-webserver-0 set cpus: 8, and Docker refuses a
limit above the host's CPU count, so in a 4 vCPU orb no container started.
The override lowers both to 4. With it, the deployment starts in a 4 vCPU,
8 GB orb, and uses 2.8 GB at idle.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1c7a5-6b65-723b-980c-b85e1e9008b5
Images and volumes from earlier versions stay on the orb's disk after an
upgrade. Every container of the deployment exists once the frontend is
healthy, so Docker keeps the images and volumes they use.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d2a1-43a0-7092-998e-43c135c772e8
Co-authored-by: Amp <amp@ampcode.com>
Setup output goes into the project snapshot, and the images are built
artifacts, not dev dependencies. Docker Compose pulls missing images on
the first start instead.

In a 16 vCPU orb, setup drops from 15 s to under 1 s and the first start
grows from about 37 s to about 54 s. Amp waits 60 s for the service; a
slower start makes amp orb services ensure exit 1, but the service keeps
running and the portal appears once Sourcegraph answers.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d2a1-43a0-7092-998e-43c135c772e8
Co-authored-by: Amp <amp@ampcode.com>
The Portal tab shows the portal in an iframe, and Sourcegraph refuses
that: its sign-in page, admin actions, and the Jaeger proxy reject
requests with Sec-Fetch-Dest: iframe, and every response carries
X-Frame-Options: DENY. The orb's Caddy now removes both, so Sourcegraph,
the Executors page, and Jaeger load in the tab. Customers' Caddy
configuration is unchanged.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d2a1-43a0-7092-998e-43c135c772e8
Co-authored-by: Amp <amp@ampcode.com>
People open Sourcegraph in many orbs, and a password that differs per orb
has to be looked up each time. The executor token is still made per orb.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d2a1-43a0-7092-998e-43c135c772e8
Co-authored-by: Amp <amp@ampcode.com>
marcleblanc2 and others added 5 commits November 12, 2026 21:42
After a branch renames or removes a service, its old container keeps
running and holds its image and volumes, so the prune cannot free them.
Every up in the service now passes --remove-orphans.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d2a1-43a0-7092-998e-43c135c772e8
Co-authored-by: Amp <amp@ampcode.com>
SOURCEGRAPH_ADMIN_USERNAME, SOURCEGRAPH_ADMIN_EMAIL, and
SOURCEGRAPH_ADMIN_PASSWORD set the first site admin, so every orb in the
project gets the same one and the repository holds no password. The
service stops with a message when one is missing. The sign-in requests
build their JSON with jq, so any character works in the values.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d2a1-43a0-7092-998e-43c135c772e8
Co-authored-by: Amp <amp@ampcode.com>
The orb is for developing and testing this repository's Docker Compose
deployment, not Sourcegraph itself, which sg in sourcegraph/sourcegraph
is for. amp orb services ensure prints only the Executors and Jaeger
links: the script adds the Sourcegraph link a few seconds later.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d2a1-43a0-7092-998e-43c135c772e8
Co-authored-by: Amp <amp@ampcode.com>
…on new versions

- Print why Sourcegraph refused the sign-in, the site admin, or a GraphQL request,
  and say when the site configuration does not parse
- Stop the containers when the service fails or stops before it follows the logs
- Prune unused images only when the deployment's images change, so executor job
  images do not pull again after every restart, and stop pruning volumes, which
  hold the data that upgrade and rename tests need
- Rewrite the site configuration when the executor token or the portal URL changed
- Include docker-compose/docker-compose.override.yaml when it exists
- Replace the orb guidance on every setup run, so changes to it reach new snapshots
- Say in AGENTS.md what .amp/ is, and that it follows the base files

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d323-9e56-72e1-ac97-48cbf9823c29
Co-authored-by: Amp <amp@ampcode.com>
- The health check is /-/amp-ready, which Caddy serves only after the script has
  created the site admin and configured the site. /healthz passed about 2 seconds
  before the admin existed, so a sign-in right after ensure got a 401
- When both sign-in and site-init fail, log both reasons: a wrong password on an
  existing site logged only site-init's "Signup failed unexpectedly."

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d323-9e56-72e1-ac97-48cbf9823c29
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2
marcleblanc2 enabled auto-merge (squash) November 13, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants