Skip to content

Commit f22c0a8

Browse files
committed
BKDK-265 Added docker-compose stack. Drupal has to be run as separate image. See ./.docker/os2web/Dockerfile.
1 parent 6f72f2c commit f22c0a8

File tree

12 files changed

+286
-3
lines changed

12 files changed

+286
-3
lines changed

.docker/mariadb/data/.gitkeep

Whitespace-only changes.

.docker/mariadb/my.cnf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# MariaDB database server configuration file.
2+
#
3+
# You can use this file to overwrite the default configuration
4+
#
5+
# For explanations see
6+
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

.docker/os2web/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM drupal:8-apache-buster
2+
3+
# Installing additional dependencies.
4+
RUN set -eux; \
5+
apt update; \
6+
apt install -qq -y \
7+
libxml2-dev \
8+
git \
9+
wget \
10+
mariadb-client-10.3 \
11+
cron; \
12+
docker-php-ext-install soap; \
13+
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
14+
15+
# Removing standard Drupal core and loading OS2Web project.
16+
WORKDIR /opt
17+
# Getting recent state of master branch.
18+
ARG OS2WEB8_TAG
19+
RUN set -eux; \
20+
rm -rf drupal; \
21+
wget https://github.com/OS2web/os2web8/archive/$OS2WEB8_TAG.tar.gz; \
22+
tar -xzvf $OS2WEB8_TAG.tar.gz; \
23+
rm $OS2WEB8_TAG.tar.gz; \
24+
mv os2web8-$OS2WEB8_TAG drupal
25+
WORKDIR /opt/drupal
26+
27+
# Loading composer dependencies and configuring project folders.
28+
RUN set -eux; \
29+
export COMPOSER_HOME="$(mktemp -d)"; \
30+
composer global require hirak/prestissimo;\
31+
COMPOSER_MEMORY_LIMIT=-1 composer install; \
32+
chown -R www-data:www-data web/sites web/modules web/themes; \
33+
# delete composer cache.
34+
rm -rf "$COMPOSER_HOME"
35+
36+
# Adding further site specific data to image.
37+
RUN echo '<?php $settings["project_env"] = PROD_ENV; ' > /opt/drupal/web/sites/default/env.settings.php; \
38+
# Adding files directories.
39+
mkdir -p files; \
40+
rm -rf /opt/drupal/web/sites/default/files; \
41+
ln -sf /opt/drupal/files /opt/drupal/web/sites/default/files; \
42+
mkdir -p private; \
43+
chown -R www-data:www-data /opt/drupal/private /opt/drupal/files
44+
45+
COPY settings/prod.settings.php /opt/drupal/web/sites/default/
46+
COPY entrypoint.sh /
47+
48+
# Adding cron tab
49+
COPY crontab /etc/cron.d/drupal
50+
RUN chmod 0644 /etc/cron.d/drupal
51+
52+
ENTRYPOINT ["/entrypoint.sh"]

