Skip to content

Commit

Permalink
BKDK-521 Adjustemts for os2web-subsites
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyun committed Apr 11, 2022
1 parent 25f3d97 commit 2da7027
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 26 deletions.
15 changes: 7 additions & 8 deletions .docker/os2web-subsites/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DRUPAL_HASH_SALT=w-NR7Q2C3URQH6qdRvDPlbxVqdvyGMbsOwyXgtqkdJGNI7FBMbrD79UMx2DDNlS
## Domain suffix that would be used for subsites
DOMAIN_SUFFIX=os2subsites.local
## Path to base site config directory
BASE_SUBSITE_CONFIG_DIR=/opr/drupal/config/base.${DOMAIN_SUFFIX}
BASE_SUBSITE_CONFIG_DIR=/opt/drupal/config/base.${DOMAIN_SUFFIX}/sync

# OS2SUBSITE common varaibles.
## Flag for using environment variables
Expand All @@ -28,22 +28,21 @@ SERVERIP=127.0.0.1
## Default Drupal profile for subsites.
## Use `base_config` value
PROFILE=base_config
ALLOWED_INSTALL_PROFILES=minimal,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=$(which 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
## 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
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
10 changes: 3 additions & 7 deletions .docker/os2web-subsites/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ RUN set -eux; \

# Adding subsites provisioner script.
RUN set -eux; \
sed -i "s/\"installer-paths\": {/\"installer-paths\": {\"scripts\/{\$name\}\": \[\"bellcom\/os2subsites_provision\"\],/g" composer.json; \
export COMPOSER_HOME="$(mktemp -d)"; \
echo "Loading bellcom/os2subsites_provision 05042022"; \
composer require bellcom/os2subsites_provision:dev-master; \
ln -s /opt/drupal/scripts/os2subsites_provision/8.x/bc_subsites /opt/drupal/web/modules/custom/; \
# delete composer cache.
rm -rf "$COMPOSER_HOME"
git clone -n https://github.com/bellcom/os2subsite_provision.git /opt/drupal/scripts/os2subsites_provision; \
cd /opt/drupal/scripts/os2subsites_provision && git checkout e1288f4a62ca94f191c17f9d497bd9fda9a82f61; \
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; \
Expand Down
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>
8 changes: 2 additions & 6 deletions .docker/os2web-subsites/apache/os2subsites-vhost-template
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
<Directory [basedir]>
AllowOverride All
Options FollowSymLinks
# Uncommenting below will only allow a limited number of Bellcom IPs access to the site
#Include /etc/apache2/limit-bellcom.conf
# Below blocks access without auth if the domain ends with bellcom.dk
#Include /etc/apache2/limit-subsite-access.conf
</Directory>

ServerAdmin [email protected]
DocumentRoot [basedir]/public_html
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 ${APACHE_LOG_DIR}/error.log
php_value error_log /dev/stderr
php_value session.save_path [basedir]/sessions/[domain]
php_admin_value upload_tmp_dir [basedir]/tmp/[domain]

Expand Down
7 changes: 3 additions & 4 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,11 +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 Down
36 changes: 36 additions & 0 deletions .docker/os2web-subsites/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
# 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
Expand All @@ -16,6 +23,35 @@ then
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

Expand Down
Binary file removed .docker/os2web-subsites/logs/apt/eipp.log.xz
Binary file not shown.
2 changes: 1 addition & 1 deletion .docker/os2web-subsites/settings/settings.local.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@

// Passing EXTERNAL_DB_PROVISIONING into Drupal settings.
if (getenv('EXTERNAL_DB_PROVISIONING')) {
$settings['external_db_provisioning'] = getenv('EXTERNAL_DB_PROVISIONING');
$config['bc_subsites.settings']['external_db_provisioning'] = getenv('EXTERNAL_DB_PROVISIONING');
}

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ drush en os2web_pagebuilder os2web_spotbox

* Enable other modules from OS2Web category and setup them on demand.

## Local development

OS2Web subsites - See [.docker/os2web-subsites/README.md](.docker/os2web-subsites/README.md)

## Contribution

OS2Web Hjemmeside projects is opened for new features and os course bugfixes.
Expand Down

0 comments on commit 2da7027

Please sign in to comment.