SkybuDocs

Ferdigheter · Apper

Deploy from Git

Connect an app to a GitHub repository or GitLab project so every push to its branch deploys, and pull requests get previews.

skill://apps/deploy-from-gitAgenter leser den med resources/read eller skills_read. Den er skrevet på engelsk, for agentene.

A linked app deploys the newest commit on one branch each time someone pushes to it, and each pull request (or merge request on GitLab) gets its own preview. Skybu fetches the commit, keeps only the app's folder, and builds it exactly like an upload. The organisation must already have GitHub or GitLab connected; agents cannot connect them.

In short

  1. get_github_status and get_gitlab_status to see what is connected. If nothing is, the user connects it in the dashboard first.
  2. list_github_repos or list_gitlab_repos to find the repository's exact name.
  3. create_app_from_git for a new app, or link_git_repo for an app that exists.
  4. Follow the first deployment with get_app and get_deployment until it is live.

Step 1: is GitHub or GitLab connected?

{ "name": "get_github_status", "arguments": {} }

configured: false means this Skybu installation has no GitHub App; use GitLab or an upload instead. An empty installations list means the organisation has not connected GitHub. The answer also gives previewsPerApp.

{ "name": "get_gitlab_status", "arguments": {} }

Lists the GitLab connections, each with its address (gitlab.com or a self-managed GitLab) and tokenExpiresAt.

If the one the user needs is missing, tell them to connect it under Settings → Integrations at https://platform.skybu.no/#/org/settings/integrations:

  • GitHub: "Connect GitHub" installs the Skybu GitHub App. They choose which repositories it may read.
  • GitLab: an access token with the api scope, best a group access token with the Maintainer role, which keeps working when people leave. The CLI does the same: skybu gitlab connect [--url <address>] < token.

Never ask the user to paste a token into the conversation; there is no tool that takes one.

Step 2: find the repository

{ "name": "list_github_repos", "arguments": {} }
{ "name": "list_gitlab_repos", "arguments": {} }

GitHub lists what the App's installations can read. GitLab lists only projects where the token's user has at least the Maintainer role, because Skybu adds a webhook to the project when it is linked. A repository that is not in the list cannot be linked: the user gives the GitHub App access to it, or a GitLab user with more rights connects.

A new app, deployed from the branch at once:

{
  "name": "create_app_from_git",
  "arguments": {
    "projectId": "<project id>",
    "name": "web",
    "repo": "nordlys/kundeportal",
    "branch": "main",
    "rootDir": "apps/web",
    "dataClass": "personal"
  }
}

An existing app:

{ "name": "link_git_repo", "arguments": { "appId": "<app id>", "repo": "nordlys/kundeportal", "branch": "main" } }
ArgumentMeaning
repoowner/repo on GitHub, or the full path on GitLab (group/subgroup/project).
providergithub or gitlab. Only needed when both have a repository with that name (repo_ambiguous).
branchPushes to this branch deploy to production. Default main.
rootDirBuild from this folder, for a monorepo. Default: the repository's root.
dataClass, department, ownerAs for any new app: ask the user (skill://apps/deploy-an-app).

The folder is all the build sees: its package.json, lockfile or Dockerfile must be inside it. Several apps can link the same repository, one folder each. Linking again changes the branch or folder and keeps the previews.

link_git_repo does not deploy. To deploy the branch now, without waiting for a push:

{ "name": "deploy_latest_commit", "arguments": { "appId": "<app id>" } }

Step 4: follow the deployment

create_app_from_git returns appId, the address and deployment with its number and commit; deploy_latest_commit returns the number and commit. Get the deployment's id from get_app, which lists the newest deployments, then poll get_deployment as in skill://apps/deploy-an-app. If deployment is null, the app was created but its first deploy did not start; deploy_latest_commit tries again and says why it cannot. A failed build keeps the previous version serving (skill://apps/fix-a-failed-deploy).

What happens on a push

  • A push to the linked branch deploys that commit to every app linked to the repository and branch. The deployment records the commit, its message, author and branch.
  • Skybu posts a commit status (skybu/<app>) that goes from building to deployed or failed.
  • If the organisation requires approval for production, the build waits as awaiting_approval and the commit status says so (skill://apps/previews-and-approval).
  • A commit with nothing in the root folder becomes a failed deployment saying so. So does a source over 50 MB after the folder is selected.

Pull request previews

Opening a pull request, or pushing to one, deploys its head commit to a preview at <app>-pr-<n>.<org>.skybu.app. The preview gets the app's preview variables and, when the project has a database, its own empty database. Closing or merging the pull request deletes the preview. Pull requests from forks get no preview, and at most a few previews run per app at once. See skill://apps/previews-and-approval.

Unlinking

{ "name": "unlink_git_repo", "arguments": { "appId": "<app id>" } }

Pushes stop deploying and the app's previews are deleted, with their databases. Confirm with the user first.

Things to know

  • get_git_link shows the linked repository, branch, folder and a link to it, or null.
  • Errors: repo_not_accessible (no installation or connection can reach it), gitlab_forbidden (the token's user is not Maintainer), branch_not_found or gitlab_not_found (check the branch), not_linked (no repository on the app), invalid_root_dir (give a relative path inside the repository).
  • GitLab tokens expire. When tokenExpiresAt is near or past, the user replaces the token in the dashboard or with skybu gitlab token <connection id> < token; linked projects keep working.
  • Disconnecting GitHub or GitLab unlinks its repositories and deletes their previews.
  • Variables for the build and the running app are set on the app, not in the repository (skill://apps/environment-variables).