Skip to content

Commit 52dd702

Browse files
committed
Update Readme and add core Drupal files
1 parent 757303a commit 52dd702

File tree

250 files changed

+34363
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+34363
-10
lines changed

.circleci/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# CircleCI service overview
2+
3+
This service runs a number of discrete testing steps, defined as jobs in `.circleci/config.yml`.
4+
5+
See https://circleci.com/docs/2.0 for configuration file/language specifications.
6+
7+
Drupal config is generally copied into the required locations in the containers for better clarity.
8+
9+
Environment variable usage is encouraged to safeguard sensitive values, but usage can be fiddly as interpolation in parts of the config file will work in some parts but not others.
10+
11+
## Running locally
12+
13+
It is possible to debug/run the pipeline locally using the CircleCI Local CLI tool.
14+
15+
See https://circleci.com/docs/2.0/local-cli/ for installation and further details.
16+
17+
TL;DR:
18+
19+
- Install with: `brew install circleci`
20+
- Run individual jobs like this: `circleci local execute --job YOUR_JOB_NAME -e GITHUB_TOKEN=YOUR-TOKEN-VALUE -e DB_NAME=circle_test -e DB_USER=root -e DB_PASS= -e DB_PREFIX= -e DB_HOST=127.0.0.1 -e DB_PORT=3306 -e DB_NAMESPACE=Drupal\\Core\\Database\\Driver\\mysql -e DB_DRIVER=mysql -e CONFIG_SYNC_DIRECTORY=../config/sync`
21+
- Note how environmental variables from CircleCI are not accessible outside of that platform. You need to pass them in as per above when running locally. That might be tricky if you don't have a certain key value; CircleCI's environment variable browser will not show you the raw value once the variable has been created.
22+
- Features such as parallelism, workspace sharing and directory caching won't work. You may need to adjust your job's execution steps to compensate for this.
23+
24+
## Interaction with other supporting repos/services
25+
26+
This is the primary CI pipeline. Other, supporting repositories will have their own pipelines that provide basic, but helpful, checks to trap simple issues earlier on.

.circleci/config.yml

