Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Setup new site

Start your setup with Kalaboom and choose setup CI. If your site is Drupal 9 this is all you need to do. If your site is Drupal 8 you will need to take some manual steps.

Update composer.json

After Kalaboom is done you need to update your composer.json file to include the following in the scripts section of the file:

"prepare-for-pantheon": [
            "DrupalProject\\composer\\ScriptHandler::prepareForPantheon"
        ]

Above drupal-scaffold section include the following:

"prepare-for-pantheon": "DrupalProject\\composer\\ScriptHandler::prepareForPantheon",

Update ScriptHandler file for composer

Navigate to /scripts/composer/ScriptHandler and update the file with the following:

  // This is called by the QuickSilver deploy hook to convert from
  // a 'lean' repository to a 'fat' repository. This should only be
  // called when using this repository as a custom upstream, and
  // updating it with `terminus composer <site>.<env> update`. This
  // is not used in the GitHub PR workflow.
  public static function prepareForPantheon()
  {
    // Get rid of any .git directories that Composer may have added.
    // n.b. Ideally, there are none of these, as removing them may
    // impair Composer's ability to update them later. However, leaving
    // them in place prevents us from pushing to Pantheon.
    $dirsToDelete = [];
    $finder = new Finder();
    foreach (
      $finder
        ->directories()
        ->in(getcwd())
        ->ignoreDotFiles(false)
        ->ignoreVCS(false)
        ->depth('> 0')
        ->name('.git')
      as $dir) {
      $dirsToDelete[] = $dir;
    }
    $fs = new Filesystem();
    $fs->remove($dirsToDelete);

    // Fix up .gitignore: remove everything above the "::: cut :::" line
    $gitignoreFile = getcwd() . '/.gitignore';
    $gitignoreContents = file_get_contents($gitignoreFile);
    $gitignoreContents = preg_replace('/.*::: cut :::*/s', '', $gitignoreContents);
    file_put_contents($gitignoreFile, $gitignoreContents);
  }

Make sure to include it inside the class e. g. prior to the last }

Setup theme processing in Drupal 8 and Drupal 9

Depending on how your theme is processed update node module cache and theme build commands, put them after composer install command in the CI.

Theme is compiled in theme folder

- restore_cache:
                name: Restore Node Cache
                keys:
                  - drupal-node-{{ checksum "web/themes/custom/MY_THEME/package-lock.json" }}
                  # Fallback to most recent build if this exact config hasn't been installed before.
                  - drupal-node-

This snippet goes after composer restore cache command

After composer-prepare-for-pantheon include the following / update existing

# Install node modules and build theme.
            - run:
                name: Node Install
                command: cd web/themes/custom/MY_THEME  && BUILD_COMMAND_FOR_YOUR_THEME

Save node cache

- save_cache:
                name: Save Node Cache
                key: drupal-node-{{ checksum "web/themes/custom/MY_THEME/package-lock.json" }}
                paths:
                  - node_modules

Theme is compiled in the root with npm it

restore_cache:
                name: Restore Node Cache
                keys:
                  - drupal-node-{{ checksum "package-lock.json" }}
                  # Fallback to most recent build if this exact config hasn't been installed before.
                  - drupal-node-

After composer-prepare-for-pantheon include the following / update existing

# Install node modules and build theme.
            - run:
                name: Node Install
                command: npm it

Save node cache

- save_cache:
                name: Save Node Cache
                key: drupal-node-{{ checksum "package-lock.json" }}
                paths:
                  - node_modules

Setup existing site

Replace config.yml in .circleci folder with something like the following:

version: 2.1
workflows:
  version: 2
  build_and_test:
    jobs:
      - pantheon/push:
          checkout: false
          clone_content: false
          pre-steps:
            - checkout
            - restore_cache:
                name: Restore Node Cache
                keys:
                  - drupal-node-{{"package-lock.json" }}
                  # Fallback to most recent build if this exact config hasn't been installed before.
                  - drupal-node-
            # Restore composer packages if they have been previously downloaded and cached.
            - restore_cache:
                name: Restore Composer Cache
                keys:
                  - drupal-composer-v1-{{ checksum "composer.lock" }}
                  # Fallback to most recent build if this exact config hasn't been installed before.
                  - drupal-composer-v1-
            - run: composer -n install --optimize-autoloader --ignore-platform-reqs --no-dev
            - run:
                name: Prepare gitignore
                command: |
                  rm .gitignore
                  mv .gitignore-deploy .gitignore
            - run: composer prepare-for-pantheon
            # Install node modules and build theme.
            - run:
                name: Node Install
                command: npm it
            # Cache node_modules so the packages don't need to be redownloaded next time.
            - save_cache:
                name: Save Node Cache
                key: drupal-node-{{ checksum "package-lock.json" }}
                paths:
                  - node_modules
            # Cache composer so the packages don't need to be redownloaded next time.
            - save_cache:
                name: Save Composer Cache
                key: drupal-composer-v1-{{ checksum "composer.lock" }}
                paths:
                  - ~/.composer/cache
          filters:
            branches:
              only:
                - master
      - pantheon/push:
          checkout: false
          terminus_clone_env: "dev"
          pre-steps:
            - checkout
            - restore_cache:
                name: Restore Node Cache
                keys:
                  - drupal-node-{{ checksum "package-lock.json" }}
                  # Fallback to most recent build if this exact config hasn't been installed before.
                  - drupal-node-
            # Restore composer packages if they have been previously downloaded and cached.
            - restore_cache:
                name: Restore Composer Cache
                keys:
                  - drupal-composer-v1-{{ checksum "composer.lock" }}
                  # Fallback to most recent build if this exact config hasn't been installed before.
                  - drupal-composer-v1-
            - run: composer -n install --optimize-autoloader --ignore-platform-reqs --no-dev
            - run: composer prepare-for-pantheon
            - run:
                name: Node Install
                command: npm it
            # Cache node_modules so the packages don't need to be redownloaded next time.
            - save_cache:
                name: Save Node Cache
                key: drupal-node-{{ checksum "package-lock.json" }}
                paths:
                  - node_modules
            # Cache composer so the packages don't need to be redownloaded next time.
            - save_cache:
                name: Save Composer Cache
                key: drupal-composer-v1-{{ checksum "composer.lock" }}
                paths:
                  - ~/.composer/cache
          filters:
            branches:
              ignore:
                - master

orbs:
  pantheon: pantheon-systems/pantheon@0.5.1

Then perform composer.json and ScriptHandler files as described above. Update theme compilation command as described above. Make sure your composer.json requires: "pantheon-systems/drupal-integrations": "^8.0"

Setup project in CircleCI

You will need to add three environment variables in the project. In CircleCI interface click on project settings → Environment Variables. Add the following variables:

TERMINUS_SITE - Name of the site on pantheon (project name).

TERMINUS_SITE_NAME - same as the above

TERMINUS_TOKEN - machine token - generate deployment machine token through the dashboard on Pantheon.

Gotchas

If your site was deploying with a different CI you may want to add -v1- to composer cache key as shown in the snippet above.

  • No labels