File tree Expand file tree Collapse file tree 4 files changed +167
-0
lines changed
Expand file tree Collapse file tree 4 files changed +167
-0
lines changed Original file line number Diff line number Diff line change 1+ # Example of .gitlab-ci.yml jobs
2+ # Use with config_split.mk and config_split_disable_all.sh
3+
4+ # # Overhead config
5+
6+ stages :
7+ - deploy
8+
9+ # Tags defines which runner to use (expected shell runner)
10+ .ra_tags : &ra_tags
11+ tags :
12+ - XXX # Mandatory, should equal to tag of available runner server with docker + docker-compose + traefik
13+
14+ .ra_only : &ra_only
15+ only :
16+ - branches
17+
18+ # # Multisite config
19+
20+ Enable split default :
21+ stage : deploy
22+ environment :
23+ url : https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
24+ name : review/$CI_COMMIT_REF_NAME
25+ on_stop : stop_review
26+ script :
27+ - echo "Starting job script in ${BUILD_DIR}"
28+ - cd ${BUILD_DIR}
29+ - pwd
30+ - make split default
31+ when : manual
32+ << : *ra_tags
33+ << : *ra_only
34+
35+ Enable split first :
36+ stage : deploy
37+ environment :
38+ url : https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
39+ name : review/$CI_COMMIT_REF_NAME
40+ on_stop : stop_review
41+ script :
42+ - echo "Starting job script in ${BUILD_DIR}"
43+ - cd ${BUILD_DIR}
44+ - pwd
45+ - make split first # Vary for each site
46+ when : manual
47+ << : *ra_tags
48+ << : *ra_only
49+
50+ Enable split second : # Job can then be duplicated to navigate between to multiple set of config (just use a different make split command for each)
51+ ...
52+
Original file line number Diff line number Diff line change 1+ # Multisite script
2+
3+ ## What
4+
5+ - These are scripts and commands to facilitate the use of different set of config in a multisite setup
6+ - It can be used locally using make commands as well as in Gitalb CI/CD pipelines using manual jobs
7+
8+ ## Why
9+
10+ - Being able to quickly switch from one set of config to another is very much useful for testing on a multisite Drupal setup
11+
12+ ## Setup
13+
14+ 3 files are required :
15+ - ` .gitlab-ci.yml `
16+ - ` config_split.mk `
17+ - ` config_split_disable_all.sh `
18+
19+ 1 . Install and enable config_split module :
20+ - ` composer require drupal/config_split `
21+ - ` drush en -y config_split `
22+ 1 . In Drupal UI, create split(s) for site where config vary
23+ - Do not create a split for "default" case, in which all shared config should be stored
24+ 1 . Create the config directories required by created splits
25+ 1 . Define a CI job "Enable split default" in .gitlab-ci.yml, as shown in .gitlab-ci.mirroring_example.yml
26+ 1 . Define additional CI jobs like "Enable split first" in .gitlab-ci.yml for each split
27+ 1 . Move files to scripts/makefile/ directory :
28+ - ` mv scripts/multisite/config_split.mk scripts/makefile/ `
29+ - ` mv scripts/multisite/config_split_disable_all.sh scripts/makefile/ `
30+
31+ ## Usage
32+
33+ Locally you can use commands like :
34+ - ` make split first ` to simulate site "first" of multisite
35+ - ` make split default ` to revert back to no split
36+
37+ On Gitlab CI/CD, Review Apps will be builded using default split :
38+ - Manually click on manual jobs "Enable split first" to simulate site "first" of multisite
39+ - Manually click on manual job "Enable split default" to revert back to no split
40+
Original file line number Diff line number Diff line change 1+
2+ .PHONY : split
3+
4+ # If the first argument is "split"
5+ ifeq (split,$(firstword $(MAKECMDGOALS ) ) )
6+ # Then use next strings as arguments
7+ ARGS := $(wordlist 2,$(words $(MAKECMDGOALS ) ) ,$(MAKECMDGOALS ) )
8+ endif
9+
10+ # # Enable a specific split of config (config_split)
11+ split :
12+ $($@ ,$(MAKECMDGOALS ) )
13+
14+ # Message if no argument passed
15+ ifeq ($(ARGS ) ,)
16+ @echo "\nMachine name of split to enable is expected as argument \nFor exemple : \n - make split first // To enable first split\nor\n - make split default // To enable default config with no split\n"
17+ @exit 1
18+ else
19+ @echo "YAY $(ARGS)"
20+
21+ # Disabling all active splits
22+ @echo "Disabling all active splits:"
23+ ifneq ("$(wildcard scripts/makefile/config_split_disable_all.sh) ","")
24+ @echo "- Script found : Executing..."
25+ @$(call php, /bin/sh ./scripts/makefile/config_split_disable_all.sh)
26+ else
27+ @echo "- scripts/makefile/config_split_disable_all.sh file does not exist"
28+ @exit 1
29+ endif
30+
31+ # Enabling selected split
32+ @echo "Enabling selected split : $(ARGS) ..."
33+ ifeq ($(ARGS ) ,default)
34+ @echo "No specific split to enable for $(ARGS) config..."
35+ else
36+ @$(call php, drush config-set config_split.config_split.$(ARGS) status 1 -y)
37+ endif
38+
39+ # Executing the rest of deploy commands
40+ @echo "Importing $(ARGS) config..."
41+ @$(call php, drush cim -y)
42+ @make localize
43+ @echo "Clearing cache..."
44+ @$(call php, drush cr)
45+ @make info
46+
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env sh
2+
3+ # Parsing command
4+ PARSING_CMD=' echo drush config:status --state=Any --format=list'
5+
6+ # Entity to parse (see PARSING_CMD for more)
7+ CONFIG_TO_PARSE=config_split.config_split
8+
9+ # Count entities
10+ CONFIG_COUNT=$( $( $PARSING_CMD ) | grep -c $CONFIG_TO_PARSE )
11+
12+ # List entities
13+ CONFIG_LIST=$( $( $PARSING_CMD ) | grep $CONFIG_TO_PARSE | awk -F " ." ' {print $3}' )
14+
15+
16+ # Looking for splits
17+ echo -e " - Looking for splits of config..."
18+
19+ if [ " $CONFIG_COUNT " -gt " 0" ]; then
20+
21+ echo -e " - Some splits were found : Disabling all splits..."
22+
23+ for bundles in $CONFIG_LIST ; do
24+ drush config-set config_split.config_split.$bundles status 0 -y
25+ done
26+
27+ else
28+ printf " - \033[1mNo split of config was\033[0m found\n"
29+ fi
You can’t perform that action at this time.
0 commit comments