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 $status2Add 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.shtests:
image: node:22
variables:
CI_RUN_ID: $CI_PIPELINE_ID
script:
- curl -fsSL https://compute.fdtn.dev/install | sh
- sh ci/fdtn-test.sh
artifacts:
when: always
paths: [results]image: node:22
pipelines:
default:
- step:
name: tests
script:
- export CI_RUN_ID=$BITBUCKET_BUILD_NUMBER
- curl -fsSL https://compute.fdtn.dev/install | sh
- sh ci/fdtn-test.sh
artifacts: [results/**]version: 2.1
jobs:
tests:
docker: [{ image: cimg/node:22.19 }]
steps:
- checkout
- run: curl -fsSL https://compute.fdtn.dev/install | sh
- run: CI_RUN_ID=$CIRCLE_BUILD_NUM sh ci/fdtn-test.sh
- store_artifacts: { path: results }
workflows:
main: { jobs: [tests] }pipeline {
agent { docker { image 'node:22' } }
environment { FDTN_API_KEY = credentials('fdtn-api-key') }
stages {
stage('tests') {
steps {
sh 'curl -fsSL https://compute.fdtn.dev/install | sh'
sh 'CI_RUN_ID=$BUILD_NUMBER sh ci/fdtn-test.sh'
}
}
}
post { always { archiveArtifacts artifacts: 'results/**', allowEmptyArchive: true } }
}# Agent needs Node.js 22.19 or newer. # Add FDTN_API_KEY as a password parameter: env.FDTN_API_KEY curl -fsSL https://compute.fdtn.dev/install | sh CI_RUN_ID=%build.number% sh ci/fdtn-test.sh
Adapt it
| To | Change |
|---|---|
| Use more sandboxes | SHARDS=10 sh ci/fdtn-test.sh. When machines are busy, extra starts queue. |
| Use another test runner | Change the test command. Write reports to /home/user/results. |
| Skip installs, or add vCPU and memory | Build a template and use its name in place of base. |
Notes
CI_RUN_IDtags 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.