# .gitlab-ci.yml # Pin the CLI with LEVELRAIL_VERSION=vX.Y.Z on the installer step for reproducible builds. # Build, push and deploy by digest with no stored Levelrail token: the job's # GitLab ID token is swapped for a deploy token that expires after 15 minutes. # One-time setup on the control plane: # levelrail-cli apps ci trust add my-app --provider gitlab \ # --repo OWNER/REPO --ref refs/heads/main --protected-ref # On a self-managed GitLab add --issuer https://gitlab.example.com. # LEVELRAIL_API_URL is a plain CI/CD variable holding the dashboard URL set in # Settings; it is also the audience of the ID token. stages: [deploy] deploy: stage: deploy image: docker:27 services: [docker:27-dind] resource_group: production rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH id_tokens: LEVELRAIL_ID_TOKEN: aud: $LEVELRAIL_API_URL variables: APP: my-app IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA LEVELRAIL_CLI_INSTALL_DIR: /usr/local/bin script: - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY" - docker build -t "$IMAGE" . - docker push "$IMAGE" - PINNED=$(docker inspect --format '{{index .RepoDigests 0}}' "$IMAGE") # With a Node image, `npm install --global levelrail-cli@0.9.4` replaces these two lines. - apk add --no-cache curl - curl -fsSL https://levelrail.com/install-cli.sh | sh - LEVELRAIL_TOKEN=$(levelrail-cli apps ci token "$APP" --provider gitlab) - export LEVELRAIL_TOKEN - levelrail-cli apps deploy "$APP" --image "$PINNED" - levelrail-cli apps wait "$APP" --timeout 5m