Skip to content

Commit 1fa60d4

Browse files
gaydaburaandypost
authored andcommitted
cleanup and rework
1 parent f656cd8 commit 1fa60d4

File tree

14 files changed

+490
-292
lines changed

14 files changed

+490
-292
lines changed

.env.default

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
COMPOSE_FILE=./docker/docker-compose.yml:./docker/docker-compose.override.yml
22
COMPOSE_PROJECT_NAME=projectname
33
PROFILE_NAME=sdd
4-
MODULES= default_content
5-
THEME_NAME=projectname_theme
6-
SITE_NAME=Site name
4+
MODULES=default_content
5+
THEME_NAME=
6+
SITE_NAME=Example
77
SITE_MAIL=admin@example.com
88
PROJECT_INSTALL=
9-
PHP_VERSION=7
109
IMAGE_PHP=skilldlabs/php:72-fpm
10+
IMAGE_NGINX=skilldlabs/nginx:1.14.1
1111
IMAGE_FRONT=skilldlabs/frontend:zen
12+
MAIN_DOMAIN_NAME=docker.localhost
1213
DB_URL=sqlite:///dev/shm/d8.sqlite
13-
MYSQL_BASE_PATH=/dev/shm
14+
#DB_URL=mysql://d8:d8@mysql/d8
15+
DB_DATA_DIR=/dev/shm
16+
#DB_DATA_DIR=../mysql #Please include path to this folder to your .gitignore

.gitignore

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,14 @@ nbproject
55
.settings
66
.project
77
config/sync/.htaccess
8-
config/sync/README.txt
98
docker/docker-compose.override.yml
109
node_modules
1110
vendor
12-
web/.csslintrc
13-
web/.editorconfig
14-
web/.eslintignore
15-
web/.eslintrc.json
16-
web/.gitattributes
17-
web/.htaccess
18-
web/autoload.php
11+
web/*.*
1912
web/core/
20-
web/index.php
2113
web/libraries/
2214
web/modules/contrib/
2315
web/profiles/contrib/config_installer/
24-
web/robots.txt
2516
web/sites/
2617
web/themes/contrib/
27-
web/update.php
28-
web/web.config
18+
mysql/

Makefile

Lines changed: 84 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,217 +1,149 @@
11
# Add utility functions and scripts to the container
22
include scripts/makefile/*.mk
33

4-
.PHONY: all up down cex cim prepare install si exec info phpcs phpcbf drush
4+
.PHONY: all provision si exec exec0 down clean dev info phpcs phpcbf drush check
5+
.DEFAULT_GOAL := help
56

6-
# Read project name from .env file
7+
# https://stackoverflow.com/a/6273809/1826109
8+
%:
9+
@:
10+
11+
# Prepare enviroment variables from defaults.
712
$(shell false | cp -i \.env.default \.env 2>/dev/null)
813
$(shell false | cp -i \.\/docker\/docker-compose\.override\.yml\.default \.\/docker\/docker-compose\.override\.yml 2>/dev/null)
914
include .env
1015

11-
# Get local values only once.
16+
# Get user/group id to manage permissions between host and containers.
1217
LOCAL_UID := $(shell id -u)
1318
LOCAL_GID := $(shell id -g)
1419

1520
# Evaluate recursively.
1621
CUID ?= $(LOCAL_UID)
1722
CGID ?= $(LOCAL_GID)
1823

24+
# Define network name.
1925
COMPOSE_NET_NAME := $(COMPOSE_PROJECT_NAME)_front
20-
MYSQL_DATADIR := $(MYSQL_BASE_PATH)/$(COMPOSE_PROJECT_NAME)_mysql
21-
22-
php = docker-compose exec -T --user $(CUID):$(CGID) php time ${1}
23-
php-0 = docker-compose exec -T php time ${1}
24-
front = docker run --rm -u $(CUID):$(CGID) -v $(shell pwd)/web/themes/$(THEME_NAME):/work $(IMAGE_FRONT) ${1}
26+
# Define mysql storage folder.
27+
MYSQL_DATADIR := $(DB_DATA_DIR)/$(COMPOSE_PROJECT_NAME)_mysql
28+
29+
# Execute php container as regular user.
30+
php = docker-compose exec -T --user $(CUID):$(CGID) php ${1}
31+
# Execute php container as root user.
32+
php-0 = docker-compose exec -T php ${1}
33+
# Function for code sniffer images.
34+
phpcsexec = docker run --rm \
35+
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
36+
-v $(shell pwd)/web/modules/custom:/work/modules \
37+
-v $(shell pwd)/web/themes/custom:/work/themes \
38+
skilldlabs/docker-phpcs-drupal ${1} -s --colors \
39+
--standard=Drupal,DrupalPractice \
40+
--extensions=php,module,inc,install,profile,theme,yml,txt,md,js \
41+
--ignore=*.css,libraries/*,dist/*,styleguide/* \
42+
.
2543

2644
## Full site install from the scratch
27-
all: | include prepare install si info
45+
all: | provision composer si info
2846

29-
include:
47+
## Provision enviroment
48+
provision:
49+
# Check if enviroment variables has been defined.
3050
ifeq ($(strip $(COMPOSE_PROJECT_NAME)),projectname)
31-
#todo: ask user to make a project name and mv folders.
32-
$(error Project name can not be default, please edit ".env" and set COMPOSE_PROJECT_NAME variable.)
51+
$(info Project name can not be default, please enter project name.)
52+
$(eval COMPOSE_PROJECT_NAME = $(strip $(shell read -p "Project name: " REPLY;echo -n $$REPLY)))
53+
$(shell sed -i -e '/COMPOSE_PROJECT_NAME=/ s/=.*/=$(COMPOSE_PROJECT_NAME)/' .env)
54+
$(info Please review your project settings and run `make all` again.)
55+
exit 1
3356
endif
34-
35-
prepare:
57+
ifeq ($(shell docker-compose config --services | grep mysql),mysql)
3658
mkdir -p $(MYSQL_DATADIR)
59+
endif
3760
make -s down
38-
make -s up
61+
@echo "Updating containers..."
62+
docker-compose pull
63+
@echo "Build and run containers..."
64+
docker-compose up -d --remove-orphans
3965
$(call php-0, apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community graphicsmagick)
4066
$(call php-0, kill -USR2 1)
4167
$(call php, composer global require -o --update-no-dev --no-suggest "hirak/prestissimo:^0.3")
4268

