Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #204: Add a task for interacting with Acquia #442

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/actions/drainpipe/acquia/clone-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Clone Environment"
description: "Clones an Acquia Environment to another site"
inputs:
source-environment:
description: "Source environment i.e. the uuid or environment alias"
required: true
target-environment:
description: "Target environment i.e. the uuid or environment alias"
required: true
api-key:
description: "Acquia API Key"
required: true
api-secret:
description: "Acquia API Secret"
required: true
runs:
using: "composite"
steps:
- name: Clone Environment
run: |
source .github/actions/drainpipe/common/set-env/bash_aliases
drainpipe_exec "ACQUIA_API_KEY=${{ inputs.api-key }} ACQUIA_API_SECRET=${{ inputs.api-secret }} ./vendor/bin/task acquia:auth"
drainpipe_exec "acli env:mirror --no-config --no-interaction ${{ inputs.source-environment }} ${{ inputs.target-environment }}"
shell: bash
67 changes: 67 additions & 0 deletions .github/actions/drainpipe/acquia/deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: 'Deploy a branch to Acquia'
description: 'Deploys a review app to an Acquia Environment'
inputs:
github-token:
description: "GitHub token as generated automatically in secrets.GITHUB_TOKEN"
required: true
environment:
description: "The environment to push to, either uuid or alias"
required: true
environment-url:
description: "The environment URL"
required: true
run-installer:
description: "Whether or not to run the Drupal site installer. Defaults to false."
required: false
commit-message:
description: "The commit message to use when pushing to Acquia"
required: true
api-key:
description: "Acquia API Key"
required: true
api-secret:
description: "Acquia API Secret"
required: true
runs:
using: "composite"
steps:
- name: Create GitHub Deployment
uses: .github/actions/drainpipe/common/deployment-create
with:
github-token: ${{ inputs.github-token }}
environment: ${{ inputs.environment }}

- name: Put side in Maintenance Mode
run: |
source .github/actions/drainpipe/common/set-env/bash_aliases
drainpipe_exec "ACQUIA_API_KEY=${{ inputs.api-key }} ACQUIA_API_SECRET=${{ inputs.api-secret }} ./vendor/bin/task acquia:auth"
ENVIRONMENT="${{ inputs.environment }}"
APPLICATION=${ENVIRONMENT%.*}
drainpipe_exec "acli remote:aliases:download --no-interaction $APPLICATION"
drainpipe_exec "./vendor/bin/task drupal:maintenance:on site=@lullabot8.dev"
shell: bash

- name: Push to Acquia
uses: .github/actions/drainpipe/acquia/push
with:
environment: ${{ inputs.environment }}
commit-message: ${{ inputs.commit-message }}
api-key: ${{ inputs.api-key }}
api-secret: ${{ inputs.api-secret }}

- name: Run updates
uses: .github/actions/drainpipe/acquia/update
with:
environment: ${{ inputs.environment }}
run-installer: ${{ inputs.run-installer }}

- name: Set Deployment Status
uses: .github/actions/drainpipe/common/deployment-status
with:
github-token: ${{ inputs.github-token }}
environment-url: ${{ inputs.environment-url }}

