Create an app from a repository
Bring code from GitHub, GitLab or any git host into Git, then create an app the platform builds from it with a Dockerfile or Railpack.
The platform builds from a repository in Git, so code that lives on GitHub, GitLab or any other git
host comes in first. Replace my-app with your app's name and
https://github.com/example/my-app with your repository's URL.
Prerequisites
- Permission for
deploy:CreateApp, and for importing,git:CreateRepository. To deploy,deploy:DeployApp. - For a private source, a GitHub or GitLab token with read access.
- In the console, also
deploy:DescribeAppto open Apps (without it the console shows Access denied and names that action).
Step 1: Import the repository
Importing brings the history, every branch and tag, and (from GitHub and GitLab) the pull requests. Keep in sync makes the copy a mirror that follows its source on a schedule. The repository page shows the import while it runs, and why if it fails. See Git.
- Open Git, then Repositories, then choose New repository. From Create app, when the organization has no repositories, Import from GitHub, GitLab or a URL opens the same form and brings you back to the app form; otherwise the Import it link under Repository does.
- On the Source and identity step, choose Import from a URL.
- For Source URL, enter the https URL of the repository. For a private source, enter the Access token.
- Enter the repository's Name.
- (Optional) Turn on Keep in sync, and choose how often under Sync.
- Choose Continue. On the Access step, choose Import repository. The repository page shows the import as it runs.
dcloud git repositories import --name my-app \
--source '{"url":"https://github.com/example/my-app"}'A private source takes --token; --mirror '{"intervalMinutes":15}' keeps the copy following its
source.
Not available in API. Importing is a Git operation; see :op[git.repositories.import] in the _API Reference_.
Not available in Terraform. An import is a one-time action, not a resource.
Step 2: Create the app
- Open Apps, then choose Create app.
- On the What to run step, under Where does this app come from?, choose A repository.
- For Repository, choose the repository, and for Branch, its branch (the repository's default branch to start with). A repository whose import failed cannot be chosen; one still being imported shows a warning, because a deployment started before the import finishes has nothing to clone.
- Under How is the image built?, choose Dockerfile (built with BuildKit from the Dockerfile in the root directory) or Railpack (detects the language and builds without a Dockerfile).
- (Optional) For Root directory, enter the build context inside the repository;
.is the whole repository. - (Optional) Clear Deploy on push (selected by default) to deploy only when you start a deployment.
- Choose Continue, then complete the App, machine and domain and Environment steps as in Create an app from an image.
- Choose Create and deploy, or, with Deploy immediately cleared, Create app.
dcloud deploy apps create --name my-app --builder dockerfile \
--git-repository-id 6f7a8b9c-0d1e-4f2a-b3c4-d5e6f7a8b9c0 --branch main --root-dir . \
--deploy-on-pushPOST /deploy/api/apps
{
"name": "my-app",
"builder": "railpack",
"gitRepositoryId": "6f7a8b9c-0d1e-4f2a-b3c4-d5e6f7a8b9c0",
"branch": "main",
"deployOnPush": true
}resource "dcloud_app" "web" {
name = "my-app"
builder = "dockerfile"
git_repository_id = dcloud_git_repository.web.id
branch = "main"
deploy_on_push = true
}Through the CLI, API and Terraform, deployOnPush is on by default for an app with a repository,
and the app is created without a deployment. Without gitRepositoryId the dockerfile and
railpack builders are refused (400, The "dockerfile" builder builds from a repository, so a repository is required).
Result
Each deployment builds the image on a temporary build machine, pushes it to your registry and runs it. The build machine is deleted once the image is pushed, and its time is not billed to you; if you bring your own cloud account, it runs and is billed there. With deploy on push, every later push to the branch deploys the pushed commit as the person who pushed; a push by someone who may not deploy the app is recorded in its activity and not deployed. See Turn on deploy on push.
Related
- Deploy an app, which also shows how to follow the build log
POST /deploy/api/apps·dcloud deploy apps create·dcloud_app
Related