Skip to content

Commit

Permalink
Merge branch 'os2subsites' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyun committed Apr 19, 2022
2 parents 64ea532 + 414a5a8 commit 914aa6d
Show file tree
Hide file tree
Showing 15 changed files with 1,151 additions and 7 deletions.
66 changes: 66 additions & 0 deletions .docker/os2web-subsites/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,72 @@
# Copy and rename this file to .env at root of this project.
#

# Uncomment and populate as needed.
## Subsite admin UI db creadentials
MYSQL_DATABASE=os2subsites
MYSQL_HOSTNAME=mariadb
MYSQL_ROOT_PASSWORD=root
MYSQL_PASSWORD=os2subsites
MYSQL_PORT=3306
MYSQL_USER=os2subsites

## Drupal salt
DRUPAL_HASH_SALT=w-NR7Q2C3URQH6qdRvDPlbxVqdvyGMbsOwyXgtqkdJGNI7FBMbrD79UMx2DDNlSqvfmY-OOKLw
## Domain suffix that would be used for subsites
DOMAIN_SUFFIX=os2subsites.local
## Path to base site config directory
BASE_SUBSITE_CONFIG_DIR=/opt/drupal/config/base.${DOMAIN_SUFFIX}/sync

# OS2SUBSITE common varaibles.
## Flag for using environment variables
## Comment this variale to use values from `config.sh file`
USE_ENV_CONFIG=1
## Drupal project root directory
BASEDIR=/opt/drupal
SERVERIP=127.0.0.1
## Default Drupal profile for subsites.
## Use `base_config` value
PROFILE=base_config
ALLOWED_INSTALL_PROFILES=minimal,os2web
## Email used for subsite admin user.
EMAIL=[email protected]
## Path to
SCRIPTDIR=/opt/drupal/scripts/os2subsites_provision
## Path to drush
DRUSH=/usr/local/bin/drush
## Database creadentials for creating subsite db.
DBHOST=mariadb
DBUSER_HOST=mariadb
## External db provisioning. NOTE: To disable external provisioning you have to JUST comment variable
EXTERNAL_DB_PROVISIONING=1
PROVISIONING_SOURCES_PATH=/opt/drupal/private/subsite-credentials
## For internal db provisioning you have to specify directory to mysql db files are stored. It's used for db existing check.
#DBDIR=/var/lib/mysql
## Subsite admin pass
ADMINPASS=admin
## Path to subsite vhost template
VHOSTTEMPLATE=${SCRIPTDIR}/../os2subsites_provision/os2subsites-vhost-template
## Drupal document root directory path
MULTISITE=${BASEDIR}/web
## Path to file where subsites registering.
SITESFILE=${MULTISITE}/sites/sites.php
## Temp directory for subsites
TMPDIRBASE=${BASEDIR}/tmp
## Log directory for subsites
LOGDIRBASE=${BASEDIR}/logs
## Session directory for subsites
SESSIONDIRBASE=${BASEDIR}/sessions
## Username for subsite administrator user. User will be created on subsites.
SITEADMIN=subsiteadmin
## Apache webserver username.
APACHEUSER=www-data
## Root user name. Sometimes this variable is empty.
USER=root
# Version of Drupal core. Accepted values 7,8
DRUPAL=8
# Additional option for site-install command
INSTALL_OPTIONS=

