Skip to content

Commit

Permalink
Updated to scaffold 4.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Mar 4, 2024
1 parent 7cfd2b4 commit ecd1d4d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 45 deletions.
56 changes: 30 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ version: 2
aliases:
# SSH deployment key fingerprint from CircleCI App -> Project -> Settings -> SSH Permissions.
# Replace with the value used for your project.
- &deploy_ssh_fingerprint "82:3d:00:0b:fb:2f:d0:98:7c:c5:4b:73:63:b1:06:98"
- &deploy_ssh_key_fingerprint "82:3d:00:0b:fb:2f:d0:98:7c:c5:4b:73:63:b1:06:98"

# Configuration for shared runner containers, applied to each job.
- &container_config
working_directory: ~/project
docker:
- image: cimg/php:8.2-browsers

job-build: &job-build
job-test: &job-test
steps:
- checkout

Expand Down Expand Up @@ -73,86 +73,90 @@ job-build: &job-build
path: /tmp/artifacts

jobs:
build-php-8.1:
test-php-8.1:
<<: *container_config
docker:
- image: cimg/php:8.1-browsers
<<: *job-build
<<: *job-test

build-php-8.2:
test-php-8.2:
<<: *container_config
docker:
- image: cimg/php:8.2-browsers
<<: *job-build
<<: *job-test

build-php-8.1-legacy:
test-php-8.1-legacy:
<<: *container_config
docker:
- image: cimg/php:8.1-browsers
environment:
DRUPAL_VERSION: 9.5
DRUPAL_PROJECT_SHA: 9.x
<<: *job-build
<<: *job-test

build-php-8.2-legacy:
test-php-8.2-legacy:
<<: *container_config
docker:
- image: cimg/php:8.2-browsers
environment:
DRUPAL_VERSION: 9.5
DRUPAL_PROJECT_SHA: 9.x
<<: *job-build
<<: *job-test

build-php-8.2-next:
test-php-8.2-next:
<<: *container_config
docker:
- image: cimg/php:8.2-browsers
environment:
DRUPAL_VERSION: 10@beta
<<: *job-build
<<: *job-test

deploy:
<<: *container_config
environment:
DEPLOY_SSH_FINGERPRINT: *deploy_ssh_fingerprint
DEPLOY_SSH_KEY_FINGERPRINT: *deploy_ssh_key_fingerprint
steps:
- checkout

- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint
- run: DEPLOY_BRANCH=${DEPLOY_BRANCH:-${CIRCLE_BRANCH}} .devtools/deploy.sh
- *deploy_ssh_key_fingerprint

- run:
name: Deploy
command: DEPLOY_BRANCH=${DEPLOY_BRANCH:-${CIRCLE_BRANCH}} .devtools/deploy.sh

workflows:
version: 2
main:
commit:
jobs:
- build-php-8.1:
- test-php-8.1:
filters:
tags:
only: /.*/
- build-php-8.2:
- test-php-8.2:
filters:
tags:
only: /.*/
- build-php-8.1-legacy:
- test-php-8.1-legacy:
filters:
tags:
only: /.*/
- build-php-8.2-legacy:
- test-php-8.2-legacy:
filters:
tags:
only: /.*/
- build-php-8.2-next:
- test-php-8.2-next:
filters:
tags:
only: /.*/
- deploy:
requires:
- build-php-8.1
- build-php-8.2
- build-php-8.1-legacy
- build-php-8.2-legacy
- build-php-8.2-next
- test-php-8.1
- test-php-8.2
- test-php-8.1-legacy
- test-php-8.2-legacy
- test-php-8.2-next
filters:
tags:
only: /.*/
Expand Down
63 changes: 44 additions & 19 deletions .devtools/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
# Deploy code to a remote repository.
#
# - configures local git
# - adds deployment SSH key to SSH agent
# - force-pushes code to a remote code repository branch
#
# It is a good practice to create a separate Deployer user with own SSH key for
# every project.
#
# Add the following variables through CI provider UI.
# - DEPLOY_USER_NAME - name of the user who will be committing to a remote repository.
# - DEPLOY_USER_EMAIL - email address of the user who will be committing to a remote repository.
Expand All @@ -34,37 +30,62 @@ DEPLOY_REMOTE="${DEPLOY_REMOTE:-}"
# Git branch to deploy. If not provided - current branch will be used.
DEPLOY_BRANCH="${DEPLOY_BRANCH:-}"

# The fingerprint of the SSH key of the user on behalf of which the deployment
# is performed.
DEPLOY_SSH_FINGERPRINT="${DEPLOY_SSH_FINGERPRINT:-}"

# Set to 1 if the deployment should proceed. Useful for testing CI configuration
# before an actual code push.
DEPLOY_PROCEED="${DEPLOY_PROCEED:-0}"