+343
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
version: 2.1
2+
3+
# Default docker image.
4+
default_docker_image: &docker_image
5+
docker:
6+
- image: thecodingmachine/php:8.0-v4-apache-node14
7+
environment:
8+
PLATFORM_REGION: "uk-1.platform.sh"
9+
PROJECT_ROOT: "/home/docker/project"
10+
PHP_EXTENSION_GD: 1
11+
PHP_EXTENSIONS: "gd"
12+
PHP_INI_MEMORY_LIMIT: -1
13+
PHP_INI_MAX_EXECUTION_TIME: 60
14+
PHP_INI_MAX_INPUT_TIME: 60
15+
custom_npm_docker_image: &custom_npm_docker_image
16+
docker:
17+
- image: circleci/php:8.0-apache-browsers
18+
environment:
19+
PLATFORM_REGION: "uk-1.platform.sh"
20+
PROJECT_ROOT: "/home/circleci/project"
21+
# git variables to avoid empty committer identity errors
22+
EMAIL: "circleci@localhost"
23+
GIT_COMMITTER_NAME: "Circle CI"
24+
GIT_AUTHOR_NAME: "Circle CI"
25+
EDGE_BUILD_BRANCH: "D8UN-edge"
26+
27+
# Re-usable commands.
28+
commands:
29+
checkout_code:
30+
description: "Handle composer access tokens, SSH key fingerprints and code checkout"
31+
steps:
32+
# Add SSH user key so we can access related repositories as part of our initial clone + composer install command.
33+
- add_ssh_keys:
34+
fingerprints:
35+
- "e8:86:75:e8:35:15:07:a6:2d:a0:00:17:69:a1:42:84"
36+
- checkout
37+
composer_tasks:
38+
description: "Validate and install dependencies using composer"
39+
steps:
40+
- run:
41+
name: Validate composer.json and composer.lock file for consistency
42+
command: composer validate --no-check-all --strict
43+
- restore_cache:
44+
keys:
45+
- composer-{{ checksum "composer.lock" }}
46+
- run:
47+
name: Fetch dependencies with composer
48+
command: |
49+
composer install --no-interaction --optimize-autoloader
50+
- save_cache:
51+
key: composer-{{ checksum "composer.lock" }}
52+
paths:
53+
- $HOME/.composer/cache
54+
composer_tasks__no_cache:
55+
description: "Validate and install dependencies using composer"
56+
steps:
57+
- run:
58+
name: Validate composer.json and composer.lock file for consistency
59+
command: composer validate --no-check-all --strict
60+
- run:
61+
name: Fetch dependencies with composer
62+
command: |
63+
composer install --no-interaction --optimize-autoloader
64+
composer_tasks__edge_packages:
65+
description: "Switch dof-dss packages to HEAD on development branch"
66+
steps:
67+
- run:
68+
name: Switch dof-dss packages to HEAD on development branch
69+
command: |
70+
composer require dof-dss/nicsdru_unity_theme:dev-development \
71+
dof-dss/nicsdru_origins_modules:dev-development \
72+
dof-dss/nicsdru_unity_modules:dev-development
73+
install_psh_cli:
74+
description: "Install the Platform.sh CLI tool"
75+
steps:
76+
- run:
77+
name: Install the Platform.sh CLI tool
78+
command: curl -sS https://platform.sh/cli/installer | php
79+
- run:
80+
name: Add platform cli tool to $PATH
81+
command: echo 'export PATH="$HOME/"'.platformsh/bin':"$PATH"' >> $BASH_ENV
82+
hosts_keyscan:
83+
description: "Adds github.com to known hosts in container; for working locally."
84+
steps:
85+
- run:
86+
name: Keyscan for hosts that require SSH access
87+
command: |
88+
mkdir -p ~/.ssh
89+
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
90+
ssh-keyscan -H ssh.$PLATFORM_REGION >> ~/.ssh/known_hosts
91+
jobs:
92+
# Tests the integrity of the build, stores the results in a workspace for re-use in later jobs.
93+
build:
94+
<<: *docker_image
95+
steps:
96+
- checkout_code
97+
- composer_tasks
98+
- persist_to_workspace:
99+
root: ./
100+
paths:
101+
- ./
102+
103+
# Test for coding standards - will inherit the workspace/filesystem changes from build step, above.
104+
coding_standards:
105+
<<: *docker_image
106+
steps:
107+
- attach_workspace:
108+
at: ./
109+
- run:
110+
name: PHPCS analysis
111+
command: |
112+
CHECK_DIRS="${PROJECT_ROOT}/web/sites"
113+
CHECK_DIRS="${CHECK_DIRS} ${PROJECT_ROOT}/web/modules/custom"
114+
CHECK_DIRS="${CHECK_DIRS} ${PROJECT_ROOT}/web/modules/origins"
115+
CHECK_DIRS="${CHECK_DIRS} ${PROJECT_ROOT}/web/themes/custom"
116+
CHECK_DIRS="${CHECK_DIRS} ${PROJECT_ROOT}/web/profiles/unity"
117+
CHECK_DIRS="${CHECK_DIRS} ${PROJECT_ROOT}/web/profiles/origins"
118+
~/project/phpcs.sh ${PROJECT_ROOT} $CHECK_DIRS
119+
120+
# Test for deprecated code - will inherit the workspace/filesystem changes from build step, above.
121+
deprecated_code:
122+
<<: *docker_image
123+
steps:
124+
- attach_workspace:
125+
at: ./
126+
- run:
127+
name: Deprecated code check
128+
command: |
129+
cd $PROJECT_ROOT
130+
CHECK_DIRS="${PROJECT_ROOT}/web/modules/custom"
131+
CHECK_DIRS="$CHECK_DIRS ${PROJECT_ROOT}/web/modules/origins"
132+
vendor/bin/drupal-check $CHECK_DIRS
133+
134+
# Nightly edge build
135+
edge_build:
136+
<<: *custom_npm_docker_image
137+
environment:
138+
# git variables to avoid empty committer identity errors
139+
EMAIL: "circleci@localhost"
140+
GIT_COMMITTER_NAME: "Circle CI"
141+
GIT_AUTHOR_NAME: "Circle CI"
142+
EDGE_BUILD_BRANCH: "edge"
143+
PLATFORM_REGION: "uk-1.platform.sh"
144+
steps:
145+
- hosts_keyscan
146+
- checkout_code
147+
- run:
148+
name: Add OS and PHP extensions
149+
command: |
150+
sudo cp $PROJECT_ROOT/.circleci/docker-php-circleci.ini /usr/local/etc/php/conf.d/
151+
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
152+
sudo apt update --allow-releaseinfo-change
153+
sudo apt install -y libpng-dev
154+
sudo docker-php-ext-install gd pcntl posix
155+
- install_psh_cli
156+
- run:
157+
name: Switch to edge branch
158+
command: git checkout -b $EDGE_BUILD_BRANCH
159+
- composer_tasks__edge_packages
160+
- run:
161+
name: Push composer package updates back to GitHub
162+
command: |
163+
git add composer.*
164+
git commit -m "Set dof-dss packages to HEAD development for build"
165+
- run:
166+
name: Download nvm in order to select legacy node version (using nvm)
167+
command: |
168+
# Need to re-build site theme with any Unity changes.
169+
# Download and configure node and npm.
170+
sudo apt install libjpeg-dev automake python -y
171+
git clone https://github.com/nvm-sh/nvm.git
172+
cd nvm
173+
chmod +x install.sh
174+
./install.sh
175+
- run:
176+
name: Rebuild site themes
177+
command: |
178+
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
179+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
180+
nvm install v15.14.0
181+
for site in `ls -l ~/project/project/sites | grep ^d | awk '{print $9}'`
182+
do
183+
if [[ -d ~/project/project/sites/${site}/themes/${site}_theme ]]; then
184+
echo "*** Building theme for ${site} ***"
185+
cd ~/project/project/sites/${site}/themes/${site}_theme
186+
sed -i -e "s/\"nicsdru_unity_theme.*/\"nicsdru_unity_theme\": \"github:dof-dss\/nicsdru_unity_theme#development\",/" package.json
187+
npm install
188+
npm rebuild node-sass
189+
npm run build
190+
191+
git add *.css
192+
git commit -m "Theme rebuild"
193+
else
194+
echo "No theme folder detected under ~/project/project/sites/${site}/themes/${site}_theme, skipping."
195+
fi
196+
done
197+
198+
# Push to fixed, non-integrating build branch. GitHub webhook integration will propagate this
199+
# to platform.sh for later steps to use.
200+
git push -f origin $EDGE_BUILD_BRANCH
201+
202+
# Separate task to allow us to sync data on PSH environments, without pauses in other jobs.
203+
sync_data:
204+
<<: *docker_image
205+
steps:
206+
- hosts_keyscan
207+
- checkout_code
208+
- install_psh_cli
209+
- run:
210+
name: Trigger a data sync from master environment to nightly edge build.
211+
command: |
212+
platform sync data -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH -y
213+
- run:
214+
name: Backup data sync if the previous attempt failed.
215+
command: |
216+
# Pause for the blocking activity to finish.
217+
sleep 90s
218+
platform sync data -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH -y
219+
when: on_fail
220+
- run:
221+
name: Turn off fastly module to allow for cleaner config import
222+
command: |
223+
for site in `ls -l ~/project/project/sites | grep ^d | awk '!/default/{print $9}'`
224+
do
225+
result=$(platform drush "st -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH | (grep "Drupal bootstrap : Successful" || true) )
226+
if [[ -n $result ]]; then
227+
result2=$(platform drush "pml -l ${site}" -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH | (grep "Fastly (fastly)" || true) )
228+
if [[ -n $result2 ]]; then
229+
echo "***** Uninstall Fastly - ${site} *****"
230+
platform drush "pmu fastly -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
231+
fi
232+
fi
233+
done
234+
- run:
235+
name: Clear cache before config import
236+
command: |
237+
for site in `ls -l ~/project/project/sites | grep ^d | awk '!/default/{print $9}'`
238+
do
239+
result=$(platform drush "st -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH | (grep "Drupal bootstrap : Successful" || true) )
240+
if [[ -n $result ]]; then
241+
echo "***** Clear Cache - ${site} *****"
242+
platform drush "cr -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
243+
fi
244+
done
245+
- run:
246+
name: Refresh configuration as our db will contain active prod config after sync operation
247+
command: |
248+
for site in `ls -l ~/project/project/sites | grep ^d | awk '!/default/{print $9}'`
249+
do
250+
result=$(platform drush "st -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH | (grep "Drupal bootstrap : Successful" || true) )
251+
if [[ -n $result ]]; then
252+
echo "***** Config Import - ${site} *****"
253+
platform drush "cim -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
254+
echo "***** Import blocks/taxonomies/menus - ${site} *****"
255+
platform drush "import-all-if-installed safe -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
256+
echo "***** Enable QA accounts - ${site} *****"
257+
platform drush "bulk_update_qa_accounts enable -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
258+
fi
259+
done
260+
- run:
261+
name: Purge and rebuild Solr indexes
262+
command: |
263+
for site in `ls -l ~/project/project/sites | grep ^d | awk '!/default/{print $9}'`
264+
do
265+
result=$(platform drush "st -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH | (grep "Drupal bootstrap : Successful" || true) )
266+
if [[ -n $result ]]; then
267+
result2=$(platform drush "pml --status=enabled -l ${site}" -y -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH | (grep "solr" || true) )
268+
if [[ -n $result2 ]]; then
269+
echo "***** Purge Solr index for - ${site} *****"
270+
platform ssh -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH \
271+
"curl http://${site}_solr.internal:8080/solr/${site}_index/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8' \
272+
&& curl http://${site}_solr.internal:8080/solr/${site}_index/update --data '<commit/>' -H 'Content-type:text/xml; charset=utf-8'"
273+
echo "***** Rebuild the Solr index for - ${site} *****"
274+
platform drush "sapi-c -l ${site}" -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
275+
platform drush "sapi-r -l ${site}" -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
276+
platform drush "sapi-i -l ${site}" -p $PLATFORM_PROJECT -e $EDGE_BUILD_BRANCH
277+
fi
278+
fi
279+
done
280+
# Checks to ensure that Unity Base has not been polluted with project files.
281+
unity_base_checks:
282+
<<: *docker_image
283+
steps:
284+
- attach_workspace:
285+
at: ./
286+
- when:
287+
condition:
288+
equal: [ "https://github.com/dof-dss/unity_base", << pipeline.project.git_url >> ]
289+
steps:
290+
- run:
291+
name: Check Project directory and files do not exist
292+
command: |
293+
cd $PROJECT_ROOT
294+
.circleci/unity_base_guardian.sh
295+
296+
workflows:
297+
version: 2
298+
build-test-deploy:
299+
jobs:
300+
- build
301+
- unity_base_checks:
302+
requires:
303+
- build
304+
- coding_standards:
305+
requires:
306+
- build
307+
- deprecated_code:
308+
requires:
309+
- build
310+
311+
# A nightly build of the project, using all dof-dss packages at HEAD from development branch.
312+
nightly-edge-build:
313+
when:
314+
and:
315+
- not:
316+
equal: [ "https://github.com/dof-dss/unity_base", << pipeline.project.git_url >> ]
317+
triggers:
318+
- schedule:
319+
# At 00:30 Monday to Friday
320+
cron: "30 0 * * 1-5"
321+
filters:
322+
branches:
323+
only:
324+
- development
325+
jobs:
326+
- edge_build
327+
328+
# A nightly deploy or re-deploy of the edge site after the git branch has been created in nightly-edge-build.
329+
nightly-edge-build-post-build-tasks:
330+
when:
331+
and:
332+
- not:
333+
equal: [ "https://github.com/dof-dss/unity_base", << pipeline.project.git_url >> ]
334+
triggers:
335+
- schedule:
336+
# At 01:23 Monday to Friday
337+
cron: "23 1 * * 1-5"
338+
filters:
339+
branches:
340+
only:
341+
- edge
342+
jobs:
343+
- sync_data

0 commit comments

Comments
 (0)