## Variable used only in docker-compose.yaml
COMPOSE_PROJECT_NAME=os2web-subsites-docker-compose
# TAG=
Expand Down
2 changes: 2 additions & 0 deletions .docker/os2web-subsites/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env
volumes/*
!volumes/.keep
logs/*
!logs/.keep
15 changes: 15 additions & 0 deletions .docker/os2web-subsites/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ RUN set -eux; \
sudo; \
rm -rf /var/lib/apt/lists/*

# Adding subsites provisioner script.
RUN set -eux; \
git clone -n https://github.com/bellcom/os2subsite_provision.git /opt/drupal/scripts/os2subsites_provision; \
cd /opt/drupal/scripts/os2subsites_provision && git checkout 89a7202548462dfbb6946fda9978cfad3e77412b; \
ln -s /opt/drupal/scripts/os2subsites_provision/8.x/bc_subsites /opt/drupal/web/modules/custom/

# Adding further site specific data to image.
RUN chown -R www-data:www-data /opt/drupal/tmp /opt/drupal/logs /opt/drupal/translations; \
echo "<?php" > /opt/drupal/web/sites/sites.php; \
Expand All @@ -21,6 +27,12 @@ RUN chown -R www-data:www-data /opt/drupal/tmp /opt/drupal/logs /opt/drupal/tran
# Additional PHP configuration for OS2Web subsites both CLI and Apache
COPY php/os2web-subsites.ini /usr/local/etc/php/conf.d/os2web-subsites.ini

# Add OS2Subsites vhost template
COPY apache/os2subsites-vhost-template /opt/drupal/scripts/os2subsites_provision/os2subsites-vhost-template

# Copy drupal local settings
COPY settings/*.php /opt/drupal/.docker/os2web-subsites/settings/

# Adding entry point where required services could be started.
COPY entrypoint.sh /usr/bin/

Expand All @@ -34,6 +46,9 @@ RUN echo "HOME=/opt/drupal" >> /opt/drupal/.env
# Addjusting php runtime.
RUN ln -s /usr/local/bin/php /usr/bin/php;

# Allow www-data call scripts.
COPY os2subsite /etc/sudoers.d/os2subsite

ENTRYPOINT ["entrypoint.sh"]

CMD ["apache2-foreground"]
118 changes: 118 additions & 0 deletions .docker/os2web-subsites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,121 @@ Example:
```

`--push` - when you this option build will be pushed to docker hub.

## Local developemnt through docker

While main OS2Web solution is using Docksal for local development. It's easier for testing purposes to use bare docker-compose environment for OS2Web sibsutes.

It expects that all action would be performed on Docker subsites folder .docker/os2web-subsites


### Restart docker stack

docker-compose down
sudo rm -rf volumes/*
docker volume rm os2web-subsites-docker-compose_mysql
docker-compose up -d
docker-compose exec php bash



### Install subsites creator
sudo -E -u www-data drush si --account-pass=admin -y && drush en bc_subsites admin_toolbar_tools -y


### Entironments variables

Define your .env file as it stated below
```
#
# Copy and rename this file to .env at root of this project.
#
# Uncomment and populate as needed.
## Subsite admin UI db creadentials
MYSQL_DATABASE=os2subsites
MYSQL_HOSTNAME=mariadb
MYSQL_ROOT_PASSWORD=root
MYSQL_PASSWORD=os2subsites
MYSQL_PORT=3306
MYSQL_USER=os2subsites
## Drupal salt
DRUPAL_HASH_SALT=w-NR7Q2C3URQH6qdRvDPlbxVqdvyGMbsOwyXgtqkdJGNI7FBMbrD79UMx2DDNlSqvfmY-OOKLw
## Domain suffix that would be used for subsites
DOMAIN_SUFFIX=os2subsites.local
## Path to base site config directory
BASE_SUBSITE_CONFIG_DIR=/opt/drupal/config/ay-test0604-3.${DOMAIN_SUFFIX}/sync
# OS2SUBSITE common varaibles.
## Flag for using environment variables
## Comment this variale to use values from `config.sh file`
USE_ENV_CONFIG=1
## Drupal project root directory
BASEDIR=/opt/drupal
SERVERIP=127.0.0.1
## Default Drupal profile for subsites.
## Use `base_config` value
PROFILE=base_config
ALLOWED_INSTALL_PROFILES=minimal,os2web
## Email used for subsite admin user.
[email protected]
## Path to
SCRIPTDIR=/opt/drupal/scripts/os2subsites_provision
## Path to drush
DRUSH=/usr/local/bin/drush
## Database creadentials for creating subsite db.
DBHOST=mariadb
DBUSER_HOST=mariadb
### Optional varialbles. Leave it empty to user root as user name.
DB_ROOT_USER=root
### Optional varialbles. Leave it empty to user root user without password from localhost.
DB_ROOT_PASSWORD=root
## External db provisioning. NOTE: To disable external provisioning you have to JUST comment variable
EXTERNAL_DB_PROVISIONING=1
PROVISIONING_SOURCES_PATH=/opt/drupal/private/subsite-credentials
## For internal db provisioning you have to specify directory to mysql db files are stored. It's used for db existing check.
#DBDIR=/var/lib/mysql
## Subsite admin pass
ADMINPASS=admin
## Path to subsite vhost template
VHOSTTEMPLATE=${SCRIPTDIR}/../os2subsites_provision/os2subsites-vhost-template
## Drupal document root directory path
MULTISITE=${BASEDIR}/web
## Path to file where subsites registering.
SITESFILE=${MULTISITE}/sites/sites.php
## Temp directory for subsites
TMPDIRBASE=${BASEDIR}/tmp
## Log directory for subsites
LOGDIRBASE=${BASEDIR}/logs
## Session directory for subsites
SESSIONDIRBASE=${BASEDIR}/sessions
## Username for subsite administrator user. User will be created on subsites.
SITEADMIN=subsiteadmin
## Apache webserver username.
APACHEUSER=www-data
## Root user name. Sometimes this variable is empty.
USER=root
# Version of Drupal core. Accepted values 7,8
DRUPAL=8
# Additional option for site-install command
INSTALL_OPTIONS=
## Variable used only in docker-compose.yaml
COMPOSE_PROJECT_NAME=os2web-subsites-docker-compose
TAG=2.1.5-rc-BKDK-521 # <---- This value should be one you use for testing.
WEB_SERVER_PORT=8098
```

### Handling domains

Main domain for subsite creator is localhost:8098

NOTE: Port could be different if you changed `WEB_SERVER_PORT` variable.

Each subsites domain should be defined in your local `/etc/hosts` file like:
```
127.0.0.1 new-subsite.os2subsites.local
```

NOTE: Domain suffix `.os2subsites.local` could be different if you changed `DOMAIN_SUFFIX` variable.
28 changes: 28 additions & 0 deletions .docker/os2web-subsites/apache/000-default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<VirtualHost *:80>
<Directory /opt/drupal>
AllowOverride All
Options FollowSymLinks
</Directory>

ServerAdmin [email protected]
DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SetEnvIf X-Forwarded-Proto https HTTPS=on

php_admin_value open_basedir /opt/drupal:/usr/share/php
php_value include_path .:/opt/drupal

php_value log_errors 1
php_value html_errors 0
php_value display_errors 0
php_admin_value error_reporting 1023
php_value error_log /dev/stderr

php_value session.save_path /opt/drupal/sessions
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value upload_tmp_dir /opt/drupal/tmp/default
</VirtualHost>
Empty file.
26 changes: 26 additions & 0 deletions .docker/os2web-subsites/apache/os2subsites-vhost-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# DO NOT EDIT THIS VHOST. IT WILL BE MODIFIED BY SCRIPTS. (The includes for access limits and ServerAliases)
<VirtualHost *:80>
<Directory [basedir]>
AllowOverride All
Options FollowSymLinks
</Directory>

ServerAdmin [email protected]
DocumentRoot /var/www/html
ServerName [domain]

CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log

php_admin_value open_basedir [basedir]:/usr/share/php
php_value include_path .:[basedir]
php_value error_log /dev/stderr
php_value session.save_path [basedir]/sessions/[domain]
php_admin_value upload_tmp_dir [basedir]/tmp/[domain]

php_value log_errors 1
php_value html_errors 0
php_value display_errors 0
php_admin_value error_reporting 2047
php_admin_value max_execution_time 180
</VirtualHost>
14 changes: 7 additions & 7 deletions .docker/os2web-subsites/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ networks:
volumes:
mysql:
driver: local
os2web:
driver: local
services:

# General application container.
Expand All @@ -22,10 +20,12 @@ services:
- ./logs:/var/log:delegated
- ./volumes/drupal/private:/opt/drupal/private
- ./volumes/drupal/web/sites:/opt/drupal/web/sites
- ./volumes/apache/sites-availbale:/etc/apache/sites-availbale
- ./volumes/apache/sites-enabled:/etc/apache/sites-enabled
- ./volumes/apache2/sites-available:/etc/apache2/sites-available
- ./volumes/apache2/sites-enabled:/etc/apache2/sites-enabled
- ./volumes/config:/opt/drupal/config
- ./volumes/crontabs:/var/spool/cron/crontabs
- ./volumes/tmp:/opt/drupal/tmp
#- ../../scripts/os2subsites_provision:/opt/drupal/scripts/os2subsites_provision
depends_on:
- mariadb
ports:
Expand All @@ -39,8 +39,8 @@ services:
mariadb:
image: mariadb:latest
volumes:
- /var/lib/mysql
- mysql:/var/lib/mysql
networks:
- backend
environment:
MARIADB_ROOT_PASSWORD: root
env_file:
- .env
52 changes: 52 additions & 0 deletions .docker/os2web-subsites/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,56 @@
# Starting cron service.
service cron start

# Check basic file structure for subsites creator
if [ ! -f "/etc/apache2/sites-available/000-default.conf" ]
then
cp -f /opt/drupal/.docker/os2web-subsites/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
ln -sf /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf
fi

# Check basic file structure for subsites creator
if [ ! -d "/opt/drupal/web/sites/default" ]
then
echo "Default sites folder doesn't exists. Create folder and standard files"
mkdir -p /opt/drupal/web/sites/default/files
cp -f /opt/drupal/.docker/os2web-subsites/settings/default.settings.php /opt/drupal/web/sites/default/default.settings.php
cp -f /opt/drupal/.docker/os2web-subsites/settings/default.settings.php /opt/drupal/web/sites/default/settings.php
echo 'include $app_root . "/" . $site_path . "/settings.local.php";' >> /opt/drupal/web/sites/default/settings.php
cp -f /opt/drupal/.docker/os2web-subsites/settings/settings.local.php /opt/drupal/web/sites/default/settings.local.php
chmod 755 /opt/drupal/web/sites/default /opt/drupal/web/sites/default/settings.php /opt/drupal/web/sites/default/settings.local.php
chown -R www-data:www-data /opt/drupal/web/sites
fi

# Check basic file structure for subsites creator
if [ ! -f "/opt/drupal/web/sites/sites.php" ]
then
echo "Creating web/sites/sites.php"
echo "<?php" > /opt/drupal/web/sites/sites.php
chown www-data:www-data /opt/drupal/web/sites/sites.php
fi

# Check default config dir
if [ ! -f "/opt/drupal/config/default" ]
then
mkdir -p /opt/drupal/config/default
chown www-data:www-data -R /opt/drupal/config
fi

# Check default temp dir
if [ ! -f "/opt/drupal/tmp/default" ]
then
mkdir -p /opt/drupal/tmp/default
chown www-data:www-data -R /opt/drupal/tmp
fi

# Check default private dir
if [ ! -f "/opt/drupal/private/default" ]
then
mkdir -p /opt/drupal/private/default
chown www-data:www-data -R /opt/drupal/private
fi

# Copying shared settings file
cp -f /opt/drupal/.docker/os2web-subsites/settings/shared.settings.php /opt/drupal/web/sites/shared.settings.php

exec "$@"
6 changes: 6 additions & 0 deletions .docker/os2web-subsites/os2subsite
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
www-data ALL=(root) NOPASSWD:SETENV: /opt/drupal/scripts/os2subsites_provision/subsite_add_domain.sh
www-data ALL=(root) NOPASSWD:SETENV: /opt/drupal/scripts/os2subsites_provision/subsite_create.sh
www-data ALL=(root) NOPASSWD:SETENV: /opt/drupal/scripts/os2subsites_provision/subsite_delete.sh
www-data ALL=(root) NOPASSWD:SETENV: /opt/drupal/scripts/os2subsites_provision/subsite_remove_domain.sh
www-data ALL=(root) NOPASSWD:SETENV: /opt/drupal/scripts/os2subsites_provision/phase1.sh
www-data ALL=(root) NOPASSWD:SETENV: /opt/drupal/scripts/os2subsites_provision/phase2.sh
2 changes: 2 additions & 0 deletions .docker/os2web-subsites/settings/default.settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
include $app_root . '/sites/shared.settings.php';
Loading

0 comments on commit 914aa6d

Please sign in to comment.