Commit adce353c authored by Ines WALLON's avatar Ines WALLON
Browse files

fix: #1 Rework init files

parent 4e8dca02
include config/Makefile.config
help:
@echo "\n${ORANGE}usage: make ${BLUE}COMMAND${NC}"
@echo "\n${YELLOW}Commands:${NC}"
@echo " ${BLUE}c-install : ${LIGHT_BLUE}Install PHP/Drupal dependencies with composer.${NC}"
@echo " ${BLUE}c-update : ${LIGHT_BLUE}Update PHP/Drupal dependencies with composer.${NC}"
@echo " ${BLUE}clean : ${LIGHT_BLUE}Clean directories for reset.${NC}"
@echo " ${BLUE}clone : ${LIGHT_BLUE}Clone module eg: ${YELLOW}make clone centreon_status${NC}"
@echo " ${BLUE}docker-start : ${LIGHT_BLUE}Create and start containers.${NC}"
@echo " ${BLUE}docker-stop : ${LIGHT_BLUE}Stop and clear all services.${NC}"
@echo " ${BLUE}d-cex : ${LIGHT_BLUE}Export configuration from Drupal App.${NC}"
@echo " ${BLUE}d-cim : ${LIGHT_BLUE}Export configuration from Drupal App.${NC}"
@echo " ${BLUE}d-cr : ${LIGHT_BLUE}Flush all caches from Drupal App.${NC}"
@echo " ${BLUE}drush : ${LIGHT_BLUE}Execute the given command from arguments eg: ${YELLOW}make drush cr${NC}"
@echo " ${BLUE}git-init : ${LIGHT_BLUE}Initialize git repository.${NC}"
@echo " ${BLUE}install : ${LIGHT_BLUE}Launch install.${NC}"
@echo " ${BLUE}logs : ${LIGHT_BLUE}Follow log output.${NC}"
@echo " ${BLUE}update : ${LIGHT_BLUE}Update Drupal.${NC}"
@echo " ${BLUE}sql-dump : ${LIGHT_BLUE}Create backup of all databases.${NC}"
@echo " ${BLUE}test : ${LIGHT_BLUE}Check coding standard, deprecated code and run phpunit eg: ${YELLOW}make test /project/web/modules/custom${NC}"
@echo -e "\n${ORANGE}usage: make ${BLUE}COMMAND${NC}"
@echo -e "\n${YELLOW}Commands:${NC}"
@echo -e " ${BLUE}c-install : ${LIGHT_BLUE}Install PHP/Drupal dependencies with composer.${NC}"
@echo -e " ${BLUE}c-update : ${LIGHT_BLUE}Update PHP/Drupal dependencies with composer.${NC}"
@echo -e " ${BLUE}clean : ${LIGHT_BLUE}Clean directories for reset.${NC}"
@echo -e " ${BLUE}clone : ${LIGHT_BLUE}Clone module eg: ${YELLOW}make clone webform${NC}"
@echo -e " ${BLUE}docker-start : ${LIGHT_BLUE}Create and start containers.${NC}"
@echo -e " ${BLUE}docker-stop : ${LIGHT_BLUE}Stop and clear all services.${NC}"
@echo -e " ${BLUE}d-cex : ${LIGHT_BLUE}Export configuration from Drupal App.${NC}"
@echo -e " ${BLUE}d-cim : ${LIGHT_BLUE}Export configuration from Drupal App.${NC}"
@echo -e " ${BLUE}d-cr : ${LIGHT_BLUE}Flush all caches from Drupal App.${NC}"
@echo -e " ${BLUE}drush : ${LIGHT_BLUE}Execute the given command from arguments eg: ${YELLOW}make drush cr${NC}"
@echo -e " ${BLUE}git-init : ${LIGHT_BLUE}Initialize git repository.${NC}"
@echo -e " ${BLUE}install : ${LIGHT_BLUE}Launch install.${NC}"
@echo -e " ${BLUE}logs : ${LIGHT_BLUE}Follow log output.${NC}"
@echo -e " ${BLUE}update : ${LIGHT_BLUE}Update Drupal.${NC}"
@echo -e " ${BLUE}sql-dump : ${LIGHT_BLUE}Create backup of all databases.${NC}"
@echo -e " ${BLUE}quality-phpcs : ${LIGHT_BLUE}Check coding standard eg: ${YELLOW}make quality-phpcs web/modules/custom/${NC}"
@echo -e " ${BLUE}quality-phpstan : ${LIGHT_BLUE}Static analyse eg: ${YELLOW}make quality-phpstan web/modules/custom/${NC}"
init:
@echo "Enter your site url [www.drupal9.localhost]:"
read sitename
@echo "Enter your maildev url [mail.drupal9.localhost]:"
read maildevurl
@bash scripts/init.sh ${INIT_FILES} $$sitename $$maildevurl
git-init:
@rm -rf .git
@git init
@git add .
@git commit -m "Initial commit"
@git checkout -b integ
@git checkout -b develop
@bash scripts/init.sh ${INIT_FILES}
clean: docker-stop
@echo "${BLUE}Clean directories${NC}"
@echo -e "${BLUE}Clean directories${NC}"
@sudo rm -Rf backup/*
@sudo rm -Rf vendor/
@sudo rm -Rf data/
......@@ -50,74 +38,57 @@ clean: docker-stop
@sudo rm -Rf docker-compose.yml
.ONESHELL:
install: init
@echo "Enter your sitename [drupal]:"
read sitename
@echo "Enter your System mail [admin@exemple.com]:"
read sitemail
install:
@docker-compose pull
@docker-compose up -d
@docker-compose exec web bash ${WORK_DIR}/scripts/install.sh "$$sitename" "$$sitemail"
@make resetOwner
update:
@docker-compose exec web ${WORK_DIR}/scripts/update.sh
@make resetOwner
clone:
@bash ./scripts/clone-project.sh $(filter-out $@,$(MAKECMDGOALS))
c-install:
@echo "${BLUE}Installing your application dependencies:${NC}"
@docker-compose exec web composer install
@make resetOwner
@echo -e "${BLUE}Installing your application dependencies:${NC}"
@docker-compose exec web composer install
c-update:
@echo "${BLUE}Updating your application dependencies:${NC}"
@docker-compose exec web composer update
@make resetOwner
@echo -e "${BLUE}Updating your application dependencies:${NC}"
@docker-compose exec web composer update
d-cr:
@echo "${BLUE}Clearings all Drupal caches:${NC}"
@docker-compose exec web drush -r=${WORK_DIR} cr
@echo -e "${BLUE}Clearings all Drupal caches:${NC}"
@docker-compose exec web drush -r=${WORK_DIR} cr
d-cex:
@echo "${BLUE}Export of your Drupal configuration:${NC}"
@docker-compose exec web drush -r=${WORK_DIR} cex
@make resetOwner
@echo -e "${BLUE}Export of your Drupal configuration:${NC}"
@docker-compose exec web drush -r=${WORK_DIR} cex
d-cim:
@echo "${BLUE}Import of your Drupal configuration:${NC}"
@docker-compose exec web drush -r=${WORK_DIR} cim
drush:
@docker-compose exec web drush -r=${WORK_DIR} $(filter-out $@,$(MAKECMDGOALS))
@make resetOwner
sql-dump:
@echo "${BLUE}Dump of all database:${NC}"
@make drush "sql:dump --result-file=/project/backup/dump_$(shell date "+%Y-%m-%d-%Hh%Mm%Ss").sql"
@make resetOwner
@echo -e "${BLUE}Import of your Drupal configuration:${NC}"
@docker-compose exec web drush -r=${WORK_DIR} cim
docker-start:
@echo "${BLUE}Starting all containers:${NC}"
@echo -e "${BLUE}Starting all containers:${NC}"
@docker-compose up -d
docker-stop:
@echo "${BLUE}Stopping all containers:${NC}"
@docker-compose down -v
@echo -e "${BLUE}Stopping all containers:${NC}"
@docker-compose down
drush:
@docker-compose exec web drush -r=${WORK_DIR} $(filter-out $@,$(MAKECMDGOALS))
sql-dump:
@echo -e "${BLUE}Dump of all database:${NC}"
@make drush "sql:dump --result-file=/project/backup/dump_$(shell date "+%Y-%m-%d-%Hh%Mm%Ss").sql"
quality-phpcs:
@docker-compose exec web bash ${WORK_DIR}/scripts/test-phpcs.sh "$(filter-out $@,$(MAKECMDGOALS))"
@make resetOwner
@docker-compose exec web bash ${WORK_DIR}/scripts/test-phpcs.sh "$(filter-out $@,$(MAKECMDGOALS))"
quality-phpstan:
@docker-compose exec web phpstan analyse -c ${WORK_DIR}/scripts/quality/phpstan.neon.dist "$(filter-out $@,$(MAKECMDGOALS))"
@make resetOwner
logs:
@docker-compose logs -f
resetOwner:
@$(shell sudo chown -Rf $(shell id -u -n):$(shell id -g -n) "$(shell pwd)/backup" "$(shell pwd)/web")
.PHONY: drush clean resetOwner
......@@ -8,26 +8,9 @@
- traefik
## Install drupal
1) Initialise git repository with ```make git-init```
2) Launch install with ```make install```
1) Initialise docker configs `make init`
2) Edit .env file
3) Launch install with `make install`
## Make command
| make| Description|
|---|---|
|c-install| Install PHP/Drupal dependencies with composer|
|c-update| Update PHP/Drupal dependencies with composer |
|clean| Clean directories for reset |
|clone| Clone module eg: `make clone centreon_status`|
|docker-start| Create and start containers |
|docker-stop| Stop and clear all services |
|d-cex| Export configuration from Drupal App |
|d-cim| Export configuration from Drupal App |
|d-cr| Flush all caches from Drupal App |
|drush| Execute the given command from arguments eg: `make drush cr`|
|git-init| Initialize git repository|
|install| Launch install |
|logs|Initialize git repository|
|update|Update Drupal|
|sql-dump| Dump database|
|test| Check coding standard, deprecated code and run phpunit eg: make test `/project/web/modules/custom/`|
Run `make help` for more information
......@@ -14,6 +14,7 @@ services:
volumes:
- .:/project
- ./config/php/php.ini:/usr/local/etc/php/php.ini
httpd:
image: httpd:alpine
labels:
......@@ -62,6 +63,7 @@ services:
- "traefik.http.routers.${PROJECT_NAME}_mail_secure.rule=Host(`${DRUPAL_MAIL_DEFAULT_DOMAIN_1}`)"
- "traefik.http.routers.${PROJECT_NAME}_mail_secure.middlewares=remove-signature-headers@file"
- "traefik.http.routers.${PROJECT_NAME}_mail_secure.tls=true"
## For development.
# For tests.
chrome:
......@@ -78,7 +80,3 @@ services:
- "--log-path=/tmp/chromedriver.log"
- "--verbose"
- "--whitelisted-ips="
networks:
default:
external:
name: drupalci_nw
......@@ -2,6 +2,8 @@ PROJECT_NAME=D9_PROJECT
DRUPAL_SITE_DEFAULT_DOMAIN_1=d9.docker.localhost
DRUPAL_MAIL_DEFAULT_DOMAIN_1=mail.docker.localhost
COMPOSER_AUTH={"github-oauth": {"github.com": "YOUR_GITHUB_TOKEN"}}
SITENAME="Drupal 9"
MAIL=exemple@exemple.com
FIXUID=1000
FIXGID=1000
......@@ -12,7 +14,22 @@ ADMIN_PASSWORD=admin
ADMIN_MAIL=admin@exemple.com
SITE_NAME=Drupal
#Xdebug
# Database
DB_NAME=drupal
DB_USER=drupal
DB_PASS=drupal
DB_HOST=mariadb
DB_PREFIX=
HASH_SALT=project_d9
# Redis
USE_REDIS=True
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=0
# Xdebug
XDEBUG_ENABLED=false
CUSTOM_PHP_XDEBUG_CLIENT_HOST=172.17.0.1
CUSTOM_PHP_XDEBUG_CLIENT_PORT=9001
......@@ -21,7 +38,6 @@ CUSTOM_PHP_XDEBUG_MAX_NESTING_LEVEL=500
CUSTOM_PHP_XDEBUG_MODE=debug
CUSTOM_PHP_XDEBUG_START_WITH_REQUEST=yes
# ENVIRONEMENT=prod
ENVIRONEMENT=dev
WORK_DIR=/project
......
<?php
$databases['default']['default'] = [
'driver' => 'mysql',
'database' => 'drupal',
'username' => 'drupal',
'password' => 'drupal',
'host' => 'mariadb',
'prefix' => '',
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'host' => getenv('DB_HOST'),
'prefix' => getenv('DB_PREFIX'),
];
$settings["config_sync_directory"] = $app_root . '/' . $site_path . '/../../../config/drupal/sync';
// Config split.
......@@ -31,18 +28,19 @@ $settings['file_scan_ignore_directories'] = [
];
// Redis.
$settings['redis.connection']['interface'] = 'PhpRedis';
$settings['redis.connection']['host'] = 'redis';
$settings['redis.connection']['port'] = '6379';
$settings['redis.connection']['base'] = 0;
if (getenv('USE_REDIS') === 'True') {
$settings['redis.connection']['interface'] = 'PhpRedis';
$settings['redis.connection']['host'] = getenv('REDIS_HOST');
$settings['redis.connection']['port'] = getenv('REDIS_PORT');
$settings['redis.connection']['base'] = getenv('REDIS_DB');
}
$settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';
$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';
$settings['cache']['default'] = 'cache.backend.redis';
$settings['hash_salt'] = 'skeleton_d9';
$settings['hash_salt'] = getenv('HASH_SALT');
// Prevent deletion of orphan files.
// TODO: Remove this line when the following issues will be fixed:
......@@ -56,6 +54,8 @@ $config['system.file']['temporary_maximum_age'] = 0;
// Performance.
$config['system.performance']['cache']['page']['max_age'] = 86400;
if (file_exists($app_root . '/' . $site_path . '/../development.settings.php')) {
include $app_root . '/' . $site_path . '/../development.settings.php';
if (getenv('ENVIRONEMENT') === 'dev') {
if (file_exists($app_root . '/' . $site_path . '/../development.settings.php')) {
include $app_root . '/' . $site_path . '/../development.settings.php';
}
}
#!/bin/bash
if [ "$#" -eq 0 ]; then
echo "[error] this script run only with make command"
exit 1
fi
INIT_FILES=$1
SITENAME=$2
MAILDEVURL=$3
PROJECT_NAME=$4
rsync -avzq --ignore-existing ${INIT_FILES}/exemple.docker-compose.yml docker-compose.yml
rsync -avzq --ignore-existing ${INIT_FILES}/exemple.gitlab-ci.yml .gitlab-ci.yml
rsync -avzq --ignore-existing ${INIT_FILES}/exemple.env .env
......@@ -18,17 +7,5 @@ rsync -avzq --ignore-existing config/drupal/example.settings.local.php config/dr
mkdir -p web/sites/default/
rsync -avzq --ignore-existing config/drupal/example.settings.php web/sites/default/settings.php
if [ ! -z $SITENAME ]; then
sed -i "s/d9.docker.localhost/${SITENAME}/g" .env
fi
if [ ! -z $MAILDEVURL ]; then
sed -i "s/mail.docker.localhost/${MAILDEVURL}/g" .env
fi
if [ ! -z $PROJECT_NAME ]; then
sed -i "s/D9_PROJECT/${PROJECT_NAME}/g" .env
fi
sed -i "s/FIXUID=1000/FIXUID=$(id -u)/g" .env
sed -i "s/FIXGID=1000/FIXGID=$(id -g)/g" .env
#!/bin/bash -e
if [ $ENVIRONEMENT = "dev" ]; then
composer install --working-dir=$WORK_DIR
cp $WORK_DIR/config/drupal/example.development.settings.php $WORK_DIR/web/sites/default/development.settings.php
......@@ -11,9 +10,8 @@ else
fi
mkdir -p $WORK_DIR/web/sites/default/files/
find $WORK_DIR/web/sites/default/files/ -type d -exec chmod 777 '{}' \;
find $WORK_DIR/web/sites/default/files/ -type f -exec chmod 644 '{}' \;
chown www-data:www-data $WORK_DIR/web/sites/default/files/ -R
chmod 777 -R $WORK_DIR/web/sites/default/files/
chown www-data:www-data -R $WORK_DIR/web/sites/default/files/
sleep 30
......@@ -24,18 +22,7 @@ drush si minimal \
--account-pass=$ADMIN_PASSWORD \
--account-mail=$ADMIN_MAIL -y \
--existing-config
if [ -n "$1" ]; then
drush config-set "system.site" name "$1" -y
else
drush config-set "system.site" name Drupal -y
fi
if [ -n "$2" ]; then
drush config-set "system.mail" mail "$2" -y
else
drush config-set "system.mail" mail admin@exemple.com -y
fi
drush config-set "system.site" name "$SITENAME" -y
chmod 777 -R $WORK_DIR/web/sites/default/files
......
#!/bin/bash
echo -e "${YELLOW}[notice] Dump database${NC}"
drush sql:dump --result-file=$WORK_DIR/backup/dump_$(date "+%Y-%m-%d-%Hh%Mm%Ss").sql
echo -e "${YELLOW}[notice] Enable maintenance_mode${NC}"
drush state:set system.maintenance_mode 1
echo -e "${YELLOW}[notice] Dump database${NC}"
drush sql:dump --result-file=$WORK_DIR/backup/dump_$(date "+%Y-%m-%d-%Hh%Mm%Ss").sql
echo -e "${YELLOW}[notice] Run composer install${NC}"
if [ $ENVIRONEMENT = "dev" ]; then
composer install --working-dir=$WORK_DIR
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment