Skip to content

Commit

Permalink
Update Drupal syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
back-2-95 committed Sep 6, 2024
1 parent 0b27f31 commit bc9e786
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
9 changes: 9 additions & 0 deletions make/drupal.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DRUSH_RSYNC_MODE ?= Pakzu
DRUSH_RSYNC_OPTS ?= -- --omit-dir-times --no-perms --no-group --no-owner --chmod=ugo=rwX
DRUSH_RSYNC_EXCLUDE ?= css:ctools:js:php:tmp:tmp_php
SYNC_TARGETS += drush-sync
SYNC_FROM_REMOTE ?= no
CS_EXTS := inc,php,module,install,profile,theme
CS_STANDARD_PATHS := vendor/drupal/coder/coder_sniffer,vendor/slevomat/coding-standard
CS_STANDARDS := Drupal,DrupalPractice
Expand All @@ -27,6 +28,10 @@ FIX_TARGETS += fix-drupal
DRUPAL_CREATE_FOLDERS := $(WEBROOT)/sites/default/files/private
DRUPAL_CREATE_FOLDERS += $(WEBROOT)/sites/default/files/translations

ifeq ($(LAGOON),yes)
SYNC_FROM_REMOTE := yes
endif

ifeq ($(GH_DUMP_ARTIFACT),yes)
DRUPAL_FRESH_TARGETS := gh-download-dump $(DRUPAL_FRESH_TARGETS)
endif
Expand Down Expand Up @@ -148,16 +153,20 @@ ifeq ($(DUMP_SQL_EXISTS),yes)
$(call step,Import local SQL dump...)
$(call drush,sql-query --file=${DOCKER_PROJECT_ROOT}/$(DUMP_SQL_FILENAME) && echo 'SQL dump imported')
else
ifeq ($(SYNC_FROM_REMOTE),yes)
$(call step,Sync database from @$(DRUPAL_SYNC_SOURCE)...)
$(call drush,sql-sync -y --structure-tables-key=common @$(DRUPAL_SYNC_SOURCE) @self)
endif
endif

PHONY += drush-sync-files
drush-sync-files: ## Sync files
ifeq ($(DRUPAL_SYNC_FILES),yes)
ifeq ($(SYNC_FROM_REMOTE),yes)
$(call step,Sync files from @$(DRUPAL_SYNC_SOURCE)...)
$(call drush,-y rsync --exclude-paths=$(DRUSH_RSYNC_EXCLUDE) --mode=$(DRUSH_RSYNC_MODE) @$(DRUPAL_SYNC_SOURCE):%files @self:%files $(DRUSH_RSYNC_OPTS))
endif
endif

PHONY += drush-create-dump
drush-create-dump: FLAGS := --structure-tables-key=common --extra-dump=--no-tablespaces
Expand Down
2 changes: 1 addition & 1 deletion make/utils.mk
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ define remove_string
endef

define run
@${1} && printf "${2}\n" || printf "${RED}${3}${NO_COLOR}\n"
@${1} && printf "${2}\n" || (printf "${RED}${3}${NO_COLOR}\n" && exit 1)
endef
2 changes: 0 additions & 2 deletions tests/outputs/drush-sync-local-dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ drush-sync IS_DRUPAL=yes DUMP_SQL_EXISTS=yes RUN_ON=docker
docker compose exec app sh -c "drush sql-drop --quiet -y"
printf "\n⭐ \033[0;33mImport local SQL dump...\033[0m\n"
docker compose exec app sh -c "drush sql-query --file=/app/dump.sql && echo 'SQL dump imported'"
printf "\n⭐ \033[0;33mSync files from @main...\033[0m\n"
docker compose exec app sh -c "drush -y rsync --exclude-paths=css:ctools:js:php:tmp:tmp_php --mode=Pakzu @main:%files @self:%files -- --omit-dir-times --no-perms --no-group --no-owner --chmod=ugo=rwX"
6 changes: 3 additions & 3 deletions tests/outputs/drush-sync-nofiles.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
drush-sync IS_DRUPAL=yes DRUPAL_SYNC_FILES=no
drush-sync IS_DRUPAL=yes DRUPAL_SYNC_FILES=no DUMP_SQL_EXISTS=yes
---
drush sql-drop --quiet -y
printf "\n⭐ \033[0;33mSync database from @main...\033[0m\n"
drush sql-sync -y --structure-tables-key=common @main @self
printf "\n⭐ \033[0;33mImport local SQL dump...\033[0m\n"
drush sql-query --file=/app/dump.sql && echo 'SQL dump imported'
8 changes: 3 additions & 5 deletions tests/outputs/drush-sync.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
drush-sync IS_DRUPAL=yes
drush-sync IS_DRUPAL=yes SYNC_TARGETS=yes DUMP_SQL_EXISTS=yes
---
drush sql-drop --quiet -y
printf "\n⭐ \033[0;33mSync database from @main...\033[0m\n"
drush sql-sync -y --structure-tables-key=common @main @self
printf "\n⭐ \033[0;33mSync files from @main...\033[0m\n"
drush -y rsync --exclude-paths=css:ctools:js:php:tmp:tmp_php --mode=Pakzu @main:%files @self:%files -- --omit-dir-times --no-perms --no-group --no-owner --chmod=ugo=rwX
printf "\n⭐ \033[0;33mImport local SQL dump...\033[0m\n"
drush sql-query --file=/app/dump.sql && echo 'SQL dump imported'
2 changes: 1 addition & 1 deletion tests/outputs/gh-download-dump-custom.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gh-download-dump DUMP_SQL_EXISTS=yes GH_DUMP_ARTIFACT=yes DUMP_SQL_EXISTS=no
---
printf "\n⭐ \033[0;33mDownload database dump from repository artifacts\n\033[0m\n"
gh run download -n latest-dump && printf "Downloaded dump.sql\n" || printf "\033[0;31mFailed\033[0m\n"
gh run download -n latest-dump && printf "Downloaded dump.sql\n" || (printf "\033[0;31mFailed\033[0m\n" && exit 1)
2 changes: 1 addition & 1 deletion tests/outputs/gh-download-dump.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gh-download-dump DUMP_SQL_EXISTS=yes GH_DUMP_ARTIFACT=yes DUMP_SQL_EXISTS=no GH_ARTIFACT=foobar GH_REPO=foobar/barfur
---
printf "\n⭐ \033[0;33mDownload database dump from repository artifacts\n\033[0m\n"
gh run download -n foobar -R foobar/barfur && printf "Downloaded dump.sql\n" || printf "\033[0;31mFailed\033[0m\n"
gh run download -n foobar -R foobar/barfur && printf "Downloaded dump.sql\n" || (printf "\033[0;31mFailed\033[0m\n" && exit 1)

0 comments on commit bc9e786

Please sign in to comment.