Docs Menu
Docs Home
/ /
Atlas App Services

Deploy Automatically with GitHub

On this page

  • Overview
  • Prerequisites
  • Enable Automatic Deployment with GitHub
  • Make Changes from the UI
  • Make Changes from the CLI
  • Summary

You can configure an Atlas App Services App to automatically deploy whenever you push App configuration files to a GitHub repository. You can clone the GitHub repository to your computer and then use standard Git commands to pull down the latest versions and deploy new changes.

  • A GitHub account and repository. The repository should either be empty or contain an exported configuration directory for an existing App. For information on how to create an empty repository, see GitHub's create a repo guide.

  • An installed copy of the Git CLI. If you do not have git installed, see the official guide for Installing Git.

  • A MongoDB Atlas Programmatic API Key to authenticate and authorize access to your app's underlying Git repo. If you have not yet generated a programmatic API key for your Atlas organization, do so now.

You can enable automatic deployment with GitHub using the App Services UI, the App Services CLI, or the App Services Admin API.

1

In order to automatically deploy based on a GitHub repository, Atlas App Services requires that you install a GitHub app that has, at minimum, read access to the repository.

To install the app, click Deployment in the left navigation menu of the App Services UI. Select the Configuration tab and then click Install App Services on GitHub. A new browser window will open to the GitHub application installation flow.

Note

GitHub Authentication

GitHub may require you to provide your GitHub account credentials before you can install the app.

Select the GitHub account or organization for which you want to install the app:

GitHub Application install location screen

Specify one or more repositories for which you want to grant App Services read access. You can either select specific repositories or grant access to all of your repositories on GitHub. Select the repositories you want to use and then click Install.

GitHub Application permissions request screen

After you install the application, return to the Configuration tab and click the Authorize button to finish connecting App Services to GitHub. This leads you to a github permissions screen. Click Authorize MongoDB Atlas App Services.

GitHub Application authorization request screen

Note

GitHub Permissions

You can manage permissions for the App Services GitHub application from the Installed GitHub Apps page in your GitHub settings.

2

Once you have linked your GitHub account to your App, you can specify a repository that App Services should automatically deploy. Specify the Repository, Branch, and Directory that contain the App's configuration files and then click Save.

GitHub repository selection

Note

The list of repositories will only contain repos that you have granted App Services read access to.

3

Clone a local copy of the Git repository that you specified:

git clone https://github.com/<organization>/<repo>.git

The configured branch and directory must contain configuration files that define your application. You can create the configuration manually or export the application directory of an existing app.

Add the application directory to the repository and then commit the changes:

git add -A
git commit -m "Adds App Services Application Directory"

Once you have committed the latest version of the application to the repository, push it to your GitHub repository:

git push origin <branch name>
4

After you have specified a repository to deploy and initialized it with the latest version of your app, you need to enable automatic deployment to begin deploying it. On the Configuration tab of the Deploy page, click Enable Automatic Deployment. In the modal that appears, click Enable Automatic Deployment to confirm your selection.

Enable Automatic GitHub Deployment in the App Services UI
5

A deployment contains one or more changes that you have made to your application since the previous deployment. Make any additions, modifications, or deletions to the repository that you want to include in your deployment.

Refer to the App Configuration reference page and individual component reference pages for details on the structure and schema of your application directory.

Important

Do not make breaking schema changes via automated deploy

Because breaking - also called destructive - schema changes require special handling, App Services does not support making breaking schema changes via automated deploy with GitHub. Instead, you should make breaking changes from the App Services UI.

6

Once you have updated your application configuration, you can deploy the updates as a new version of your App by pushing them to the GitHub repo that you specified. If Automatic GitHub Deployment is enabled, App Services immediately deploys the latest commit for the configured branch and directory.

When you are ready to deploy, commit all of the files that you want to include and then push them to GitHub:

git add -A
git commit -m "<commit message>"
git push origin <branch name>

Once you successfully push your changes to GitHub, App Services immediately deploys a new version of your application that matches the state of the latest commit. Client applications will automatically use the newest version, so make sure that you also update your client code to use the new version if necessary.

Note

Deployment History

You can see the currently deployed version of your application as well as a historical log of previous deployments in the Deployment History table in the App Services UI.

New in version 1.1.0.

You can use the CLI to configure, enable, or disable automatic deployment.

1

Use your MongoDB Atlas Admin API Key to log in to the CLI:

appservices login --api-key="<my api key>" --private-api-key="<my private api key>"
2

The App Services CLI can walk you through the process of configuring automatic deployment. This is an interactive command.

