Foundational Compute

Run CI on Foundational Compute

Run your tests in sandboxes from the CI you already use: one secret and two lines.

Your CI job
- curl -fsSL https://compute.fdtn.dev/install | sh
- sh ci/fdtn-test.sh

1Add the script

Save as ci/fdtn-test.sh. It splits tests/ across 3 sandboxes, writes JUnit reports to results/, exits with the test result and always stops its sandboxes.

ci/fdtn-test.sh
#!/bin/sh
# Run the tests in tests/ on Foundational Compute, split across SHARDS sandboxes.
# Needs FDTN_API_KEY and the fdtn command. Exits non-zero when a test fails.
set -eu
SHARDS=${SHARDS:-3}
RUN=ci-${CI_RUN_ID:-$(date +%s)}-$$
OUT=${OUT:-results}
trap 'fdtn kill --all -s running,paused -m run=$RUN >/dev/null 2>&1 || true' EXIT
TMP=$(mktemp -d "${RUNNER_TEMP:-$HOME}/fdtn.XXXXXX")
tar czf "$TMP/src.tgz" --exclude=.git .
i=0
while [ "$i" -lt "$SHARDS" ]; do
  id=$(fdtn create base -d --timeout 900 -e SHARD=$i -e SHARDS=$SHARDS -m run=$RUN)
  fdtn cp "$TMP/src.tgz" "$id:/home/user/src.tgz"
  i=$((i + 1))
done
fdtn each -m run=$RUN -- sh -c "mkdir -p repo && tar xzf src.tgz -C repo && pip install -q pytest"
status=0
fdtn each -m run=$RUN -- sh -c 'cd repo && python3 -m pytest -q --junitxml=/home/user/results/junit.xml $(ls tests/test_*.py | awk -v s=$SHARD -v n=$SHARDS "NR % n == s")' || status=$?
fdtn collect -m run=$RUN --path /home/user/results --destination "$OUT" || true
exit $status

2Add the API key

Create a key named ci with an expiry at compute.fdtn.dev (API keys). Add it to your CI as the secret FDTN_API_KEY.

3Add the two lines

GitHub Actions · GitLab CI · Bitbucket · CircleCI · Jenkins · TeamCity

.github/workflows/tests.yml
name: tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    env:
      FDTN_API_KEY: ${{ secrets.FDTN_API_KEY }}
      CI_RUN_ID: ${{ github.run_id }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 22 }
      - run: curl -fsSL https://compute.fdtn.dev/install | sh
      - run: sh ci/fdtn-test.sh

Adapt it

ToChange
Use more sandboxesSHARDS=10 sh ci/fdtn-test.sh. When machines are busy, extra starts queue.
Use another test runnerChange the test command. Write reports to /home/user/results.
Skip installs, or add vCPU and memoryBuild a template and use its name in place of base.

Notes

  • CI_RUN_ID tags the sandboxes, so parallel runs stay apart.
  • Each sandbox stops after 15 minutes (--timeout 900), even if the CI job dies.
  • Cost: 3 sandboxes for 1 minute = 3 × $0.039 × 1/60 = about $0.002.