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

Justafish/issue 204 acquia integration v2 #732

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1ce6e34
Issue #204: Add a task for fetching a database from Acquia
justafish Feb 22, 2024
6118b7a
Allow the db name to be customised
justafish Mar 1, 2024
a67e79f
Add GitHub Actions for Acquia
justafish Mar 5, 2024
652d845
Source a different file if we're testing ourselves
justafish Mar 5, 2024
cee500d
Move actions to .github/actions
justafish Mar 5, 2024
aef7660
Change back paths
justafish Mar 5, 2024
abc86f6
Update .github/actions/drainpipe/acquia/deploy/action.yml
justafish Mar 12, 2024
b631e9d
Update .github/workflows/TestAcquia.yml
justafish Mar 12, 2024
8ca5fa1
Update README.md
justafish Mar 12, 2024
c580937
Update README.md
justafish Mar 12, 2024
b15f123
To trigger CI workflows
beto-aveiga Nov 5, 2024
6f3298b
To trigger workflows
beto-aveiga Nov 5, 2024
c67f6bc
ISSUE-204: restoring README.md
beto-aveiga Nov 5, 2024
d8366c8
ISSUE-204: ScaffoldInstallerPlugin merge with main [skip ci]
beto-aveiga Nov 6, 2024
edd938f
ISSUE-204: README.md merge with main [skip ci]
beto-aveiga Nov 6, 2024
d0f2dc9
Merge branch 'justafish/issue-204-acquia-integration' into justafish/…
beto-aveiga Nov 6, 2024
7225a9a
ISSUE-204: avoid errors running these configuration commands by alter…
beto-aveiga Nov 6, 2024
78ad5c1
ISSUE-204: avoid errors running these configuration commands by alter…
beto-aveiga Nov 6, 2024
1c934d7
ISSUE-204: ssh debug
beto-aveiga Nov 6, 2024
ce8f063
ISSUE-204: similar commands to do the sae
beto-aveiga Nov 6, 2024
a6b3640
ISSUE-204: no debug now
beto-aveiga Nov 6, 2024
2dc50a0
To trigger CI workflows
beto-aveiga Nov 6, 2024
2a4929c
Merge branch 'main' of github.com:Lullabot/drainpipe into justafish/i…
beto-aveiga Nov 6, 2024
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
}
97 changes: 97 additions & 0 deletions .github/workflows/TestAcquia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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 --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

# This line was causing an error related to a JSON syntax error.
# ddev composer config extra.drainpipe.acquia --json '{"settings": true, "github": []}'
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

- 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 }}
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,27 @@ 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 All @@ -370,7 +391,9 @@ copied to `.github/actions/drainpipe` in your project:
```json
"extra": {
"drainpipe": {
"github": []
"acquia": {
"github": []
}
}
}
```
Expand Down Expand Up @@ -554,6 +577,16 @@ include which will give you helpers that you can include and reference for tasks
such as setting up [Terminus](https://pantheon.io/docs/terminus). See
[scaffold/gitlab/Pantheon.gitlab-ci.yml](scaffold/gitlab/Pantheon.gitlab-ci.yml).

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

## Tugboat

Add the following to `composer.json` to add Tugboat configuration:
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"]
}
}
Loading
Loading