-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from OS2web/BKDK-265
Added os2web docker image
- Loading branch information
Showing
11 changed files
with
299 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
FROM drupal:8-apache-buster | ||
|
||
# Installing additional dependencies. | ||
RUN set -eux; \ | ||
apt update; \ | ||
apt install -qq -y \ | ||
libxml2-dev \ | ||
git \ | ||
wget \ | ||
mariadb-client-10.3 \ | ||
cron; \ | ||
docker-php-ext-install 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 OS2WEB8_TAG | ||
RUN set -eux; \ | ||
rm -rf drupal; \ | ||
wget https://github.com/OS2web/os2web8/archive/$OS2WEB8_TAG.tar.gz; \ | ||
tar -xzvf $OS2WEB8_TAG.tar.gz; \ | ||
rm $OS2WEB8_TAG.tar.gz; \ | ||
mv os2web8-$OS2WEB8_TAG 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; \ | ||
# Adding syn directory. | ||
mkdir -p config/sync; \ | ||
# Adjusting ownership | ||
chown -R www-data:www-data /opt/drupal/private /opt/drupal/files /opt/drupal/config/sync; \ | ||
chmod g+s -R /opt/drupal/private /opt/drupal/files /opt/drupal/config/sync | ||
|
||
COPY settings/prod.settings.php /opt/drupal/web/sites/default/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# OS2Web8 docker image | ||
|
||
Image based on official [Drupal image](https://hub.docker.com/_/drupal) | ||
|
||
Image includes all functional project files inside (PHP code, Composer dependencies). | ||
|
||
Drupal content files should be attached as [Volumes](https://docs.docker.com/storage/volumes/) to container: | ||
* public files - `/opt/drupal/files` | ||
* private files - `/opt/drupal/private` | ||
|
||
## Environment settings | ||
|
||
There are available following environment settings: | ||
|
||
### Mysql database | ||
* MYSQL_HOSTNAME - mysql service host name | ||
* MYSQL_DATABASE - mysql service database name | ||
* MYSQL_PORT - mysql service port | ||
* MYSQL_USER - mysql service user | ||
* MYSQL_PASSWORD - mysql service password | ||
* MYSQL_ROOT_PASSWORD - mysql service root password, uses in mysql container | ||
|
||
### Drupal | ||
* DRUPAL_HASH_SALT - define drupal hash salt. Uses in `settings.php` file | ||
* OS2WEB_THEME - Drupal theme name for OS2Web project | ||
|
||
## Build image | ||
|
||
To build image use `build.sh` script with git tag of OS2Web project release as first argument. | ||
NOTE: You should have existing tag for OS2Web project before. | ||
|
||
Example: | ||
``` | ||
./build.sh [tag-name] --push | ||
``` | ||
|
||
`--push` - when you this option build will be pushed to docker hub. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "WARNING: There was no tag-name provided!" | ||
echo "Script usage is: './build.sh tag-name'" | ||
echo "Example: './build.sh 1.0.3'" | ||
exit 0 | ||
fi | ||
|
||
docker build ./ --build-arg OS2WEB8_TAG=$1 -t dkbellcom/os2web8:$1 | ||
|
||
if [ "$2" = "--push" ]; then | ||
echo "Docker login to dkbellcom. Type password:" | ||
read -s DOCKERHUB_PASS | ||
echo "Authorization..." | ||
echo $DOCKERHUB_PASS | docker login --username dkbellcom --password-stdin | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Pushing image to docker hub ..." | ||
docker push dkbellcom/os2web8:$1 | ||
echo "Check your image here https://hub.docker.com/repository/docker/dkbellcom/os2web8/tag" | ||
else | ||
echo "Image is not pushed to docker hub :(" | ||
fi; | ||
fi; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
version: '3.7' | ||
|
||
networks: | ||
frontend: | ||
driver: bridge | ||
backend: | ||
driver: bridge | ||
|
||
volumes: | ||
mysql: | ||
driver: local | ||
os2web: | ||
driver: local | ||
|
||
services: | ||
|
||
# General application container. | ||
# Could be run with many replica on demand. | ||
php: | ||
# Both php and CLI containers should use the same container. | ||
image: dkbellcom/os2web8:${OS2WEB_TAG} | ||
container_name: php | ||
volumes: | ||
- ./.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_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} | ||
|
||
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=root | ||
- MYSQL_DATABASE=${MYSQL_DATABASE} | ||
- MYSQL_USER=${MYSQL_USER} | ||
- MYSQL_PASSWORD=${MYSQL_PASSWORD} | ||
networks: | ||
- backend | ||
|
||
# Example of CLI container. | ||
# It's used separately from php container as standalone CLI container. | ||
# Starts on demands and stops right after job has been done. | ||
# Use cases for this container: | ||
# - provide CLI for developers | ||
# - run cron job | ||
cli: | ||
# Both php and CLI containers should use the same container. | ||
image: dkbellcom/os2web8:${OS2WEB_TAG} | ||
container_name: cli | ||
volumes: | ||
- ./files:/opt/drupal/files | ||
- ./private:/opt/drupal/private | ||
depends_on: | ||
- mariadb | ||
networks: | ||
- backend | ||
entrypoint: | ||
- /bin/bash | ||
- -c | ||
- "ls -al /opt/drupal && ls -al /opt/drupal/files && ls -al /opt/drupal/private && drush status --root=/opt/drupal" | ||
environment: | ||
## Environment sensitive settings. See .env file. | ||
- MYSQL_HOSTNAME=${MYSQL_HOSTNAME} | ||
- MYSQL_ROOT_PASSWORD=root | ||
- 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* The PHP page that using as liveness probe. | ||
* | ||
* Environment that needs indication on project liveness can use this page. | ||
*/ | ||
|
||
use Drupal\Core\DrupalKernel; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
$autoloader = require_once 'autoload.php'; | ||
|
||
// Sending error code by default. | ||
http_response_code(500); | ||
|
||
try { | ||
// Loading standard Drupal Kernel process. | ||
$kernel = new DrupalKernel('prod', $autoloader); | ||
$server = $_SERVER; | ||
// Requesting user/login page. | ||
$server['REQUEST_URI'] = '/user/login'; | ||
$request = new Request($_GET, $_POST, [], $_COOKIE, $_FILES, $server); | ||
$response = $kernel->handle($request); | ||
$result = 'NOK'; | ||
// Only 200 response code is allowed for valid health check. | ||
if ($response->getStatusCode() == 200) { | ||
http_response_code($response->getStatusCode()); | ||
$result = 'OK'; | ||
} | ||
} | ||
catch (\Exception $exception) { | ||
$result = 'NOK' . PHP_EOL; | ||
$result = $exception->getMessage(); | ||
} | ||
|
||
echo '<pre>' . $result; |