Skip to content

Commit

Permalink
Merge pull request #1907 from acquia/ACMS-4329
Browse files Browse the repository at this point in the history
ACMS-4329: New CD workflow added.
  • Loading branch information
vishalkhode1 authored Dec 4, 2024
2 parents 26474a9 + e0acf49 commit bbcf22a
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 84 deletions.
11 changes: 11 additions & 0 deletions .github/cd.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/docroot/sites/*/settings.*.php
/docroot/sites/*/services*.yml
/docroot/sites/*/files
/docroot/sites/*/private
/docroot/sites/simpletest

# Directories specific to this template
/docroot/libraries
/docroot/modules/contrib
/docroot/profiles/contrib
/docroot/themes/contrib
6 changes: 5 additions & 1 deletion .github/workflows/acquia_cms_ci.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
paths-ignore:
- README.md

env:
ORCA_VERSION: ^4
jobs:
static_code_analysis:
if: ${{ github.event_name == 'pull_request' }}
Expand All @@ -17,7 +19,6 @@ jobs:
# Provide your package's name.
ORCA_SUT_NAME: acquia/acquia_cms
ORCA_SUT_BRANCH: develop
ORCA_VERSION: ^4
ORCA_PACKAGES_CONFIG_ALTER: ../acquia_cms/tests/packages_alter.yml
ORCA_FIXTURE_PROJECT_TEMPLATE: acquia/drupal-recommended-project
ORCA_ENABLE_NIGHTWATCH: "FALSE"
Expand Down Expand Up @@ -151,6 +152,7 @@ jobs:
composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n
curl https://gist.githubusercontent.com/rajeshreeputra/170586f217b422eb9cdfd9ca9457a2e3/raw/c2f277ba9005b91d7f662cacf37b3940a66a9b8c/sut-path-reposories.patch | git -C ../orca apply
curl https://gist.githubusercontent.com/rajeshreeputra/efe6fd50fc839e0e05480a5eb58d1ba4/raw/c5e81aa3c0fba9f4abe42460f3d24c7ca976a527/remove-local-settings.patch | git -C ../orca apply
composer config extra."drupal-scaffold".file-mapping {} --json -d ${ORCA_SUT_DIR}
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
Expand Down Expand Up @@ -255,6 +257,7 @@ jobs:
composer self-update
composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n
curl https://gist.githubusercontent.com/rajeshreeputra/170586f217b422eb9cdfd9ca9457a2e3/raw/c2f277ba9005b91d7f662cacf37b3940a66a9b8c/sut-path-reposories.patch | git -C ../orca apply
composer config extra."drupal-scaffold".file-mapping {} --json -d ${ORCA_SUT_DIR}
- name: Before Install
run: |
# Remove all ExistingSite test in CI.
Expand Down Expand Up @@ -346,6 +349,7 @@ jobs:
composer self-update
composer create-project --no-dev --ignore-platform-req=php acquia/orca ../orca "$ORCA_VERSION" -n
curl https://gist.githubusercontent.com/rajeshreeputra/170586f217b422eb9cdfd9ca9457a2e3/raw/c2f277ba9005b91d7f662cacf37b3940a66a9b8c/sut-path-reposories.patch | git -C ../orca apply
composer config extra."drupal-scaffold".file-mapping {} --json -d ${ORCA_SUT_DIR}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand Down
148 changes: 148 additions & 0 deletions .github/workflows/deployment.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: "Code Deployment on Acquia Environment"
on:
push:
branches: [ develop, main, ACMS-4329 ]

concurrency:
group: "ci-${{ github.ref }}"
cancel-in-progress: true

env:
GIT_AUTHOR_NAME: "CD"
GIT_COMMITTER_NAME: "CD"
GIT_COMMITTER_EMAIL: "[email protected]"
GIT_AUTHOR_EMAIL: "[email protected]"
PHP_VERSION: 8.3
CORE_VERSION: ^11

