From 5525d103ffa9d9fae437cc94b0781b2213c5601f Mon Sep 17 00:00:00 2001 From: iberdinsky-skilld Date: Mon, 8 Jul 2019 16:13:19 +0600 Subject: [PATCH] rework of front processes. --- .env.default | 2 +- .gitlab-ci.yml | 47 ++++++++++++++++++++++++++++++++++++-- Makefile | 12 +++++----- README.md | 48 +++++++++++++++++++++------------------ scripts/makefile/front.mk | 43 +++++++++++++++++++++++++++-------- 5 files changed, 112 insertions(+), 40 deletions(-) diff --git a/.env.default b/.env.default index b2c775d5f..6cbc23743 100644 --- a/.env.default +++ b/.env.default @@ -8,7 +8,7 @@ SITE_MAIL=admin@example.com PROJECT_INSTALL= IMAGE_PHP=skilldlabs/php:72-fpm IMAGE_NGINX=skilldlabs/nginx:1.14.1 -IMAGE_FRONT=skilldlabs/frontend:zen +IMAGE_FRONT=node:lts-alpine IMAGE_DRIVER=zenika/alpine-chrome MAIN_DOMAIN_NAME=docker.localhost DB_URL=sqlite:///dev/shm/d8.sqlite diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e4bceaef..e3628c420 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,7 @@ image: skilldlabs/php:72 variables: GIT_DEPTH: "3" + THEME_PATH: "web/themes/custom/test_project" before_script: - date @@ -9,6 +10,7 @@ before_script: stages: - sniffers + - prepare - deploy - tests - logs @@ -25,6 +27,23 @@ sniffers:compose: - composer -vvv -V - time composer validate --profile --strict +sniffers:front: + cache: + key: "front-packages" + paths: + - ${THEME_PATH}/node_modules/ + stage: sniffers + image: node:lts-alpine + before_script: + - date + - pwd + - node -v + - yarn -v + script: + - cd ${THEME_PATH} + - yarn install --no-optional --prod + - yarn run lint + sniffers:phpcs: stage: sniffers image: skilldlabs/docker-phpcs-drupal @@ -32,7 +51,7 @@ sniffers:phpcs: - phpcs -s --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,profile,theme,yml,txt,md,js - --ignore=*.css,libraries/* + --ignore=*.css,libraries/*,web/themes/custom/**/*.js web/profiles web/modules/custom web/themes/custom @@ -53,6 +72,27 @@ sniffers:sonarqube: - master allow_failure: true +prepare:nodejs: + cache: + key: "front-packages" + paths: + - ${THEME_PATH}/node_modules/ + stage: prepare + image: node:lts-alpine + before_script: + - date + - pwd + - node -v + - yarn -v + script: + - cd ${THEME_PATH} + - yarn install --no-optional --prod + - yarn run build --verbose + artifacts: + name: "$CI_COMMIT_REF_NAME" + paths: + - ${THEME_PATH}/dist/ + .job_deploy_commit_template: &job_deploy_commit stage: deploy before_script: @@ -86,13 +126,16 @@ deploy:review: - echo "INSTALL_DEV_DEPENDENCIES=TRUE" >> .env.default - docker --version - docker-compose --version - - make all + - make all_ci after_script: - echo "Started ${CI_ENVIRONMENT_URL} composition in ${BUILD_DIR} from Makefile." environment: url: http://${CI_ENVIRONMENT_SLUG}.${REVIEW_DOMAIN} name: review/$CI_COMMIT_REF_NAME on_stop: stop_review + dependencies: + - prepare:nodejs + stop_review: <<: *job_deploy_commit diff --git a/Makefile b/Makefile index d382a430f..89549a5cf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,3 @@ -# Add utility functions and scripts to the container -include scripts/makefile/*.mk - .PHONY: all provision si exec exec0 down clean dev drush info phpcs phpcbf hooksymlink clang cinsp compval watchdogval drupalcheckval behat sniffers tests front behatdl behatdi browser_driver browser_driver_stop .DEFAULT_GOAL := help @@ -13,6 +10,9 @@ $(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 +# Add utility functions and scripts to the container +include scripts/makefile/*.mk + # Get user/group id to manage permissions between host and containers. LOCAL_UID := $(shell id -u) LOCAL_GID := $(shell id -g) @@ -43,7 +43,9 @@ phpcsexec = docker run --rm \ ## Full site install from the scratch -all: | provision composer si hooksymlink info +all: | provision composer front si info +## Full site install from the scratch without front task(it managed in .gitlab-ci). +all_ci: | provision composer si info ## Provision enviroment provision: @@ -79,8 +81,6 @@ else endif $(call php, composer drupal-scaffold) $(call php, composer create-required-files) -# Uncomment this string to build front separately. See scripts/makefile/front.mk -# make -s front ## Install drupal. si: diff --git a/README.md b/README.md index 9e6b48309..b55638d2c 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,21 @@ --- -* [Overview](#overview) -* [What is this?](#what-is-this) -* [What is this not?](#what-is-this-not) -* [Quickstart](#quickstart) - + [Used variables](#used-variables) - + [Persistent Mysql](#persistent-mysql) - + [Network](#network) -* [Usage](#usage) - + [Additional goals](#additional-goals) -* [Support](#support) -* [Drush commands](#drush-commands) -* [Troubleshooting](#troubleshooting) -* [License](#license) +- [Skilld docker container](#Skilld-docker-container) + - [Overview](#Overview) + - [What is this?](#What-is-this) + - [What is this not?](#What-is-this-not) + - [Quickstart](#Quickstart) + - [Used variables](#Used-variables) + - [Persistent Mysql](#Persistent-Mysql) + - [Network](#Network) + - [Usage](#Usage) + - [Additional goals](#Additional-goals) + - [Support](#Support) + - [Drush commands](#Drush-commands) + - [Troubleshooting](#Troubleshooting) + - [Git hooks](#Git-hooks) + - [License](#License) ## Overview @@ -40,8 +42,9 @@ * Copy **.env.default** to **.env**, more information about enviroment file can be found docs.docker.com * Copy **docker-compose.override.yml.default** to **docker-compose.override.yml**, update parts you want to overwrite. * **docker-compose.yml** contains the base requirements of a working Drupal site. It should not be updated. +* Update **.gitlab-ci.yml** `variables` section THEME_PATH to make front gitlab CI works. * Run `make all` - + #### Used variables @@ -61,23 +64,23 @@ | MAIN_DOMAIN_NAME | Domain name used for traefik | `docker.localhost` | | DB_URL | Url to connect to database | `sqlite:///dev/shm/d8.sqlite` | | DB_DATA_DIR | Full path to database storage | `/dev/shm` | - +| CLEAR_FRONT_PACKAGES | Set it to `no` to keep `/node_nodules` directory in theme after `make front` task to save build time. | yes | #### Persistent Mysql * By default sqlite storage used, which is created inside php container, if you need persistent data to be saved: - * Update `docker-compose.override.yml`, set + * Update `docker-compose.override.yml`, set ```yaml php: depends_on: - mysql - ``` - and update mysql container part + ``` + and update mysql container part ```yaml mysql: image: percona:5.7.22 ... - ``` + ``` * Update `.env` file, and set `DB_URL=mysql://d8:d8@mysql/d8` #### Network @@ -103,11 +106,12 @@ networks: * `make exec` - `docker exec` into php container. * `make exec0` - `docker exec` into php container as root. * `make dev` - Devel + kint setup, and config for Twig debug mode, disable aggregation. -* `make drush [command]` - execute drush command. +* `make drush [command]` - execute drush command. * `make phpcs` - Check codebase with `phpcs` sniffers to make sure it conforms https://www.drupal.org/docs/develop/standards. * `make phpcbf` - Fix codebase according to Drupal standards https://www.drupal.org/docs/develop/standards. * `make front` - Builds frontend tasks. * `make lint` - Runs frontend linters. +* `make storybook` - Runs storybook in current theme. #### Additional goals @@ -115,7 +119,7 @@ networks: ## Support -* This project is supported by © Skilld SAS +* This project is supported by © Skilld SAS ## Drush commands @@ -123,7 +127,7 @@ networks: ## Troubleshooting -* Use our issue queue, which is public, to search or add new issues. +* Use our issue queue, which is public, to search or add new issues. ## Git hooks diff --git a/scripts/makefile/front.mk b/scripts/makefile/front.mk index dc68af3c6..6cb6259b7 100644 --- a/scripts/makefile/front.mk +++ b/scripts/makefile/front.mk @@ -1,15 +1,40 @@ +# Evaluate recursively. +CUID ?= $(LOCAL_UID) +CGID ?= $(LOCAL_GID) +CLEAR_FRONT_PACKAGES?=yes +FRONT_PORT?=65200 + # Execute front container function. -front = docker run --rm -u $(CUID):$(CGID) -v $(shell pwd)/web/themes/custom/$(THEME_NAME):/work $(IMAGE_FRONT) ${1} +front = docker run \ + --rm \ + --init \ + -p $(FRONT_PORT):$(FRONT_PORT) \ + -u $(CUID):$(CGID) \ + -v $(shell pwd)/web/themes/custom/$(THEME_NAME):/app \ + --workdir /app \ + $(IMAGE_FRONT) ${1} + +clear-front: +ifeq ($(CLEAR_FRONT_PACKAGES), yes) + @echo "Clean of node_modules... To skip this action please set CLEAR_FRONT_PACKAGES=no in .env file" + $(call front, rm -rf /app/node_modules) +endif -## Build front tasks. front: - @echo "Building front tasks..." + @echo "Running front tasks..." docker pull $(IMAGE_FRONT) - $(call front, bower install) - $(call front) - $(call php-0, rm -rf web/themes/custom/$(THEME_NAME)/node_modules) + $(call front, yarn install --prod --ignore-optional --check-files) + $(call front, yarn build --verbose) + make clear-front lint: - @echo "Running linters..." - $(call front, gulp lint) - $(call php-0, rm -rf web/themes/custom/$(THEME_NAME)/node_modules) + @echo "Running theme linters with fix..." + docker pull $(IMAGE_FRONT) + $(call front, yarn install --prod --ignore-optional --check-files) + $(call front, yarn lint-fix) + +storybook: + @echo "Running storybook..." + docker pull $(IMAGE_FRONT) + $(call front, yarn install --ignore-optional --check-files) + $(call front, yarn storybook -p $(FRONT_PORT))