.docker/os2web/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# OS2Web8 docker image
2+
3+
Image based on official [Drupal image](https://hub.docker.com/_/drupal)
4+
5+
Image includes all functional project files inside (PHP code, Composer dependencies).
6+
7+
Drupal content files should be attached as [Volumes](https://docs.docker.com/storage/volumes/) to container:
8+
* public files - `/opt/drupal/files`
9+
* private files - `/opt/drupal/private`
10+
11+
## Environment settings
12+
13+
There are available following environment settings:
14+
15+
### Mysql database
16+
* MYSQL_HOSTNAME - mysql service host name
17+
* MYSQL_DATABASE - mysql service database name
18+
* MYSQL_PORT - mysql service port
19+
* MYSQL_USER - mysql service user
20+
* MYSQL_PASSWORD - mysql service password
21+
* MYSQL_ROOT_PASSWORD - mysql service root password, uses in mysql container
22+
23+
### Drupal
24+
* DRUPAL_HASH_SALT - define drupal hash salt. Uses in `settings.php` file
25+
* OS2WEB_THEME - Drupal theme name for OS2Web project
26+
27+
### Deployment sensitive
28+
29+
* WAIT_ON_MYSQL - flag is used to set delay for getting MYSQL service ready
30+
* PRINT_STATUS - Runs "drush status" command
31+
* DEPLOYMENT - Runs deployment action: drush updb, drush cr etc
32+
* INSTALL_OS2WEB - Runs installation process. **WARNING:** It will drop existing database and reinstall Drupal.
33+
34+
## Build image
35+
36+
To build image use `build.sh` script with git tag of OS2Web project release as first argument.
37+
NOTE: You should have existing tag for OS2Web project before.
38+
39+
Example:
40+
```
41+
./build.sh [tag-name] --push
42+
```
43+
44+
`--push` - when you this option build will be pushed to docker hub.

.docker/os2web/build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
if [ $# -eq 0 ]; then
4+
echo "WARNING: There was no tag-name provided!"
5+
echo "Script usage is: './build.sh tag-name'"
6+
echo "Example: './build.sh 1.0.3'"
7+
exit 0
8+
fi
9+
10+
docker build ./ --build-arg OS2WEB8_TAG=$1 -t dkbellcom/os2web8:$1
11+
12+
if [ "$2" = "--push" ]; then
13+
echo "Docker login to dkbellcom. Type password:"
14+
read -s DOCKERHUB_PASS
15+
echo "Authorization..."
16+
echo $DOCKERHUB_PASS | docker login --username dkbellcom --password-stdin
17+
18+
if [ $? -eq 0 ]; then
19+
echo "Pushing image to docker hub ..."
20+
docker push dkbellcom/os2web8:$1
21+
echo "Check your image here https://hub.docker.com/repository/docker/dkbellcom/os2web8/tag"
22+
else
23+
echo "Image is not pushed to docker hub :("
24+
fi;
25+
fi;

.docker/os2web/crontab

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* * * * * drush cron --root=/opt/drupal >> /var/log/cron.log 2>&1
2+
# Mandatory blank line

.docker/os2web/entrypoint.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
if [ "$WAIT_ON_MYSQL" = true ]; then
3+
echo "Waiting mysql service 10s"
4+
sleep 10
5+
fi;
6+
7+
if [ "$PRINT_STATUS" = true ]; then
8+
echo "drush status"
9+
export DRUSH="drush --root=/opt/drupal"
10+
$DRUSH status
11+
fi;
12+
13+
if [ "$INSTALL_OS2WEB" = true ]; then
14+
echo "Installing new OS2Web installation"
15+
export DRUSH="drush --root=/opt/drupal"
16+
# Install drupal.
17+
$DRUSH sql-drop -y
18+
$DRUSH si os2web --account-pass=admin --locale=da -y
19+
20+
# Enable theme.
21+
if [ -z "$OS2WEB_THEME" ]; then
22+
export OS2WEB_THEME="fds_custom_theme"
23+
fi;
24+
$DRUSH theme:enable $OS2WEB_THEME -y
25+
$DRUSH config-set system.theme default $OS2WEB_THEME -y
26+
27+
# Enable modules.
28+
$DRUSH en -y os2web_pagebuilder os2web_spotbox
29+
else
30+
echo "Updating project files skipped"
31+
fi;
32+
33+
if [ "$DEPLOYMENT" = true ]; then
34+
echo "Running deployment"
35+
export DRUSH="drush --root=/opt/drupal"
36+
$DRUSH cr
37+
$DRUSH updb -y
38+
else
39+
echo "Deployment skipped"
40+
fi;
41+
42+
# Starting cron service.
43+
service cron start
44+
45+
# Starting apache.
46+
apache2-foreground

.docker/os2web/logs/.keep

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* @file
4+
* Local development override configuration feature.
5+
*
6+
* To activate this feature, copy and rename it such that its path plus
7+
* filename is 'sites/default/settings.local.php'. Then, go to the bottom of
8+
* 'sites/default/settings.php' and uncomment the commented lines that mention
9+
* 'settings.local.php'.
10+
*
11+
* If you are using a site name in the path, such as 'sites/example.com', copy
12+
* this file to 'sites/example.com/settings.local.php', and uncomment the lines
13+
* at the bottom of 'sites/example.com/settings.php'.
14+
*/
15+
16+
$databases['default']['default'] = [
17+
'database' => getenv('MYSQL_DATABASE'),
18+
'driver' => 'mysql',
19+
'host' => getenv('MYSQL_HOSTNAME'),
20+
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
21+
'password' => getenv('MYSQL_PASSWORD'),
22+
'port' => getenv('MYSQL_PORT'),
23+
'prefix' => '',
24+
'username' => getenv('MYSQL_USER'),
25+
];
26+
27+
$settings['hash_salt'] = getenv('DRUPAL_HASH_SALT');
28+
29+
$settings['file_temp_path'] = '/tmp';
30+
$settings['file_private_path'] = '../private';
31+

.env.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@
2222
# MYSQL_PASSWORD=
2323
# MYSQL_PORT=
2424
# MYSQL_USER=
25-
26-
# Another common use case is to set Drush's --uri via environment.
27-
# DRUSH_OPTIONS_URI=http://example.com
25+
# DRUPAL_HASH_SALT=
26+
# OS2WEB_THEME=

0 commit comments

Comments
 (0)