# The fingerprint of the SSH key.
DEPLOY_SSH_KEY_FINGERPRINT="${DEPLOY_SSH_KEY_FINGERPRINT:-}"

#-------------------------------------------------------------------------------

if [ -n "${DEPLOY_SSH_KEY_FINGERPRINT}" ]; then
echo "-------------------------------"
echo " Setup SSH "
echo "-------------------------------"

mkdir -p "${HOME}/.ssh/"
echo -e "\nHost *\n\tStrictHostKeyChecking no\n\tUserKnownHostsFile /dev/null\n" >"${HOME}/.ssh/config"

# Find the MD5 hash if the SSH_KEY_FINGERPRINT starts with SHA256.
if [ "${DEPLOY_SSH_KEY_FINGERPRINT#SHA256:}" != "${DEPLOY_SSH_KEY_FINGERPRINT}" ]; then
for file in "${HOME}"/.ssh/id_rsa*; do
calculated_sha256_fingerprint=$(ssh-keygen -l -E sha256 -f "${file}" | awk '{print $2}')
if [ "${calculated_sha256_fingerprint}" = "${DEPLOY_SSH_KEY_FINGERPRINT}" ]; then
DEPLOY_SSH_KEY_FINGERPRINT=$(ssh-keygen -l -E md5 -f "${file}" | awk '{print $2}')
DEPLOY_SSH_KEY_FINGERPRINT="${DEPLOY_SSH_KEY_FINGERPRINT#MD5:}"
break
fi
done
fi

file="${DEPLOY_SSH_KEY_FINGERPRINT//:/}"
file="${HOME}/.ssh/id_rsa_${file//\"/}"

if [ ! -f "${file:-}" ]; then
echo "ERROR: Unable to find SSH key file ${file}."
exit 1
fi

if [ -z "${SSH_AGENT_PID:-}" ]; then
eval "$(ssh-agent)"
fi

ssh-add -D
ssh-add "${file}"
ssh-add -l
fi

echo "-------------------------------"
echo " Deploy code "
echo "-------------------------------"

[ -z "${DEPLOY_USER_NAME}" ] && echo "ERROR: Missing required value for DEPLOY_USER_NAME" && exit 1
[ -z "${DEPLOY_USER_EMAIL}" ] && echo "ERROR: Missing required value for DEPLOY_USER_EMAIL" && exit 1
[ -z "${DEPLOY_REMOTE}" ] && echo "ERROR: Missing required value for DEPLOY_REMOTE" && exit 1
[ -z "${DEPLOY_SSH_FINGERPRINT}" ] && echo "ERROR: Missing required value for DEPLOY_SSH_FINGERPRINT" && exit 1

[ "${DEPLOY_PROCEED}" != "1" ] && echo "> Skip deployment because $DEPLOY_PROCEED is not set to 1" && exit 0

echo "> Configure git and SSH to connect to remote servers for deployment."
mkdir -p "${HOME}/.ssh/"
echo -e "Host *\n\tStrictHostKeyChecking no\n" >"${HOME}/.ssh/config"
DEPLOY_SSH_FILE="${DEPLOY_SSH_FINGERPRINT//:/}"
DEPLOY_SSH_FILE="${HOME}/.ssh/id_rsa_${DEPLOY_SSH_FILE//\"/}"
[ ! -f "${DEPLOY_SSH_FILE:-}" ] && echo "ERROR: Unable to find Deploy SSH key file ${DEPLOY_SSH_FILE}." && exit 1
if [ -z "${SSH_AGENT_PID:-}" ]; then eval "$(ssh-agent)"; fi
ssh-add -D >/dev/null
ssh-add "${DEPLOY_SSH_FILE}"

echo "> Configure git user name and email, but only if not already set."
[ "$(git config --global user.name)" == "" ] && echo "> Configure global git user name ${DEPLOY_USER_NAME}." && git config --global user.name "${DEPLOY_USER_NAME}"
[ "$(git config --global user.email)" == "" ] && echo "> Configure global git user email ${DEPLOY_USER_EMAIL}." && git config --global user.email "${DEPLOY_USER_EMAIL}"
Expand All @@ -75,6 +96,10 @@ git config --global push.default matching
echo "> Add remote ${DEPLOY_REMOTE}."
git remote add deployremote "${DEPLOY_REMOTE}"

if [ -z "${DEPLOY_BRANCH}" ]; then
DEPLOY_BRANCH="$(git symbolic-ref --short HEAD)"
fi

echo "> Push code to branch ${DEPLOY_BRANCH}."
git push --force deployremote HEAD:"${DEPLOY_BRANCH}"

Expand Down

0 comments on commit ecd1d4d

Please sign in to comment.