jobs:
acquia_code_deployment:
if: ${{ github.event_name == 'push' }}
name: "Code Deployment"
runs-on: ubuntu-latest
environment: acquia_code_deployment
env:
ACQUIA_CLOUD_ENVIRONMENT: "dev"
ACQUIA_CLOUD_API_KEY: ${{ secrets.ACQUIA_CLOUD_API_KEY }}
ACQUIA_CLOUD_API_SECRET: ${{ secrets.ACQUIA_CLOUD_API_SECRET }}
ACQUIA_CLOUD_APPLICATION: ${{ secrets.ACQUIA_CLOUD_APPLICATION }}
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
- name: Configure SSH keys
run: |
mkdir -p ~/.ssh
echo "${ACQUIA_CLOUD_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
# Loop through each line in the environment variable.
echo "${ACQUIA_CLOUD_KNOWN_HOSTS}" | while IFS= read -r KNOWN_HOST; do
if [[ -n "${KNOWN_HOST}" ]]; then
CLEANED_HOST=$(echo "${KNOWN_HOST}" | tr -d '\r' | xargs -n1)
ssh-keyscan "${CLEANED_HOST}" >> ~/.ssh/known_hosts 2>/dev/null || {
echo "Warning: Unable to scan host ${CLEANED_HOST}. Skipping."
}
fi
done
shell: bash
env:
ACQUIA_CLOUD_SSH_PRIVATE_KEY: ${{ secrets.ACQUIA_CLOUD_SSH_PRIVATE_KEY }}
ACQUIA_CLOUD_KNOWN_HOSTS: ${{ vars.ACQUIA_CLOUD_KNOWN_HOSTS }}
- name: Setup Drupal Project
run: |
# Install specific version of Drupal Core.
composer require drupal/core:${CORE_VERSION} drupal/core-composer-scaffold:${CORE_VERSION} drupal/core-recommended:${CORE_VERSION} --no-install --no-update -n
# Move some of development dependencies to production depencies or else acli push:artifact will fail.
composer require oomphinc/composer-installers-extender --no-install --no-update -n
composer update "drupal/core-*" drush/drush "drupal/*" -W --with=drupal/core:${CORE_VERSION} --minimal-changes
# Include MySQL 5.7 connection settings, before DRS require line is added.
echo "require DRUPAL_ROOT . '/modules/contrib/mysql57/settings.inc';" >> docroot/sites/default/settings.php
# Download acquia/drupal-recommended-settings plugin & drupal/mysql57 library.
composer require acquia/drupal-recommended-settings:^1.1 drupal/mysql57
# Update .gitignore file, otherwise acli won't push any settings file.
sed -i 's/docroot\//docroot\/core/' .gitignore
cat .github/cd.gitignore >> .gitignore 2>/dev/null
# Create symlink directory for multisite headless and community.
cd docroot/sites
ln -s default headless
ln -s default community
cd -
git add . && git commit -m "Update drupal core and it's dependencies." 2>/dev/null
- name: Setup Acquia CLI
run: |
curl -OL https://github.com/acquia/cli/releases/latest/download/acli.phar
chmod +x acli.phar
mv acli.phar /usr/local/bin/acli
acli --version
acli auth:login --key=${ACQUIA_CLOUD_API_KEY} --secret=${ACQUIA_CLOUD_API_SECRET} -n
ACQUIA_APPLICATION_UUID=$(acli api:applications:find ${ACQUIA_CLOUD_APPLICATION} -n | jq -r '.uuid')
acli link ${ACQUIA_APPLICATION_UUID} -n
acli remote:aliases:download -n
git add . && git commit -m "Added acli & drush alias configurations." 2>/dev/null
- name: Deploy & Switch Code
shell: bash
run: |
BRANCH_TO_DEPLOY=acli-${GITHUB_REF_NAME}
acli push:artifact ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} --destination-git-branch=${BRANCH_TO_DEPLOY} -n
DEPLOYED_BRANCH=$(acli api:environments:find ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} -n | jq -r '.vcs.path')
# If BRANCH_TO_DEPLOY is NOT the same as DEPLOYED_BRANCH. Then switch code.
if [ "$BRANCH_TO_DEPLOY" != "$DEPLOYED_BRANCH" ]; then
# Step 1: Run the code:switch command and capture its output.
response=$(acli api:environments:code-switch ${ACQUIA_CLOUD_APPLICATION}.${ACQUIA_CLOUD_ENVIRONMENT} ${BRANCH_TO_DEPLOY} -n)
# Step 2: Extract the notification ID from the JSON response
notification_id=$(echo "$response" | jq -r '.notification')
# Step 3: Check if the notification ID was successfully extracted.
if [[ -z "$notification_id" ]]; then
echo "Error: Notification ID not found in the response."
exit 1
fi
progress=0
timeout=1800 # Timeout in seconds (30 minutes).
start_time=$(date +%s) # Get the current time in seconds
echo "Please wait while code is being switched..."
# Step 4: Poll the notification status until progress reaches 100.
while [[ "$progress" -lt 100 ]]; do
# Run the notification find command.
notification_response=$(acli api:notifications:find "$notification_id" -n)
# Extract the progress value.
progress=$(echo "$notification_response" | jq -r '.progress')
# Display current progress.
#echo "Current progress: $progress%"
# Check if we've exceeded the timeout (5 minutes).
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [[ "$elapsed_time" -ge "$timeout" ]]; then
# Calculate minutes and seconds.
minutes=$((elapsed_time / 60))
seconds=$((elapsed_time % 60))
echo "Error: Timeout reached after $minutes minute(s) and $seconds second(s). Progress did not reach 100%."
exit 1
fi
# Wait for 5 seconds before polling again.
sleep 5
done
fi
47 changes: 0 additions & 47 deletions acquia-pipelines.yml

This file was deleted.

17 changes: 5 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,6 @@
}
}
},
"consumer_image_styles": {
"type": "vcs",
"url": "https://git.drupalcode.org/issue/consumer_image_styles-3429496.git"
},
"config_filter": {
"type": "vcs",
"url": "https://git.drupalcode.org/issue/config_filter-3428542.git"
},
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
Expand Down Expand Up @@ -262,8 +254,7 @@
"phpstan/extension-installer": true,
"tbachert/spi": true,
"webdriver-binary/binary-chromedriver": true,
"wikimedia/composer-merge-plugin": true,
"tbachert/spi": true
"wikimedia/composer-merge-plugin": true
},
"preferred-install": {
"drupal/core": "dist"
Expand All @@ -287,8 +278,10 @@
"[web-root]/profiles/README.txt": false,
"[web-root]/robots.txt": false,
"[web-root]/sites/README.txt": false,
"[web-root]/sites/default/default.settings.php": {
"append": "./patches/d9-acms-settings.patch"
"[web-root]/sites/default/settings.php": {
"mode": "replace",
"overwrite": false,
"path": "docroot/core/assets/scaffold/files/default.settings.php"
},
"[web-root]/themes/README.txt": false,
"[web-root]/themes/contrib/cohesion-theme/templates/maintenance-page.html.twig": "./patches/maintenance-page.patch",
Expand Down
Loading

0 comments on commit bbcf22a

Please sign in to comment.