- name: Take site out of Maintenance Mode
run: |
drainpipe_exec "./vendor/bin/task drupal:maintenance:on site=@${{ inputs.environment }}"
shell: bash
35 changes: 35 additions & 0 deletions .github/actions/drainpipe/acquia/push/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Push code to Acquia'
description: 'Pushes code to an Acquia environment'
inputs:
environment:
description: "The environment to push to, either uuid or alias"
required: true
commit-message:
description: "The commit message to use when pushing to Acquia"
required: true
api-key:
description: "Acquia API Key"
required: true
api-secret:
description: "Acquia API Secret"
required: true
runs:
using: "composite"
steps:
- name: Push to Acquia
run: |
source .github/actions/drainpipe/common/set-env/bash_aliases
drainpipe_exec "ACQUIA_API_KEY=${{ inputs.api-key }} ACQUIA_API_SECRET=${{ inputs.api-secret }} ./vendor/bin/task acquia:auth"
ENV_INFO=$(drainpipe_exec "acli api:environments:find ${{ inputs.environment }}")
VCS_TYPE=$(echo $ENV_INFO | jq -r ".vcs.type")
if [ "$VCS_TYPE" != "git" ]; then
echo "Unrecognised VCS type"
exit 1
fi
BRANCH=$(echo $ENV_INFO | jq -r ".vcs.path")
REMOTE=$(echo $ENV_INFO | jq -r ".vcs.url")
drainpipe_exec "./vendor/bin/task deploy:git directory=/tmp/release branch=\"$BRANCH\" remote=\"$REMOTE\" message=\"${{ inputs.commit-message }}\""
# Run code-switch to the same branch so we wait for everything to sync.
drainpipe_exec "acli api:environments:code-switch ${{ inputs.environment }} \"$BRANCH\""
shell: bash

27 changes: 27 additions & 0 deletions .github/actions/drainpipe/acquia/update/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Update or Install Acquia Site"
description: "Runs the Drupal updater or the site installer in an Acquia environment"
inputs:
environment:
description: "The environment to run the updates or install in, either uuid or alias e.g. 'test'"
required: true
run-installer:
description: "Whether or not to run the Drupal site installer. Defaults to false."
required: false
runs:
using: "composite"
steps:
- name: Update site on Acquia
run: |
source .github/actions/drainpipe/common/set-env/bash_aliases
drainpipe_exec "ACQUIA_API_KEY=${{ inputs.api-key }} ACQUIA_API_SECRET=${{ inputs.api-secret }} ./vendor/bin/task acquia:auth"
ENVIRONMENT="${{ inputs.environment }}"
APPLICATION=${ENVIRONMENT%.*}
drainpipe_exec "acli remote:aliases:download --no-interaction $APPLICATION"
if [ "${{ inputs.run-installer }}" == "true" ]; then
drainpipe_exec "./vendor/bin/drush @${{ inputs.environment }} --yes site:install --existing-config"
elif drainpipe_exec "./vendor/bin/task -l | grep '* update: ')"; then
drainpipe_exec "./vendor/bin/task update site=@${{ inputs.environment }}"
else
drainpipe_exec "./vendor/bin/task drupal:update site=@${{ inputs.environment }}"
fi
shell: bash
28 changes: 28 additions & 0 deletions .github/actions/drainpipe/common/deployment-create/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 'Create a GitHub deployment'
description: 'Creates a GitHub deployment and echos the ID to the $GITHUB_ENV file'
inputs:
github-token:
description: "GitHub token as generated automatically in secrets.GITHUB_TOKEN"
required: true
environment:
description: "The environment name"
required: true
runs:
using: "composite"
steps:
- uses: ./.github/actions/drainpipe/set-env

- name: Create GitHub Deployment
run: |
export GITHUB_DEPLOYMENT=$(curl -f -X POST \
https://api.github.com/repos/$GITHUB_REPOSITORY/deployments \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ inputs.github-token }}" \
-d "{\"ref\": \"$DRAINPIPE_SHA\", \"auto_merge\": false, \"environment\": \"${{ inputs.environment }}\", \"transient_environment\": false, \"required_contexts\": [], \"description\": \"Acquia Cloud environment\"}" \
)
export GITHUB_DEPLOYMENT_ID=$(echo $GITHUB_DEPLOYMENT | jq '.id')
echo "GITHUB_DEPLOYMENT_ID=$GITHUB_DEPLOYMENT_ID" >> $GITHUB_ENV
echo "Created GitHub Deployment ID $GITHUB_DEPLOYMENT_ID"
if [ -z "$GITHUB_DEPLOYMENT_ID" ] || [ "$GITHUB_DEPLOYMENT_ID" = "null" ]; then echo $GITHUB_DEPLOYMENT && exit 1; fi
curl -f -H "Authorization: token ${{ inputs.github-token }}" -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$GITHUB_REPOSITORY/deployments/$GITHUB_DEPLOYMENT_ID/statuses -d '{"state":"in_progress"}'
shell: bash
24 changes: 24 additions & 0 deletions .github/actions/drainpipe/common/deployment-status/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Sets the GitHub Deployment status'
description: 'Sets a GitHub deployment to success or failure'
inputs:
github-token:
description: "GitHub token as generated automatically in secrets.GITHUB_TOKEN"
required: true
environment-url:
description: "The environment URL"
required: true
runs:
using: "composite"
steps:
- uses: ./.github/actions/drainpipe/set-env