appservices deploy configure

The command also supports additional flags that you can optionally include. For information on these flags, refer to appservices deploy configure.

App Services CLI immediately enables automatic deployment when you complete this command. You don't need to run the enable command as an additional step.

Tip

Configuring automatic deployment via CLI relies on a GitHub beta feature

The ability to configure automatic deployment using App Services CLI relies on a GitHub feature that is currently in beta. If GitHub makes breaking changes to this feature, you may be unable to configure automatic deployment using the App Services CLI. In this case, use the App Services UI or Admin API to configure automatic deployment.

The GitHub beta feature only affects configuring automatic deployment. If you have previously configured automatic deployment for your application, you can enable or disable it using the App Services CLI regardless of the status of this beta GitHub feature.

3

You can use the App Services CLI to view configuration details after you have configured automatic deployment.

appservices deploy describe

You can also disable and enable automatic deployment using the App Services CLI. For more information about these commands and their options, refer to appservices deploy.

1

Call the admin user authentication endpoint with your MongoDB Atlas API key pair:

curl -X POST \
https://services.cloud.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/login \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"username": "<Public API Key>",
"apiKey": "<Private API Key>"
}'

If authentication succeeds, the response body contains a JSON object with an access_token value:

{
"access_token": "<access_token>",
"refresh_token": "<refresh_token>",
"user_id": "<user_id>",
"device_id": "<device_id>"
}

The access_token grants access to the App Services Admin API. You must include it as a Bearer token in the Authorization header for all Admin API requests.

2

You can get the existing deployment configuration for your App by making a GET request to the Get the Deployment Configuration endpoint.

curl -X GET \
https://services.cloud.mongodb.com/api/admin/v3.0/groups/{groupId}/apps/{appId}/deploy/config \
-H 'Authorization: Bearer <access_token>'
3

You can update the existing deployment configuration for your App by making a PATCH request to the Configure Deployment endpoint.

curl -X PATCH \
https://services.cloud.mongodb.com/api/admin/v3.0/groups/{groupId}/apps/{appId}/deploy/config \
-H 'Authorization: Bearer <access_token>' \
-d '{
"ui_drafts_disabled": true,
"automatic_deployment": {
"enabled": true,
"provider": "github",
"installation_ids": [
"string"
]
},
"last_modified": 0
}'

Automatic GitHub deployment does not prevent you from making changes to your App from the App Services UI. You can make changes to your app via the UI, and App Services automatically commits changes back to your linked GitHub repository.

Tip

If your linked GitHub repository contains new commits that are not reflected in your App Services UI changes, App Services can't automatically commit those changes to your repo. However, you can use the Export button to download the updated configuration files to your local machine, and then you push them manually to your GitHub repository.

When changes are committed to your linked GitHub repository, you'll see a Commit: <commit-hash> link in your app's Deployment History.

GitHub repository selection

You can click that link to view the commit in GitHub. The mongodb-realm bot appears as the commit author.

GitHub repository selection

Previously, we have recommended that you avoid making changes to your app with App Services CLI after configuring automatic deployment. Starting with App Services CLI v1.1.0 and later, you can safely use the App Services CLI to make changes to your app.

App Services CLI version 1.1.0 and later

In App Services CLI v1.1.0 and later, a push from the App Services CLI automatically generates a corresponding commit in GitHub. This keeps your code changes synchronized with your version-controlled GitHub source of truth.

App Services CLI version 1.0.3 and earlier

In App Services CLI v1.0.3 and earlier, avoid making changes to your app with the App Services CLI after configuring automatic deployment, because:

  • If you push changes with the CLI while GitHub deployment is enabled, App Services deploys the changes but does not commit them back to your linked repository.

  • The configuration files in your repository no longer reflect the current state of your app.

  • To get the changes you pushed, a contributor must manually pull the latest configuration files directly from your App. The GitHub repository is no longer the source of truth.

  • If a contributor adds a new commit to a stale repo, they overwrite any deployed but uncommitted changes.

  • You can deploy your App by modifying a repo hosted on GitHub.

  • While Automatic GitHub Deployment is enabled, App Services immediately deploys the latest commit. To deploy, commit your changes locally, then push them to your repo on GitHub.

  • When you make changes via the App Services UI after enabling Automatic GitHub Deployment, those changes are automatically committed back to your linked repository.

  • If you would like to use App Services CLI to update configuration files after enabling Automatic GitHub Deployment, use App Services CLI v1.1.0 or later.

Next

What are the Atlas Application Services?