Skip to content

Commit 6591f27

Browse files
authored
Merge pull request #11 from OS2web/BKDK-265
Added os2web docker image
2 parents b2ba4cc + 342b0af commit 6591f27

File tree

11 files changed

+299
-2
lines changed

11 files changed

+299
-2
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
# Adding syn directory.
44+
mkdir -p config/sync; \
45+
# Adjusting ownership
46+
chown -R www-data:www-data /opt/drupal/private /opt/drupal/files /opt/drupal/config/sync; \
47+
chmod g+s -R /opt/drupal/private /opt/drupal/files /opt/drupal/config/sync
48+
49+
COPY settings/prod.settings.php /opt/drupal/web/sites/default/

.docker/os2web/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
## Build image
28+
29+
To build image use `build.sh` script with git tag of OS2Web project release as first argument.
30+
NOTE: You should have existing tag for OS2Web project before.
31+
32+
Example:
33+
```
34+
./build.sh [tag-name] --push
35+
```
36+
37+
`--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/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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
# ];
1818
#
1919
# Uncomment and populate as needed.
20+
## Mysql variables.
2021
# MYSQL_DATABASE=
2122
# MYSQL_HOSTNAME=
2223
# MYSQL_PASSWORD=
2324
# MYSQL_PORT=
2425
# MYSQL_USER=
2526

26-
# Another common use case is to set Drush's --uri via environment.
27-
# DRUSH_OPTIONS_URI=http://example.com
27+
## Drupal salt
28+
# DRUPAL_HASH_SALT=
29+
30+
## Theme that is going to be used on installation process.
31+
# OS2WEB_THEME=
32+
33+
34+
## Variable used only in docker-compose.yaml
35+
# OS2WEB_TAG=

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
# Ignore Drupal's file directory
1818
/web/sites/*/files/
19+
/files
20+
!/files/.gitkeep
21+
/private
22+
!/private/.gitkeep
1923

2024
# Ignore config files. Accordingly to bussines requirements we should not store
2125
# configuration files in git.
@@ -40,3 +44,13 @@
4044
*.log
4145
*.sql
4246
*.sql.gz
47+
48+
# docker/docksal
49+
logs/*.log
50+
!logs/.gitkeep
51+
52+
.docker/logs/*
53+
!.docker/logs/.gitkeep
54+
.docker/php/logs/*.log
55+
.docker/mariadb/data/*
56+
!.docker/mariadb/data/.gitkeep

docker-compose.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
version: '3.7'
2+
3+
networks:
4+
frontend:
5+
driver: bridge
6+
backend:
7+
driver: bridge
8+
9+
volumes:
10+
mysql:
11+
driver: local
12+
os2web:
13+
driver: local
14+
15+
services:
16+
17+
# General application container.
18+
# Could be run with many replica on demand.
19+
php:
20+
# Both php and CLI containers should use the same container.
21+
image: dkbellcom/os2web8:${OS2WEB_TAG}
22+
container_name: php
23+
volumes:
24+
- ./.docker/logs:/var/log:delegated
25+
- ./files:/opt/drupal/files
26+
- ./private:/opt/drupal/private
27+
depends_on:
28+
- mariadb
29+
ports:
30+
- "8080:80"
31+
networks:
32+
- backend
33+
- frontend
34+
environment:
35+
## Environment sensitive settings. See .env file.
36+
- MYSQL_HOSTNAME=${MYSQL_HOSTNAME}
37+
- MYSQL_DATABASE=${MYSQL_DATABASE}
38+
- MYSQL_USER=${MYSQL_USER}
39+
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
40+
- MYSQL_PORT=${MYSQL_PORT}
41+
- DRUPAL_HASH_SALT=${DRUPAL_HASH_SALT}
42+
- OS2WEB_THEME=${OS2WEB_THEME}
43+
44+
mariadb:
45+
image: mariadb:latest
46+
container_name: mariadb
47+
volumes:
48+
- ./.docker/mariadb/data:/var/lib/mysql:delegated
49+
- ./.docker/mariadb/my.cnf:/etc/mysql/conf.d/my.cnf:ro,delegated
50+
environment:
51+
## Environment sensitive settings. See .env file.
52+
- MYSQL_ROOT_PASSWORD=root
53+
- MYSQL_DATABASE=${MYSQL_DATABASE}
54+
- MYSQL_USER=${MYSQL_USER}
55+
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
56+
networks:
57+
- backend
58+
59+
# Example of CLI container.
60+
# It's used separately from php container as standalone CLI container.
61+
# Starts on demands and stops right after job has been done.
62+
# Use cases for this container:
63+
# - provide CLI for developers
64+
# - run cron job
65+
cli:
66+
# Both php and CLI containers should use the same container.
67+
image: dkbellcom/os2web8:${OS2WEB_TAG}
68+
container_name: cli
69+
volumes:
70+
- ./files:/opt/drupal/files
71+
- ./private:/opt/drupal/private
72+
depends_on:
73+
- mariadb
74+
networks:
75+
- backend
76+
entrypoint:
77+
- /bin/bash
78+
- -c
79+
- "ls -al /opt/drupal && ls -al /opt/drupal/files && ls -al /opt/drupal/private && drush status --root=/opt/drupal"
80+
environment:
81+
## Environment sensitive settings. See .env file.
82+
- MYSQL_HOSTNAME=${MYSQL_HOSTNAME}
83+
- MYSQL_ROOT_PASSWORD=root
84+
- MYSQL_DATABASE=${MYSQL_DATABASE}
85+
- MYSQL_USER=${MYSQL_USER}
86+
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
87+
- MYSQL_PORT=${MYSQL_PORT}
88+
- DRUPAL_HASH_SALT=${DRUPAL_HASH_SALT}
89+
- OS2WEB_THEME=${OS2WEB_THEME}

0 commit comments

Comments
 (0)