Skip to content

Commit

Permalink
Rellocation of tests makefile targets and housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
David Ferlay committed Jul 26, 2019
1 parent 2a9708c commit 893b903
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .env.default
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
COMPOSE_FILE=./docker/docker-compose.yml:./docker/docker-compose.override.yml
COMPOSE_PROJECT_NAME=projectname
PROFILE_NAME=sdd
MODULES=skilld_default_content
MODULES=project_default_content
THEME_NAME=
SITE_NAME=Example
[email protected]
Expand Down
144 changes: 9 additions & 135 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ include scripts/makefile/*.mk
%:
@:

# Prepare enviroment variables from defaults.
# Prepare enviroment variables from defaults
$(shell false | cp -i \.env.default \.env 2>/dev/null)
$(shell false | cp -i \.\/docker\/docker-compose\.override\.yml\.default \.\/docker\/docker-compose\.override\.yml 2>/dev/null)
include .env

# Get user/group id to manage permissions between host and containers.
# Get user/group id to manage permissions between host and containers
LOCAL_UID := $(shell id -u)
LOCAL_GID := $(shell id -g)

# Evaluate recursively.
# Evaluate recursively
CUID ?= $(LOCAL_UID)
CGID ?= $(LOCAL_GID)

Expand All @@ -26,28 +26,17 @@ COMPOSE_NET_NAME := $(COMPOSE_PROJECT_NAME)_front
# Define mysql storage folder.
MYSQL_DATADIR := $(DB_DATA_DIR)/$(COMPOSE_PROJECT_NAME)_mysql

# Execute php container as regular user.
# Execute php container as regular user
php = docker-compose exec -T --user $(CUID):$(CGID) php ${1}
# Execute php container as root user.
# Execute php container as root user
php-0 = docker-compose exec -T php ${1}
# Function for code sniffer images.
phpcsexec = docker run --rm \
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
-v $(shell pwd)/web/modules/custom:/work/modules \
-v $(shell pwd)/web/themes/custom:/work/themes \
skilldlabs/docker-phpcs-drupal ${1} -s --colors \
--standard=Drupal,DrupalPractice \
--extensions=php,module,inc,install,profile,theme,yml,txt,md,js \
--ignore=*.css,libraries/*,dist/*,styleguide/*,README.md,README.txt \
.


## Full site install from the scratch
all: | provision composer si hooksymlink info

## Provision enviroment
provision:
# Check if enviroment variables has been defined.
# Check if enviroment variables has been defined
ifeq ($(strip $(COMPOSE_PROJECT_NAME)),projectname)
$(info Project name can not be default, please enter project name.)
$(eval COMPOSE_PROJECT_NAME = $(strip $(shell read -p "Project name: " REPLY;echo -n $$REPLY)))
Expand Down Expand Up @@ -82,7 +71,7 @@ endif
# Uncomment this string to build front separately. See scripts/makefile/front.mk
# make -s front

## Install drupal.
## Install drupal
si:
@echo "Installing from: $(PROJECT_INSTALL)"
ifeq ($(PROJECT_INSTALL), config)
Expand All @@ -95,7 +84,7 @@ ifneq ($(strip $(MODULES)),)
$(call php, drush pmu $(MODULES) -y)
endif

## Project's containers information
## Display project's information
info:
$(info Containers for "$(COMPOSE_PROJECT_NAME)" info:)
$(eval CONTAINERS = $(shell docker ps -f name=$(COMPOSE_PROJECT_NAME) --format "{{ .ID }}" -f 'label=traefik.enable=true'))
Expand Down Expand Up @@ -133,7 +122,7 @@ ifeq ($(shell docker-compose config --services | grep mysql),mysql)
@if [ -d $(MYSQL_DATADIR) ]; then echo "Removing mysql data $(MYSQL_DATADIR) ..."; docker run --rm -v $(shell pwd):/mnt/2rm $(IMAGE_PHP) sh -c "rm -rf /mnt/2rm/$(DB_DATA_DIR)"; fi
endif

## Enable development mode and disable caching.
## Enable development mode and disable caching
dev:
@echo "Dev tasks..."
$(call php, composer install --prefer-dist -o)
Expand All @@ -156,118 +145,3 @@ drush:
$(call php, $(filter-out "$@",$(MAKECMDGOALS)))
$(info "To pass arguments use double dash: "make drush dl devel -- -y"")

## Check codebase with phpcs sniffers to make sure it conforms https://www.drupal.org/docs/develop/standards
phpcs:
@echo "Phpcs validation..."
@$(call phpcsexec, phpcs)

## Fix codebase according to Drupal standards https://www.drupal.org/docs/develop/standards
phpcbf:
@$(call phpcsexec, phpcbf)

## Add symbolic link from custom script(s) to .git/hooks/
hooksymlink:
# Check if .git directory exists
ifneq ($(wildcard .git/.*),)
# Check if script file exists
ifneq ("$(wildcard scripts/git_hooks/sniffers.sh)","")
@echo "Removing previous git hooks and installing fresh ones"
$(shell find .git/hooks -type l -exec unlink {} \;)
$(shell ln -sf ../../scripts/git_hooks/sniffers.sh .git/hooks/pre-push)
else
@echo "scripts/git_hooks/sniffers.sh file does not exist"
endif
else
@echo "No git directory found, git hooks won't be installed"
endif


## Validate langcode of base config files
clang:
ifneq ("$(wildcard scripts/makefile/baseconfig-langcode.sh)","")
@echo "Base config langcode validation..."
@/bin/sh ./scripts/makefile/baseconfig-langcode.sh
else
@echo "scripts/makefile/baseconfig-langcode.sh file does not exist"
endif


## Validate configuration schema
cinsp:
ifneq ("$(wildcard scripts/makefile/config-inspector-validation.sh)","")
@echo "Config schema validation..."
$(call php, composer install -o)
@$(call php, /bin/sh ./scripts/makefile/config-inspector-validation.sh)
else
@echo "scripts/makefile/config-inspector-validation.sh file does not exist"
endif


## Validate composer.json file
compval:
@echo "Composer.json validation..."
@docker run --rm -v `pwd`:`pwd` -w `pwd` $(IMAGE_PHP) composer validate --strict


## Validate watchdog logs
watchdogval:
ifneq ("$(wildcard scripts/makefile/watchdog-validation.sh)","")
@echo "Watchdog validation..."
@$(call php, /bin/sh ./scripts/makefile/watchdog-validation.sh)
else
@echo "scripts/makefile/watchdog-validation.sh file does not exist"
endif


## Validate drupal-check
drupalcheckval:
@echo "Drupal-check validation..."
$(call php, composer install -o)
$(call php, vendor/bin/drupal-check -V)
$(call php, vendor/bin/drupal-check -ad -vv -n --no-progress web/modules/custom/)

## Behat scenarios validation
behat:
@echo "Getting base url"
ifdef REVIEW_DOMAIN
$(eval BASE_URL := $(MAIN_DOMAIN_NAME))
else
$(eval BASE_URL := $(shell docker inspect --format="{{.NetworkSettings.Networks.$(COMPOSE_NET_NAME).IPAddress}}" $(COMPOSE_PROJECT_NAME)_web))
endif
ifeq ($(shell docker ps -f 'name=$(COMPOSE_PROJECT_NAME)_chrome' --format '{{.Names}}'), )
@echo 'Browser driver is stoped. Running it.'
make -s browser_driver
endif
@echo "Replacing URL_TO_TEST value in behat.yml with http://$(BASE_URL)"
$(call php, cp behat.default.yml behat.yml)
$(call php, sed -i "s/URL_TO_TEST/http:\/\/$(BASE_URL)/" behat.yml)
@echo "Running Behat scenarios against http://$(BASE_URL)"
$(call php, composer install -o)
$(call php, vendor/bin/behat -V)
$(call php, vendor/bin/behat --colors)

behatdl:
$(call php, vendor/bin/behat -dl --colors)

behatdi:
$(call php, vendor/bin/behat -di --colors)

## Running browser driver for behat tests
browser_driver:
docker run -d --init --rm --name $(COMPOSE_PROJECT_NAME)_chrome \
--network container:$(COMPOSE_PROJECT_NAME)_php $(IMAGE_DRIVER) \
--remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --no-sandbox \
--entrypoint "" chromium-browser --headless --disable-gpu \
--window-size=1200,2080 \
--disable-web-security

## Stopping browser driver
browser_driver_stop:
docker stop $(COMPOSE_PROJECT_NAME)_chrome

## Run sniffer validations (executed as git hook, by scripts/git_hooks/sniffers.sh)
sniffers: | clang compval phpcs

## Run all tests & validations (including sniffers)
tests: | sniffers behat cinsp drupalcheckval watchdogval

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
| COMPOSE_FILE | Path to a Compose file(s) | `./docker/docker-compose.yml:./docker/docker-compose.override.yml` |
| COMPOSE_PROJECT_NAME | Your project name | - |
| PROFILE_NAME | Profile used for site install | sdd |
| MODULES | Additional modules to enable after site install | skilld_default_content |
| MODULES | Additional modules to enable after site install | project_default_content |
| THEME_NAME | Theme name used for frontend | - |
| SITE_NAME | Site name | Example |
| SITE_MAIL | Site e-mail address | [email protected] |
Expand Down
4 changes: 2 additions & 2 deletions scripts/makefile/front.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Execute front container function.
# Execute front container function
front = docker run --rm -u $(CUID):$(CGID) -v $(shell pwd)/web/themes/custom/$(THEME_NAME):/work $(IMAGE_FRONT) ${1}

## Build front tasks.
## Build front tasks
front:
@echo "Building front tasks..."
docker pull $(IMAGE_FRONT)
Expand Down
126 changes: 126 additions & 0 deletions scripts/makefile/tests.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Function for code sniffer images.
phpcsexec = docker run --rm \
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
-v $(shell pwd)/web/modules/custom:/work/modules \
-v $(shell pwd)/web/themes/custom:/work/themes \
skilldlabs/docker-phpcs-drupal ${1} -s --colors \
--standard=Drupal,DrupalPractice \
--extensions=php,module,inc,install,profile,theme,yml,txt,md,js \
--ignore=*.css,libraries/*,dist/*,styleguide/*,README.md,README.txt \
.

## Validate codebase with phpcs sniffers to make sure it conforms https://www.drupal.org/docs/develop/standards
phpcs:
@echo "Phpcs validation..."
@$(call phpcsexec, phpcs)

## Fix codebase according to Drupal standards https://www.drupal.org/docs/develop/standards
phpcbf:
@$(call phpcsexec, phpcbf)


## Add symbolic link from custom script(s) to .git/hooks/
hooksymlink:
# Check if .git directory exists
ifneq ($(wildcard .git/.*),)
# Check if script file exists
ifneq ("$(wildcard scripts/git_hooks/sniffers.sh)","")
@echo "Removing previous git hooks and installing fresh ones"
$(shell find .git/hooks -type l -exec unlink {} \;)
$(shell ln -sf ../../scripts/git_hooks/sniffers.sh .git/hooks/pre-push)
else
@echo "scripts/git_hooks/sniffers.sh file does not exist"
endif
else
@echo "No git directory found, git hooks won't be installed"
endif


## Validate langcode of base config files
clang:
ifneq ("$(wildcard scripts/makefile/baseconfig-langcode.sh)","")
@echo "Base config langcode validation..."
@/bin/sh ./scripts/makefile/baseconfig-langcode.sh
else
@echo "scripts/makefile/baseconfig-langcode.sh file does not exist"
endif


## Validate configuration schema
cinsp:
ifneq ("$(wildcard scripts/makefile/config-inspector-validation.sh)","")
@echo "Config schema validation..."
$(call php, composer install -o)
@$(call php, /bin/sh ./scripts/makefile/config-inspector-validation.sh)
else
@echo "scripts/makefile/config-inspector-validation.sh file does not exist"
endif


## Validate composer.json file
compval:
@echo "Composer.json validation..."
@docker run --rm -v `pwd`:`pwd` -w `pwd` $(IMAGE_PHP) composer validate --strict


## Validate watchdog logs
watchdogval:
ifneq ("$(wildcard scripts/makefile/watchdog-validation.sh)","")
@echo "Watchdog validation..."
@$(call php, /bin/sh ./scripts/makefile/watchdog-validation.sh)
else
@echo "scripts/makefile/watchdog-validation.sh file does not exist"
endif


## Validate drupal-check
drupalcheckval:
@echo "Drupal-check validation..."
$(call php, composer install -o)
$(call php, vendor/bin/drupal-check -V)
$(call php, vendor/bin/drupal-check -ad -vv -n --no-progress web/modules/custom/)

## Validate Behat scenarios
behat:
@echo "Getting base url"
ifdef REVIEW_DOMAIN
$(eval BASE_URL := $(MAIN_DOMAIN_NAME))
else
$(eval BASE_URL := $(shell docker inspect --format="{{.NetworkSettings.Networks.$(COMPOSE_NET_NAME).IPAddress}}" $(COMPOSE_PROJECT_NAME)_web))
endif
ifeq ($(shell docker ps -f 'name=$(COMPOSE_PROJECT_NAME)_chrome' --format '{{.Names}}'), )
@echo 'Browser driver is stoped. Running it.'
make -s browser_driver
endif
@echo "Replacing URL_TO_TEST value in behat.yml with http://$(BASE_URL)"
$(call php, cp behat.default.yml behat.yml)
$(call php, sed -i "s/URL_TO_TEST/http:\/\/$(BASE_URL)/" behat.yml)
@echo "Running Behat scenarios against http://$(BASE_URL)"
$(call php, composer install -o)
$(call php, vendor/bin/behat -V)
$(call php, vendor/bin/behat --colors)

behatdl:
$(call php, vendor/bin/behat -dl --colors)

behatdi:
$(call php, vendor/bin/behat -di --colors)

## Run browser driver for behat tests
browser_driver:
docker run -d --init --rm --name $(COMPOSE_PROJECT_NAME)_chrome \
--network container:$(COMPOSE_PROJECT_NAME)_php $(IMAGE_DRIVER) \
--remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --no-sandbox \
--entrypoint "" chromium-browser --headless --disable-gpu \
--window-size=1200,2080 \
--disable-web-security

## Stop browser driver
browser_driver_stop:
docker stop $(COMPOSE_PROJECT_NAME)_chrome

## Run sniffer validations (executed as git hook, by scripts/git_hooks/sniffers.sh)
sniffers: | clang compval phpcs

## Run all tests & validations (including sniffers)
tests: | sniffers behat cinsp drupalcheckval watchdogval
27 changes: 27 additions & 0 deletions web/modules/custom/project_default_content/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Skilld default content

## How to use ?

1. Enable module default_content. It should be already installed by composer.
2. Create content manually on site using UID1 admin user
3. Use `drush dcer` commands (brought by module) to export selected content :
```
drush dcer node <node id> --folder=modules/custom/project_default_content/content
drush dcer user <user id> --folder=modules/custom/project_default_content/content
drush dcer block_content <content id> --folder=modules/custom/project_default_content/content
drush dcer menu_link_content <link id> --folder=modules/custom/project_default_content/content
drush dcer taxonomy_term <term id> --folder=modules/custom/project_default_content/content
drush dcer file <file id> --folder=modules/custom/project_default_content/content
drush dcer media <media id> --folder=modules/custom/project_default_content/content
```
4. Find out what is UUID of admin user : `ls web/modules/custom/project_default_content/content/user`
- `4bad48eb-ff5b-45b4-b30c-ecabff09591a` : UUID of default_content_author user
- Another UUID should be listed here : UUID of admin user
5. Delete json file of admin user :
- `rm web/modules/custom/project_default_content/content/user/UUID_OF_ADMIN_USER.json`
6. Use _sed_ commands to replace UID and UUID values of admin author in files of all exported content :
- `cd web/modules/custom/project_default_content/content/`
- `find . -type f -exec sed -i 's/\/user\\\/1/\/user\\\/2/g' {} +`
- `find . -type f -exec sed -i 's/UUID_OF_ADMIN_USER/4bad48eb-ff5b-45b4-b30c-ecabff09591a' {} +`
7. Exported default content will be created at build and it's author should be `default_content_author`

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
],
"mail": [
{
"value": "[email protected]"
"value": ""
}
],
"timezone": [
Expand Down Expand Up @@ -80,7 +80,7 @@
],
"init": [
{
"value": "[email protected]"
"value": ""
}
],
"default_langcode": [
Expand Down
Loading

0 comments on commit 893b903

Please sign in to comment.