Skip to content

Commit

Permalink
BKDK-265 Added docker-compose stack. Drupal has to be run as separate…
Browse files Browse the repository at this point in the history
… image. See ./.docker/os2web/Dockerfile.
  • Loading branch information
andriyun committed Jan 11, 2021
1 parent 6f72f2c commit 0b6bd3c
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 3 deletions.
Binary file added .docker/logs/apt/eipp.log.xz
Binary file not shown.
Empty file added .docker/mariadb/data/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions .docker/mariadb/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# MariaDB database server configuration file.
#
# You can use this file to overwrite the default configuration
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
40 changes: 40 additions & 0 deletions .docker/os2web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM drupal:8-apache-buster

# Installing additional dependencies.
RUN set -eux; \
apt update; \
apt install libxml2-dev git -y; \
docker-php-ext-install mysqli soap; \
curl -fsSL "https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar" -o /usr/local/bin/drush && chmod +x /usr/local/bin/drush

# Removing standard Drupal core and loading OS2Web project.
WORKDIR /opt
# Getting recent state of master branch.
ARG OS2WEB_TAG
RUN set -eux; \
rm -rf drupal; \
git clone --single-branch --branch master https://github.com/OS2web/os2web8.git drupal
WORKDIR /opt/drupal

# Loading composer dependencies and configuring project folders.
RUN set -eux; \
export COMPOSER_HOME="$(mktemp -d)"; \
composer global require hirak/prestissimo;\
COMPOSER_MEMORY_LIMIT=-1 composer install; \
chown -R www-data:www-data web/sites web/modules web/themes; \
# delete composer cache.
rm -rf "$COMPOSER_HOME"

# Adding further site specific data to image.
RUN echo '<?php $settings["project_env"] = PROD_ENV; ' > /opt/drupal/web/sites/default/env.settings.php; \
# Adding files directories.
mkdir -p files; \
rm -rf /opt/drupal/web/sites/default/files; \
ln -sf /opt/drupal/files /opt/drupal/web/sites/default/files; \
mkdir -p private; \
chown -R www-data:www-data /opt/drupal/private /opt/drupal/files

COPY settings/prod.settings.php /opt/drupal/web/sites/default/
COPY entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]
2 changes: 2 additions & 0 deletions .docker/os2web/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker build ./ -t os2web
42 changes: 42 additions & 0 deletions .docker/os2web/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
if [ "$WAIT_ON_MYSQL" = true ]; then
echo "Waiting mysql service 10s"
sleep 10
fi;

if [ "$PRINT_STATUS" = true ]; then
echo "drush status"
export DRUSH="drush --root=/opt/drupal"
$DRUSH status
fi;

if [ "$INSTALL_OS2WEB" = true ]; then
echo "Installing new OS2Web installation"
export DRUSH="drush --root=/opt/drupal"
# Install drupal.
$DRUSH sql-drop -y
$DRUSH si os2web --account-pass=admin --locale=da -y

# Enable theme.
if [ -z "$OS2WEB_THEME" ]; then
export OS2WEB_THEME="fds_custom_theme"
fi;
$DRUSH theme:enable $OS2WEB_THEME -y
$DRUSH config-set system.theme default $OS2WEB_THEME -y

# Enable modules.
$DRUSH en -y os2web_pagebuilder os2web_spotbox
else
echo "Updating project files skipped"
fi;

if [ "$DEPLOYMENT" = true ]; then
echo "Running deployment"
export DRUSH="drush --root=/opt/drupal"
$DRUSH cr
$DRUSH updb -y
else
echo "Deployment skipped"
fi;

apache2-foreground
Empty file added .docker/os2web/logs/.keep
Empty file.
31 changes: 31 additions & 0 deletions .docker/os2web/settings/prod.settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @file
* Local development override configuration feature.
*
* To activate this feature, copy and rename it such that its path plus
* filename is 'sites/default/settings.local.php'. Then, go to the bottom of
* 'sites/default/settings.php' and uncomment the commented lines that mention
* 'settings.local.php'.
*
* If you are using a site name in the path, such as 'sites/example.com', copy
* this file to 'sites/example.com/settings.local.php', and uncomment the lines
* at the bottom of 'sites/example.com/settings.php'.
*/

$databases['default']['default'] = [
'database' => getenv('MYSQL_DATABASE'),
'driver' => 'mysql',
'host' => getenv('MYSQL_HOSTNAME'),
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'password' => getenv('MYSQL_PASSWORD'),
'port' => getenv('MYSQL_PORT'),
'prefix' => '',
'username' => getenv('MYSQL_USER'),
];

$settings['hash_salt'] = getenv('DRUPAL_HASH_SALT');

$settings['file_temp_path'] = '/tmp';
$settings['file_private_path'] = '../private';

5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
# MYSQL_PASSWORD=
# MYSQL_PORT=
# MYSQL_USER=

# Another common use case is to set Drush's --uri via environment.
# DRUSH_OPTIONS_URI=http://example.com
# DRUPAL_HASH_SALT=
# OS2WEB_THEME=
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

# Ignore Drupal's file directory
/web/sites/*/files/
/files
!/files/.gitkeep
/private
!/private/.gitkeep

# Ignore config files. Accordingly to bussines requirements we should not store
# configuration files in git.
Expand All @@ -40,3 +44,10 @@
*.log
*.sql
*.sql.gz

# docker/docksal
logs/*.log
.docker/logs/*.log
.docker/php/logs/*.log
.docker/mariadb/data/*
!.docker/mariadb/data/.gitkeep
64 changes: 64 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: '3.7'

networks:
frontend:
driver: bridge
backend:
driver: bridge

volumes:
mysql:
driver: local

services:

php:
image: os2web
container_name: php
volumes:
# - ./:/opt/drupal
- ./.docker/logs:/var/log:delegated
- ./files:/opt/drupal/files
- ./private:/opt/drupal/private
depends_on:
- mariadb
ports:
- "8080:80"
networks:
- backend
- frontend
environment:
## Environment sensitive settings. See .env file.
- MYSQL_HOSTNAME=${MYSQL_HOSTNAME}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_PORT=${MYSQL_PORT}
- DRUPAL_HASH_SALT=${DRUPAL_HASH_SALT}
- OS2WEB_THEME=${OS2WEB_THEME}

## Deployment sensitive settings. See .docker/os2web/entrypoint.sh
# This flag is used to set delay for getting MYSQL service ready.
- WAIT_ON_MYSQL=true
# Runs "drush status" command.
- PRINT_STATUS=true
# Runs deployment action: drush updb, drush cr etc.
- DEPLOYMENT=true
# WARNING: It will drop existing database and reinstall Drupal.
- INSTALL_OS2WEB=true

mariadb:
image: mariadb:latest
container_name: mariadb
volumes:
- ./.docker/mariadb/data:/var/lib/mysql:delegated
- ./.docker/mariadb/my.cnf:/etc/mysql/conf.d/my.cnf:ro,delegated
environment:
## Environment sensitive settings. See .env file.
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
networks:
- backend

0 comments on commit 0b6bd3c

Please sign in to comment.