Using Probo with Your Acquia Site



Search Results

If your site lives on Acquia Cloud, Probo can pull the most recent database backup straight from Acquia every time it builds a pull request. This keeps your Probo environments in sync with real content without you having to export and upload a database by hand. Probo does this by authenticating against the Acquia Cloud API with a set of credentials you provide as secrets, then running our acquia-integration.php script as a build step to download the latest backup into your build.

Note: You must still have your code in a repository on GitHub, Bitbucket, or GitLab. Probo builds from your git repository - it does not pull your code directly from Acquia. Only the database is retrieved from Acquia Cloud.

Step 1: Generate Your Acquia Cloud API Credentials

The integration authenticates using an Acquia Cloud API token (a key and secret pair). If you don’t already have one, log in to the Acquia Cloud Platform, open your account’s API Tokens page, and create a new token. See Acquia’s API authentication documentation for step-by-step instructions.

You will also need two identifiers that tell the script which database to fetch:

  • The environment ID for the environment whose database you want (for example, your prod or test environment).
  • The database name of the database within that environment.

Step 2: Add Your Acquia Secrets to Probo

The acquia-integration.php script reads its configuration from four environment variables. Add each of the following as a secret on your Probo project (or organization, if you want to share them across projects):

SecretDescription
ACQUIA_CLOUD_API_KEYThe API key (client ID) from your Acquia Cloud API token.
ACQUIA_CLOUD_API_SECRETThe API secret (client secret) from your Acquia Cloud API token.
ACQUIA_CLOUD_APPLICATION_IDThe ID of the Acquia environment whose database backup you want to pull.
ACQUIA_CLOUD_APPLICATION_NAMEThe name of the database to download from that environment.

Keep these values out of your repository. Because they are stored as Probo secrets, they are injected into your build as environment variables at run time and never need to be committed to your .probo.yml or your codebase. If a secret is defined on both the project and the organization, the project value takes precedence.

Step 3: Add the Build Step

Commit the acquia-integration.php script to an acquia-utils folder inside your repository’s document root (for example, docroot/acquia-utils/acquia-integration.php). This keeps the script alongside your application code so it can load your project’s autoloader and dependencies when it runs.

With your secrets in place and the script committed, add a step to your .probo.yml that runs it. The script uses your credentials to request the most recent backup from the Acquia Cloud API and writes it to your build’s assets directory as acquia-cloud-database.sql.gz.

Note: it is very important for the build step to download the database from Acquia come before your Drupal plugin step. This is because the Drupal Plugin will attempt to use your downloaded database and will fail if it cannot find it in the assets folder.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
steps:
  - name: Download database from Acquia
    plugin: Script
    script: |
      php $SRC_DIR/acquia-utils/acquia-integration.php
  - name: Provision Drupal
    plugin: Drupal
    composer: true
    redis: true
    database: acquia-cloud-database.sql.gz
    databaseGzipped: true
    clearCaches: true
    databaseUpdates: true
    subDirectory: docroot
    phpIniOptions:
      max_execution_time: 60
      upload_max_filesize: 25M
      post_max_size: 25M

Once the script has run, acquia-cloud-database.sql.gz is available in your assets directory and can be imported like any other database. When a Drupal site, this cooperates with Probo’s Drupal plugin - point the plugin at the downloaded file and it will import the database and finish standing up your environment.

Note: The backup is downloaded as a gzipped SQL file. Be sure any import step expects a .sql.gz file (or unzip it first).

For reference, here is the script we use based on the same script used in the Lando development environment configuration for Acquia. You can download this script directly by clicking here and downloading our Probo.CI Utilities Package.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  <?php
  require __DIR__ . '/../../docroot/autoload.php';

  use League\OAuth2\Client\Provider\GenericProvider;
  use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
  use GuzzleHttp\Client;

  // See https://docs.acquia.com/acquia-cloud/develop/api/auth/
  // for how to generate a client ID and Secret.
  $clientId = getenv('ACQUIA_CLOUD_API_KEY');
  $clientSecret = getenv('ACQUIA_CLOUD_API_SECRET');
  $applicationID = getenv('ACQUIA_CLOUD_APPLICATION_ID');
  $applicationName = getenv('ACQUIA_CLOUD_APPLICATION_NAME');
  $outputFile = getenv('ASSET_DIR') . '/acquia-cloud-database.sql.gz';

  if (empty($clientId) || empty($clientSecret)) {
    throw new \Exception('Missing Acquia cloud API Key and/or API Secret.
      See https://docs.acquia.com/acquia-cloud/develop/api/auth/ to create a new
      key. For information on Acquia integration with Probo.CI, please see our
      page at https://www.probo.ci/docs/integrations/acquia');
  }

  $provider = new GenericProvider([
    'clientId' => $clientId,
    'clientSecret' => $clientSecret,
    'urlAuthorize' => '',
    'urlAccessToken' => 'https://accounts.acquia.com/api/auth/oauth/token',
    'urlResourceOwnerDetails' => '',
  ]);

  // Try to get an access token using the client credentials grant.
  $accessToken = $provider->getAccessToken('client_credentials');

  // Generate a request object using the access token.
  $request = $provider->getAuthenticatedRequest(
    'GET',
    'https://cloud.acquia.com/api/environments/' . $applicationID . '/databases/' . $applicationName . '/backups?sort=-created&limit=1',
    $accessToken
  );

  // Send the request.
  $client = new Client();
  $response = $client->send($request);
  $responseBody = $response->getBody();

  $contents = json_decode((string) $responseBody);

  $backupId = $contents->_embedded->items[0]->id;
  $request = $provider->getAuthenticatedRequest(
    'GET',
    'https://cloud.acquia.com/api/environments/' . $applicationID . '/databases/' . $applicationName . '/backups/' . $backupId . '/actions/download',
    $accessToken
  );
  $response = $client->send($request);
  $responseBody = $response->getBody();
  $file = fopen($outputFile, 'wb');
  fwrite($file, (string) $responseBody);
Get Started with Probo.CI

Want to Try Probo today?
Get Started Fast!.

When you sign up for a Probo.CI registration code, you will get a two week trial of the plan of your choosing. For more information on how to get started, click here .

LEARN MORE ABOUT PROBO.CI'S PRICING