43-
install:
69+
composer:
4470
$(call php, composer install --prefer-dist -o --no-dev)
4571
$(call php, composer drupal-scaffold)
72+
$(call php, composer create-required-files)
73+
# Uncomment this string to build front separately. See scripts/makefile/front.mk
74+
# make -s front
4675

47-
## Reinstall site
76+
## Install drupal.
4877
si:
49-
$(call php-0, chmod +w web/sites/default)
50-
ifneq ("$(wildcard web/sites/default/settings.php)","")
51-
$(call php-0, rm -f web/sites/default/settings.php)
52-
endif
5378
@echo "Installing from: $(PROJECT_INSTALL)"
5479
ifeq ($(PROJECT_INSTALL), config)
5580
$(call php, drush si config_installer --db-url=$(DB_URL) --account-pass=admin -y config_installer_sync_configure_form.sync_directory=../config/sync)
5681
else
5782
$(call php, drush si $(PROFILE_NAME) --db-url=$(DB_URL) --account-pass=admin -y --site-name="$(SITE_NAME)" --site-mail="$(SITE_MAIL)" install_configure_form.site_default_country=FR install_configure_form.date_default_timezone=Europe/Paris)
5883
endif
59-
#$(call php, drush en $(MODULES) -y)
60-
#$(call php, drush pmu $(MODULES) -y)
61-
#make -s locale-update
62-
#make -s cim
63-
#make -s update-alias
64-
#make -s _local-settings
65-
make -s info
66-
67-
## Update locale
68-
locale-update:
69-
$(call php, drush locale-check)
70-
$(call php, drush locale-update)
71-
72-
_local-settings:
73-
@echo "Turn on settings.local"
74-
$(call php, chmod +w web/sites/default)
75-
$(call php, cp settings/settings.local.php web/sites/default/settings.local.php)
76-
$(call php-0, sed -i "/settings.local.php';/s/# //g" web/sites/default/settings.php)
77-
78-
## Execute config export to config/sync directory
79-
cex:
80-
$(call php, drush cex -y)
81-
ifneq ($(PROJECT_INSTALL), config)
82-
rm -rf config/sync/*
83-
cp -R web/$(shell docker-compose exec -T --user $(CUID):$(CGID) php drush ev 'echo substr(\Drupal::service("config.storage.sync")->getFilePath("drush"), 0, -10);')/* config/sync
84+
ifneq ($(strip $(MODULES)),)
85+
$(call php, drush en $(MODULES) -y)
86+
$(call php, drush pmu $(MODULES) -y)
8487
endif
8588

86-
## Execute config import from config/sync directory
87-
cim:
88-
$(call php, drush cr)
89-
$(call php, drush cim -y)
90-
91-
update-alias:
92-
$(call php, drush pag canonical_entities:node update)
93-
$(call php, drush cr)
94-
9589
## Project's containers information
9690
info:
97-
ifeq ($(shell docker inspect --format="{{ .State.Running }}" $(COMPOSE_PROJECT_NAME)_web 2> /dev/null),true)
98-
@echo Project http://$(shell docker inspect --format='{{(index .NetworkSettings.Networks "$(COMPOSE_NET_NAME)").IPAddress}}' $(COMPOSE_PROJECT_NAME)_web)
99-
endif
100-
ifeq ($(shell docker inspect --format="{{ .State.Running }}" $(COMPOSE_PROJECT_NAME)_mail 2> /dev/null),true)
101-
@echo Mailhog http://$(shell docker inspect --format='{{(index .NetworkSettings.Networks "$(COMPOSE_NET_NAME)").IPAddress}}' $(COMPOSE_PROJECT_NAME)_mail):8025
102-
endif
103-
ifeq ($(shell docker inspect --format="{{ .State.Running }}" $(COMPOSE_PROJECT_NAME)_adminer 2> /dev/null),true)
104-
@echo Adminer http://$(shell docker inspect --format='{{(index .NetworkSettings.Networks "$(COMPOSE_NET_NAME)").IPAddress}}' $(COMPOSE_PROJECT_NAME)_adminer)
105-
endif
91+
$(info Containers for "$(COMPOSE_PROJECT_NAME)" info:)
92+
$(eval CONTAINERS = $(shell docker ps -f name=$(COMPOSE_PROJECT_NAME) --format "{{ .ID }}"))
93+
$(foreach CONTAINER, $(CONTAINERS),$(info $(shell printf '%-19s \n' $(shell docker inspect --format='{{.NetworkSettings.Networks.$(COMPOSE_NET_NAME).IPAddress}} {{range $$p, $$conf := .NetworkSettings.Ports}}{{$$p}}{{end}} {{.Name}}' $(CONTAINER) | rev | sed "s/pct\//,pct:/g" | sed "s/,//" | rev | awk '{ print $0}')) ))
94+
@echo "$(RESULT)"
10695

107-
chown:
108-
# Use this goal to set permissions in docker container
109-
$(call php-0, /bin/sh -c "chown $(CUID):$(CGID) /var/www/html/web -R")
110-
# Need this to fix files folder
111-
$(call php-0, /bin/sh -c "chown www-data: /var/www/html/web/sites/default/files -R")
112-
113-
## Run shell in PHP container as CUID:CGID user
96+
## Run shell in PHP container as regular user
11497
exec:
11598
docker-compose exec --user $(CUID):$(CGID) php ash
11699

117-
## Run shel in PHP container as root
100+
## Run shell in PHP container as root
118101
exec0:
119102
docker-compose exec php ash
120103

121-
up: net
122-
@echo "Updating containers..."
123-
docker-compose pull
124-
@echo "Build and run containers..."
125-
docker-compose up -d --remove-orphans
126-
127104
down:
128105
@echo "Removing network & containers for $(COMPOSE_PROJECT_NAME)"
129106
@docker-compose down -v --remove-orphans --rmi local
130107

108+
DIRS = web/core web/libraries web/modules/contrib web/profiles/contrib web/sites web/themes/contrib vendor
109+
131110
## Totally remove project build folder, docker containers and network
132-
clean: DIRS := core libraries modules/contrib profiles/contrib sites themes/contrib
133-
clean: info down
134-
@for i in $(DIRS); do if [ -d "web/$$i" ]; then echo "Removing web/$$i..."; docker run --rm -v $(shell pwd):/mnt $(IMAGE_PHP) sh -c "rm -rf /mnt/web/$$i"; fi; done
135-
@if [ -d $(MYSQL_DATADIR) ]; then echo "Removing mysql data $(MYSQL_DATADIR)..."; docker run --rm -v $(MYSQL_BASE_PATH):/mnt/2rm $(IMAGE_PHP) sh -c "rm -rf /mnt/2rm/$(COMPOSE_PROJECT_NAME)_mysql"; fi
136-
137-
net:
138-
ifeq ($(shell docker network ls -q -f Name=$(COMPOSE_NET_NAME)),)
139-
docker network create $(COMPOSE_NET_NAME)
140-
endif
141-
ifeq ($(shell grep -c -F 'IPRANGE=' .env), 0)
142-
# @echo Define IP range $(net-range)
143-
@printf "\nIPRANGE=%s\n" $(shell docker network inspect $(COMPOSE_NET_NAME) --format '{{(index .IPAM.Config 0).Subnet}}') >> .env
144-
else
145-
# @if [ '$(IPRANGE)' != '$(shell docker network inspect $(COMPOSE_NET_NAME) --format '{{(index .IPAM.Config 0).Subnet}}')' ]; then echo "Replace IP range $(IPRANGE)"; sed -i "s#IPRANGE=.*#IPRANGE=$(shell docker network inspect $(COMPOSE_NET_NAME) --format '{{(index .IPAM.Config 0).Subnet}}')#" .env; fi;
111+
clean: info
112+
@for i in $(DIRS); do if [ -d "$$i" ]; then echo "Removing $$i..."; docker run --rm -v $(shell pwd):/mnt $(IMAGE_PHP) sh -c "rm -rf /mnt/$$i"; fi; done
113+
$(eval SCAFFOLD = $(shell docker-compose exec -T --user $(CUID):$(CGID) php composer run-script list-scaffold-files | grep -P '^(?!>)'))
114+
@for i in $(SCAFFOLD); do if [ -e "web/$$i" ]; then echo "Removing web/$$i..."; rm -rf web/$$i; fi; done
115+
make -s down
116+
ifeq ($(shell docker-compose config --services | grep mysql),mysql)
117+
@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
146118
endif
147-
# grep -q -F 'IPRANGE=' .env || printf "\nIPRANGE=$(shell docker network inspect $(COMPOSE_NET_NAME) --format '{{(index .IPAM.Config 0).Subnet}}')" >> .env
148-
149-
front:
150-
@echo "Building front tasks..."
151-
docker pull $(IMAGE_FRONT)
152-
$(call front, bower install)
153-
$(call front)
154-
$(call php-0, rm -rf web/themes/$(THEME_NAME)/node_modules)
155-
156-
lint:
157-
@echo "Running linters..."
158-
$(call front, gulp lint)
159-
$(call php-0, rm -rf web/themes/$(THEME_NAME)/node_modules)
160119

120+
## Enable development mode and disable caching.
161121
dev:
162122
@echo "Dev tasks..."
163123
$(call php, composer install --prefer-dist -o)
164-
$(call php-0, chmod +w web/sites/default)
165-
$(call php, cp web/sites/default/default.services.yml web/sites/default/services.yml)
166-
$(call php, sed -i -e 's/debug: false/debug: true/g' web/sites/default/services.yml)
167-
$(call php, cp web/sites/example.settings.local.php web/sites/default/settings.local.php)
168-
$(call php, drush -y config-set system.performance css.preprocess 0)
169-
$(call php, drush -y config-set system.performance js.preprocess 0)
170-
$(call php, drush en devel devel_generate webform_devel kint -y)
171-
$(call php, drush pm-uninstall dynamic_page_cache page_cache -y)
172-
$(call php, drush cr)
173-
124+
@$(call php-0, chmod +w web/sites/default)
125+
@$(call php, cp web/sites/default/default.services.yml web/sites/default/services.yml)
126+
@$(call php, sed -i -e 's/debug: false/debug: true/g' web/sites/default/services.yml)
127+
@$(call php, cp web/sites/example.settings.local.php web/sites/default/settings.local.php)
128+
@echo "Including settings.local.php."
129+
@$(call php-0, sed -i "/settings.local.php';/s/# //g" web/sites/default/settings.php)
130+
@$(call php, drush -y -q config-set system.performance css.preprocess 0)
131+
@$(call php, drush -y -q config-set system.performance js.preprocess 0)
132+
@echo "Enabling devel module."
133+
@$(call php, drush -y -q en devel devel_generate kint)
134+
@echo "Disabling caches."
135+
@$(call php, drush -y -q pm-uninstall dynamic_page_cache page_cache)
136+
@$(call php, drush cr)
137+
138+
## Run drush command in PHP container. To pass arguments use double dash: "make drush dl devel -- -y"
174139
drush:
175-
$(call php, drush $(filter-out $@,$(MAKECMDGOALS)))
176-
177-
# https://stackoverflow.com/a/6273809/1826109
178-
%:
179-
@:
140+
$(call php, $(filter-out "$@",$(MAKECMDGOALS)))
141+
$(info "To pass arguments use double dash: "make drush dl devel -- -y"")
180142

181143
## Check codebase with phpcs sniffers to make sure it conforms https://www.drupal.org/docs/develop/standards
182144
phpcs:
183-
docker run --rm \
184-
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
185-
-v $(shell pwd)/web/modules/custom:/work/modules \
186-
-v $(shell pwd)/web/themes/$(THEME_NAME):/work/themes \
187-
skilldlabs/docker-phpcs-drupal phpcs -s --colors \
188-
--standard=Drupal,DrupalPractice \
189-
--extensions=php,module,inc,install,profile,theme,yml \
190-
--ignore=*.css,*.md,*.js .
191-
docker run --rm \
192-
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
193-
-v $(shell pwd)/web/modules/custom:/work/modules \
194-
-v $(shell pwd)/web/themes/$(THEME_NAME):/work/themes \
195-
skilldlabs/docker-phpcs-drupal phpcs -s --colors \
196-
--standard=Drupal,DrupalPractice \
197-
--extensions=js \
198-
--ignore=*.css,*.md,libraries/*,styleguide/* .
145+
@$(call phpcsexec, phpcs)
199146

200147
## Fix codebase according to Drupal standards https://www.drupal.org/docs/develop/standards
201148
phpcbf:
202-
docker run --rm \
203-
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
204-
-v $(shell pwd)/web/modules/custom:/work/modules \
205-
-v $(shell pwd)/web/themes/$(THEME_NAME):/work/themes \
206-
skilldlabs/docker-phpcs-drupal phpcbf -s --colors \
207-
--standard=Drupal,DrupalPractice \
208-
--extensions=php,module,inc,install,profile,theme,yml,txt,md \
209-
--ignore=*.css,*.md,*.js .
210-
docker run --rm \
211-
-v $(shell pwd)/web/profiles/$(PROFILE_NAME):/work/profile \
212-
-v $(shell pwd)/web/modules/custom:/work/modules \
213-
-v $(shell pwd)/web/themes/$(THEME_NAME):/work/themes \
214-
skilldlabs/docker-phpcs-drupal phpcbf -s --colors \
215-
--standard=Drupal,DrupalPractice \
216-
--extensions=js \
217-
--ignore=*.css,*.md,libraries/*,styleguide/* .
149+
@$(call phpcsexec, phpcbf)

0 commit comments

Comments
 (0)