- name: Set deployment to success
run: |
curl -f -H "Authorization: token ${{ inputs.github-token }}" -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$GITHUB_REPOSITORY/deployments/$GITHUB_DEPLOYMENT_ID/statuses -d "{\"state\":\"success\", \"environment_url\": \"${{ inputs.environment-url }}\"}"
shell: bash

- name: Set Deployment Failure Status
run: |
curl -f -H "Authorization: token ${{ inputs.github-token }}" -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$GITHUB_REPOSITORY/deployments/$GITHUB_DEPLOYMENT_ID/statuses -d "{\"state\":\"failure\"}"
if: ${{ failure() }}
shell: bash
17 changes: 17 additions & 0 deletions .github/actions/drainpipe/common/set-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Set Env'
description: 'Creates some useful environment variables'
inputs:
github-api-token:
description: "GitHub API token"
required: true
github-api-token-username:
description: "GitHub API token username"
required: true
runs:
using: "composite"
steps:
- run: |
echo "Setting Drainpipe environment variables:"
echo "DRAINPIPE_PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')" >> $GITHUB_ENV
echo "DRAINPIPE_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)" >> $GITHUB_ENV
shell: bash
7 changes: 7 additions & 0 deletions .github/actions/drainpipe/common/set-env/bash_aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
drainpipe_exec() {
if [ "$DRAINPIPE_DDEV" == "true" ]; then
ddev exec "$@"
else
eval "$@"
fi
}
90 changes: 90 additions & 0 deletions .github/workflows/TestAcquia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: "Test Acquia"

on:
pull_request:
types: [opened, synchronize, reopened]

concurrency: development

jobs:
Test-Acquia:
runs-on: ubuntu-22.04
steps:
- name: Create a Drupal project
run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd

- uses: actions/checkout@v4
with:
path: drainpipe

- uses: ./drainpipe/scaffold/github/actions/common/set-env

- name: Install DDEV
uses: ./drainpipe/scaffold/github/actions/common/ddev
with:
git-name: Drainpipe Bot
git-email: no-reply@example.com
ssh-private-key: ${{ secrets.ACQUIA_SSH_PRIVATE_KEY }}

- name: Setup Project
run: |
ddev config --auto
ddev start
ddev composer config extra.drupal-scaffold.gitignore true
ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"]
ddev composer config --no-plugins allow-plugins.composer/installers true
ddev composer config --no-plugins allow-plugins.drupal/core-composer-scaffold true
ddev composer config --no-plugins allow-plugins.lullabot/drainpipe true
ddev composer config repositories.drainpipe --json '{"type": "path", "url": "drainpipe", "options": {"symlink": false}}'
ddev composer config extra.drainpipe.acquia --json '{"settings": true, "github": []}'
ddev composer config minimum-stability dev
ddev composer require lullabot/drainpipe --with-all-dependencies

Comment on lines +31 to +42
Copy link
Collaborator

