Docs Menu
Docs Home
/ /
Atlas App Services
/

Copy an App

On this page

  • Overview
  • Before You Begin
  • Procedure

You can make a copy of an existing App by reusing the App's configuration files and manually porting Secrets.

You might want to copy an application if:

  • You use feature branches for development. Use a unique copy of the App for each feature branch to avoid conflicts.

  • You run tests against a working version of the App. You can copy an App for each test run to to ensure a consistent start state.

  • You deploy the same app to clusters across regions using a local deployment model. You can copy an App to serve multiple regions locally.

You will need the following to copy an App in the CLI:

  • A MongoDB Atlas account with Project Owner permissions. To learn how to sign up for a free account, see Get Started with Atlas.

  • A MongoDB Atlas Admin API public/private key pair. The API key must have Project Owner permissions to work with App Services Admin API.

  • A copy of App Services CLI installed and added to your local system PATH. To learn how, see Install App Services CLI.

To copy an App based on configuration files in a GitHub repository, you must enable Automatic GitHub Deployment for the App.

Warning

If Automatic GitHub Deploymeny is enabled, do not push changes to your App with App Services CLI. For more information, see Avoid Making Changes from the CLI.

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

Create a new blank App. Choose a name and set the deployment model and region to be what you want the copied App to use. For more information, see Create an App.

Example

# Create the new App
appservices app create \
--name "myapp-copy" \
--deployment-model "LOCAL" \
--provider-region "aws-us-west-2"
3

An App's configuration files do not include the names or values of any Secrets.

You must have access to the original App's existing Secret values and add them manually to the new App. If your app doesn't have any Secrets, you can skip this step.

To add the secrets from your original App:

  1. Get the names of all the secrets from the exported app by following the view secrets documentation.

  2. Save the names of all the secrets to a secure location. The list won't include the actual Secret values, but it's useful to have a list of the Secret names to add to your new App.

  3. Find the value for each of the original App's Secrets.

  4. Add each Secret individually to the new App. To learn how, see Define a Secret.

Important

Add Secrets Before You Copy Configuration Files

Some App Services features require you to have one or more Secrets defined before you can define and use the feature. For example, OAuth authentication providers require a Secret that contains a clientSecret value.

If you push configuration files that reference undefined Secrets, the deployment will fail.

4

Pull the latest version of your original App's configuration files to your local filesystem. To learn how, see Export an App.

Example

# Pull the config files for an existing App
appservices pull --remote="myapp-abcde"

Copy all configuration files from your original App, except for root_config.json, to the new App's configuration directory. You should use the new App's root_config.json and overwrite any other configuration files.

Example

# Copy all configuration files except for root_config.json
cp -r myapp myapp-temp
rm myapp-temp/root_config.json
cp -r myapp-temp/* myapp-copy
rm -rf myapp-temp
5

Push the configuration files you copied from your original App. The new App will automatically update and deploy with the copied configuration files.

Example

# Navigate back to the new App
cd myapp-copy
# Push the copied configuration files to App Services
appservices push
1

Create a new directory to store the copied App's configuration files. You can create a new repository for the copied App or keep both Apps' configurations in the same repository using branches or subdirectories.

Example

# Create a new directory for the copied App
mkdir myapp-copy
2

Create a new blank App. Choose the same name as the original App and set the deployment model and region to be what you want the copied App to use. For more information, see Create an App.

Once created, save the new App's configuration files to the directory you created in the previous step if they aren't already.

Example

# Navigate to the new App's directory
cd myapp-copy
# Create the new App. The create command saves the new
# App's configuration file directory in the current directory
appservices app create \
--name "myapp-copy" \
--deployment-model "LOCAL" \
--provider-region "aws-us-west-2"
cp -r myapp-copy/* .
rm -rf myapp-copy
# Navigate back to the root of the repo
cd ..
3

In the new App, set up and enable Automatic Github Deployment. Make sure to point to the repository, branch, and directory that you created for the new App, not your original App.

4

An App's configuration files do not include the names or values of any Secrets.

You must have access to the original App's existing Secret values and add them manually to the new App. If your app doesn't have any Secrets, you can skip this step.

To add the secrets from your original App:

  1. Get the names of all the secrets from the exported app by following the view secrets documentation.

  2. Save the names of all the secrets to a secure location. The list won't include the actual Secret values, but it's useful to have a list of the Secret names to add to your new App.

  3. Find the value for each of the original App's Secrets.

  4. Add each Secret individually to the new App. To learn how, see Define a Secret.

Important

Add Secrets Before You Copy Configuration Files

Some App Services features require you to have one or more Secrets defined before you can define and use the feature. For example, OAuth authentication providers require a Secret that contains a clientSecret value.

If you push configuration files that reference undefined Secrets, the deployment will fail.

5

Copy all configuration files from your original App, except for root_config.json, to the new App's configuration directory. You should use the new App's root_config.json and overwrite any other configuration files.

Example

# Copy all configuration files except for root_config.json
cp -r myapp myapp-temp
rm myapp-temp/root_config.json
cp -r myapp-temp/* myapp-copy
rm -rf myapp-temp
6

Commit the copied application configuration files and then push them to GitHub. The new App will automatically update and deploy with the copied configuration files.

Example

# Navigate back to the new App
cd myapp-copy
# Push the copied configuration files to GitHub
git add -A
git commit -m "Copy configuration from myapp"
git push origin main

Back

Update an App