@beto-aveiga beto-aveiga Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using composer with --json is failing.
I'm not clear why.
I also tried multiple JSON configurations through composer without success.
I used this instead:

          ddev config --auto
          ddev start
          ddev composer config --json extra.drupal-scaffold.allowed-packages \[\"lullabot/drainpipe\"]
          ddev composer config --no-plugins allow-plugins.composer/installers true
          ddev composer config --no-plugins allow-plugins.drupal/core-composer-scaffold true
          ddev composer config --no-plugins allow-plugins.lullabot/drainpipe true
          jq '.extra.drainpipe.acquia.settings = true' composer.json > tmp.json && mv tmp.json composer.json
          ddev composer config minimum-stability dev
          ddev composer config repositories.drainpipe path drainpipe
          ddev composer config repositories.drainpipe.options.symlink false
          ddev composer require lullabot/drainpipe --with-all-dependencies

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beto-aveiga it's a ddev bug, will be fixed in the next release. We fixed it on main for #729 and you can do something similar here.

- name: Install Drupal
run: |
ddev drush site:install minimal -y
echo "\$settings['config_sync_directory'] = '../config';" >> web/sites/default/settings.php
ddev drush config:export -y

- name: Create .drainpipeignore
run: |
echo "/web/sites/default/files" >> .drainpipeignore
echo "/.ddev" >> .drainpipeignore
echo "settings.ddev.php" >> .drainpipeignore
echo "/drainpipe" >> .drainpipeignore

- name: Create settings.php
run: |
echo '<?php' > web/sites/default/settings.php
echo "\$settings['container_yamls'][] = __DIR__ . '/services.yml';" >> web/sites/default/settings.php
echo "include __DIR__ . \"/settings.acquia.php\";" >> web/sites/default/settings.php
echo "\$settings['config_sync_directory'] = '../config';" >> web/sites/default/settings.php

- name: Snapshot Project
env:
directory: /tmp/release
remote:
message:
site:
run: |
echo "/drainpipe" >> .drainpipeignore
ddev task snapshot:directory directory=/tmp/release

- name: Clone from production to dev
uses: ./drainpipe/scaffold/github/actions/acquia/clone-env
with:
source-environment: lullabotsandbox.prod
target-environment: lullabotsandbox.dev
api-key: ${{ secrets.ACQUIA_API_KEY }}
api-secret: ${{ secrets.ACQUIA_API_SECRET }}

- name: Deploy to dev
uses: ./drainpipe/scaffold/github/actions/acquia/deploy
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
environment: lullabotsandbox.dev
environment-url: https://lullabotsandboxffi2ugpgwh.devcloud.acquia-sites.com
run-installer: true
commit-message: ${{ github.sha }}
api-key: ${{ secrets.ACQUIA_API_KEY }}
api-secret: ${{ secrets.ACQUIA_API_SECRET }}
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,28 @@ ddev ssh
terminus site:upstream:set [site_name] empty
```

### Acquia
Acquia specific tasks are contained in [`tasks/acquia.yml`](tasks/acquia.yml).
Add the following to your `Taskfile.yml`'s `includes` section to use them:
```yml
includes:
acquia: ./vendor/lullabot/drainpipe/tasks/acquia.yml
```
| | |
|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `task acquia:fetch-db` | Fetches a database from Acquia. Set `ACQUIA_ENVIRONMENT_ID` in Taskfile `vars`, along with `ACQUIA_API_KEY` and `ACQUIA_API_SECRET` as environment variables |

To enable auto configuration of Acquia Cloud settings:
```json
"extra": {
"drainpipe": {
"acquia": {
"settings": true
},
}
}
```


## GitHub Actions Integration

Expand Down Expand Up @@ -460,6 +482,16 @@ To enable deployment of Pantheon Review Apps:
- `PANTHEON_REVIEW_USERNAME` (optional) A username for HTTP basic auth local
- `PANTHEON_REVIEW_PASSWORD` (optional) The password to lock the site with

### Acquia
To add Acquia specific GitHub actions, add the following composer.json
```json
"extra": {
"drainpipe": {
"github": ["Acquia"]
}
}
```

## GitLab CI Integration

Add the following to `composer.json` for GitLab helpers:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
}
},
"archive": {
"exclude": ["/.github", "/.yarn", "/drainpipe-dev", "/metapackages"]
"exclude": ["/.github/workflows", "/.yarn", "/drainpipe-dev", "/metapackages"]
}
}
3 changes: 3 additions & 0 deletions scaffold/acquia/.drainpipeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Acquia reserved paths
/docroot/sites/default/files
/sites/default/files
Loading
Loading