mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-11-05 20:58:21 +00:00
Compare commits
2 Commits
aa1a901309
...
9e874408a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e874408a7 | |||
| bebf76951c |
@@ -7,6 +7,7 @@ features:
|
|||||||
oidc: true
|
oidc: true
|
||||||
central_database: true
|
central_database: true
|
||||||
logout: true
|
logout: true
|
||||||
|
|
||||||
server:
|
server:
|
||||||
csp:
|
csp:
|
||||||
flags: {}
|
flags: {}
|
||||||
@@ -15,18 +16,21 @@ server:
|
|||||||
canonical:
|
canonical:
|
||||||
- "drupal.{{ PRIMARY_DOMAIN }}"
|
- "drupal.{{ PRIMARY_DOMAIN }}"
|
||||||
aliases: []
|
aliases: []
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
services:
|
services:
|
||||||
database:
|
database:
|
||||||
enabled: true
|
enabled: true
|
||||||
drupal:
|
drupal:
|
||||||
version: latest
|
# Use a PHP 8.2+ base image to ensure compatibility with OIDC 2.x syntax
|
||||||
|
version: "10-php8.2-apache"
|
||||||
image: drupal
|
image: drupal
|
||||||
name: drupal
|
name: drupal
|
||||||
backup:
|
backup:
|
||||||
no_stop_required: true
|
no_stop_required: true
|
||||||
volumes:
|
volumes:
|
||||||
data: drupal_data
|
data: drupal_data
|
||||||
|
|
||||||
rbac:
|
rbac:
|
||||||
roles:
|
roles:
|
||||||
authenticated:
|
authenticated:
|
||||||
|
|||||||
11
roles/web-app-drupal/tasks/00_permissions.yml
Normal file
11
roles/web-app-drupal/tasks/00_permissions.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
- name: "Ensure sites/default/files exists and is writable"
|
||||||
|
command: >
|
||||||
|
docker exec -u root {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
|
"set -e;
|
||||||
|
d='{{ DRUPAL_DOCKER_HTML_PATH }}/sites/default';
|
||||||
|
f=\"$d/files\";
|
||||||
|
mkdir -p \"$f\";
|
||||||
|
chown -R {{ DRUPAL_USER }}:{{ DRUPAL_USER }} \"$d\";
|
||||||
|
find \"$d\" -type d -exec chmod 775 {} +;
|
||||||
|
find \"$d\" -type f -exec chmod 664 {} +;"
|
||||||
|
changed_when: true
|
||||||
@@ -1,8 +1,25 @@
|
|||||||
|
- name: "Wait for database readiness"
|
||||||
|
command: >
|
||||||
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
|
"php -r '
|
||||||
|
$h=\"{{ database_host }}\"; $p={{ database_port }};
|
||||||
|
$d=\"{{ database_name }}\"; $u=\"{{ database_username }}\"; $pw=\"{{ database_password }}\";
|
||||||
|
$t=microtime(true)+60; $ok=false;
|
||||||
|
while (microtime(true)<$t) {
|
||||||
|
try { new PDO(\"mysql:host=$h;port=$p;dbname=$d;charset=utf8mb4\", $u, $pw,[PDO::ATTR_TIMEOUT=>2]); $ok=true; break; }
|
||||||
|
catch (Exception $e) { usleep(300000); }
|
||||||
|
}
|
||||||
|
if (!$ok) { fwrite(STDERR, \"DB not ready\\n\"); exit(1); }'"
|
||||||
|
register: db_wait
|
||||||
|
retries: 1
|
||||||
|
failed_when: db_wait.rc != 0
|
||||||
|
|
||||||
- name: "Run Drupal site:install via Drush"
|
- name: "Run Drupal site:install via Drush"
|
||||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||||
command: >
|
command: >
|
||||||
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
"/var/www/html/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} si standard -y
|
"/opt/drupal/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} site:install standard -y
|
||||||
|
--db-url='mysql://{{ database_username }}:{{ database_password }}@{{ database_host }}:{{ database_port }}/{{ database_name }}'
|
||||||
--site-name='{{ applications | get_app_conf(application_id, 'title', True) }}'
|
--site-name='{{ applications | get_app_conf(application_id, 'title', True) }}'
|
||||||
--account-name='{{ applications | get_app_conf(application_id, 'users.administrator.username') }}'
|
--account-name='{{ applications | get_app_conf(application_id, 'users.administrator.username') }}'
|
||||||
--account-mail='{{ applications | get_app_conf(application_id, 'users.administrator.email', True) }}'
|
--account-mail='{{ applications | get_app_conf(application_id, 'users.administrator.email', True) }}'
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
- name: "Enable OpenID Connect core module"
|
- name: "Enable OpenID Connect core module"
|
||||||
command: >
|
command: >
|
||||||
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
"/var/www/html/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} en openid_connect -y"
|
"drush -r {{ DRUPAL_DOCKER_HTML_PATH }} en openid_connect -y"
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
||||||
- name: "Enable OpenID Connect Keycloak preset (submodule of openid_connect)"
|
- name: "Enable OpenID Connect Keycloak preset (submodule of openid_connect)"
|
||||||
command: >
|
command: >
|
||||||
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
"/var/www/html/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} en openid_connect_client_keycloak -y"
|
"drush -r {{ DRUPAL_DOCKER_HTML_PATH }} en openid_connect_client_keycloak -y"
|
||||||
changed_when: true
|
changed_when: true
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|||||||
@@ -9,26 +9,46 @@
|
|||||||
label: "{{ item.key }}"
|
label: "{{ item.key }}"
|
||||||
command: >
|
command: >
|
||||||
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
"/var/www/html/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} cset -y
|
"drush -r {{ DRUPAL_DOCKER_HTML_PATH }} cset -y
|
||||||
openid_connect.settings {{ item.key }}
|
openid_connect.settings {{ item.key }}
|
||||||
{{ (item.value | to_json) if item.value is mapping or item.value is sequence else item.value }}"
|
{{ (item.value | to_json) if item.value is mapping or item.value is sequence else item.value }}"
|
||||||
|
|
||||||
- name: "Ensure OIDC client entity exists"
|
- name: "Ensure/Update OIDC client entity (generic)"
|
||||||
vars:
|
vars:
|
||||||
client_id: "{{ oidc_vars.oidc_client.id }}"
|
client_id: "{{ oidc_vars.oidc_client.id }}"
|
||||||
client_label: "{{ oidc_vars.oidc_client.label }}"
|
client_label: "{{ oidc_vars.oidc_client.label }}"
|
||||||
|
plugin_id: "{{ oidc_vars.oidc_client.plugin }}"
|
||||||
|
settings_b64: "{{ oidc_vars.oidc_client.settings | to_json | b64encode }}"
|
||||||
command: >
|
command: >
|
||||||
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
"/var/www/html/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} eval '
|
"drush -r {{ DRUPAL_DOCKER_HTML_PATH }} eval '
|
||||||
$id=\"{{ client_id }}\"; $label=\"{{ client_label }}\";
|
$id=\"{{ client_id }}\";
|
||||||
$storage=\Drupal::entityTypeManager()->getStorage(\"openid_connect_client\");
|
$label=\"{{ client_label }}\";
|
||||||
if (!$storage->load($id)) {
|
$plugin=\"{{ plugin_id }}\";
|
||||||
$client=$storage->create([\"id\"=>$id,\"label\"=>$label]);
|
$settings=json_decode(base64_decode(\"{{ settings_b64 }}\"), TRUE);
|
||||||
$client->save();
|
$storage=\\Drupal::entityTypeManager()->getStorage(\"openid_connect_client\");
|
||||||
print \"created\";
|
$e=$storage->load($id);
|
||||||
} else { print \"exists\"; }'"
|
if (!$e) {
|
||||||
register: client_exists
|
$e=$storage->create([
|
||||||
changed_when: "'created' in client_exists.stdout"
|
\"id\"=> $id,
|
||||||
|
\"label\"=> $label,
|
||||||
|
\"status\"=> TRUE,
|
||||||
|
\"plugin\"=> $plugin,
|
||||||
|
\"settings\"=> $settings,
|
||||||
|
]);
|
||||||
|
$e->save();
|
||||||
|
print \"created\";
|
||||||
|
} else {
|
||||||
|
$e->set(\"label\", $label);
|
||||||
|
$e->set(\"plugin\", $plugin);
|
||||||
|
$e->set(\"settings\", $settings);
|
||||||
|
$e->set(\"status\", TRUE);
|
||||||
|
$e->save();
|
||||||
|
print \"updated\";
|
||||||
|
}
|
||||||
|
'"
|
||||||
|
register: client_apply
|
||||||
|
changed_when: "'created' in client_apply.stdout or 'updated' in client_apply.stdout"
|
||||||
|
|
||||||
- name: "Apply OIDC client settings"
|
- name: "Apply OIDC client settings"
|
||||||
vars:
|
vars:
|
||||||
@@ -40,7 +60,7 @@
|
|||||||
label: "{{ item.key }}"
|
label: "{{ item.key }}"
|
||||||
command: >
|
command: >
|
||||||
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
"/var/www/html/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} eval '
|
"drush -r {{ DRUPAL_DOCKER_HTML_PATH }} eval '
|
||||||
$id=\"{{ client_id }}\";
|
$id=\"{{ client_id }}\";
|
||||||
$key=\"{{ item.key }}\";
|
$key=\"{{ item.key }}\";
|
||||||
$val=json_decode(base64_decode(\"{{ (item.value | to_json | b64encode) }}\"), true);
|
$val=json_decode(base64_decode(\"{{ (item.value | to_json | b64encode) }}\"), true);
|
||||||
@@ -55,5 +75,5 @@
|
|||||||
- name: "Clear caches after OIDC config"
|
- name: "Clear caches after OIDC config"
|
||||||
command: >
|
command: >
|
||||||
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
docker exec {{ DRUPAL_CONTAINER }} bash -lc
|
||||||
"/var/www/html/vendor/bin/drush -r {{ DRUPAL_DOCKER_HTML_PATH }} cr"
|
"drush -r {{ DRUPAL_DOCKER_HTML_PATH }} cr"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|||||||
@@ -37,6 +37,9 @@
|
|||||||
- name: Flush handlers to make container ready
|
- name: Flush handlers to make container ready
|
||||||
meta: flush_handlers
|
meta: flush_handlers
|
||||||
|
|
||||||
|
- name: "Fix permissions for sites/default/files"
|
||||||
|
include_tasks: 00_permissions.yml
|
||||||
|
|
||||||
- name: "Ensure settings.php includes settings.local.php"
|
- name: "Ensure settings.php includes settings.local.php"
|
||||||
include_tasks: 01_settings_local_include.yml
|
include_tasks: 01_settings_local_include.yml
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
FROM {{ DRUPAL_IMAGE }}:{{ DRUPAL_VERSION }}
|
FROM {{ DRUPAL_IMAGE }}:{{ DRUPAL_VERSION }}
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# System dependencies (mail support + basic tools)
|
# System dependencies (mail support + MySQL client + basic tools)
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y msmtp msmtp-mta git unzip zip less nano curl vim && \
|
apt-get install -y msmtp msmtp-mta git unzip zip less nano curl vim mariadb-client && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# PHP extensions required by Drupal/Drush bootstrap
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
RUN docker-php-ext-install -j"$(nproc)" pdo_mysql
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# Install Composer
|
# Install Composer
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
@@ -19,13 +24,13 @@ ENV COMPOSER_ALLOW_SUPERUSER=1
|
|||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# Build Drupal project with Drush + OpenID Connect
|
# Build Drupal project with Drush + OpenID Connect
|
||||||
# IMPORTANT:
|
# IMPORTANT:
|
||||||
# - The Drupal base image uses /var/www/html as a symlink to /opt/drupal/web
|
# - The Drupal base image uses /var/www/html as a symlink to {{ DRUPAL_DOCKER_HTML_PATH }}
|
||||||
# - Therefore, the actual project root must be placed in /opt/drupal
|
# - Therefore, the actual project root must be placed in /opt/drupal
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
builddir="$(mktemp -d)"; \
|
builddir="$(mktemp -d)"; \
|
||||||
composer create-project --no-interaction --no-ansi --no-progress drupal/recommended-project:^10 "$builddir"; \
|
composer create-project --no-interaction --no-ansi --no-progress drupal/recommended-project:^10 "$builddir"; \
|
||||||
composer --working-dir="$builddir" require -n drush/drush:^13 drupal/openid_connect:^1; \
|
composer --working-dir="$builddir" require -n drush/drush:^13 drupal/openid_connect:^2@beta; \
|
||||||
rm -rf /opt/drupal/* /opt/drupal/.[!.]* /opt/drupal/..?* 2>/dev/null || true; \
|
rm -rf /opt/drupal/* /opt/drupal/.[!.]* /opt/drupal/..?* 2>/dev/null || true; \
|
||||||
mkdir -p /opt/drupal; \
|
mkdir -p /opt/drupal; \
|
||||||
cp -a "$builddir"/. /opt/drupal/; \
|
cp -a "$builddir"/. /opt/drupal/; \
|
||||||
@@ -34,7 +39,7 @@ RUN set -eux; \
|
|||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# Make vendor binaries available in PATH
|
# Make vendor binaries available in PATH
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
ENV PATH="/opt/drupal/vendor/bin:${PATH}"
|
RUN ln -sf /opt/drupal/vendor/bin/drush /usr/local/bin/drush
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# PHP upload configuration
|
# PHP upload configuration
|
||||||
@@ -55,21 +60,24 @@ RUN set -eux; \
|
|||||||
# Ensure vendor binaries are executable
|
# Ensure vendor binaries are executable
|
||||||
if [ -d /opt/drupal/vendor/bin ]; then chmod a+rx /opt/drupal/vendor/bin/*; fi; \
|
if [ -d /opt/drupal/vendor/bin ]; then chmod a+rx /opt/drupal/vendor/bin/*; fi; \
|
||||||
if [ -f /opt/drupal/vendor/drush/drush/drush ]; then chmod a+rx /opt/drupal/vendor/drush/drush/drush; fi; \
|
if [ -f /opt/drupal/vendor/drush/drush/drush ]; then chmod a+rx /opt/drupal/vendor/drush/drush/drush; fi; \
|
||||||
# Ensure the docroot (/opt/drupal/web) is accessible
|
# Ensure the docroot ({{ DRUPAL_DOCKER_HTML_PATH }}) is accessible
|
||||||
if [ -d /opt/drupal/web ]; then \
|
if [ -d {{ DRUPAL_DOCKER_HTML_PATH }} ]; then \
|
||||||
chmod 755 /opt/drupal/web; \
|
chmod 755 {{ DRUPAL_DOCKER_HTML_PATH }}; \
|
||||||
find /opt/drupal/web -type d -exec chmod 755 {} +; \
|
find {{ DRUPAL_DOCKER_HTML_PATH }} -type d -exec chmod 755 {} +; \
|
||||||
fi; \
|
fi; \
|
||||||
# Ensure settings.local.php exists and is owned by www-data
|
# Ensure settings.local.php exists and is owned by www-data
|
||||||
install -o www-data -g www-data -m 640 /dev/null /opt/drupal/web/sites/default/settings.local.php
|
install -o www-data -g www-data -m 640 /dev/null {{ DRUPAL_DOCKER_HTML_PATH }}/sites/default/settings.local.php
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# Runtime defaults
|
# Runtime defaults
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
USER www-data
|
USER www-data
|
||||||
WORKDIR /var/www/html # symlink pointing to /opt/drupal/web
|
WORKDIR /var/www/html # symlink pointing to {{ DRUPAL_DOCKER_HTML_PATH }}
|
||||||
|
|
||||||
|
# Ensure PATH for non-login shells includes /usr/local/bin
|
||||||
|
ENV PATH="/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# Build-time check (optional)
|
# Build-time check (optional)
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
RUN drush --version
|
RUN /usr/local/bin/drush --version
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:{{ ports.localhost.http[application_id] }}:80"
|
- "127.0.0.1:{{ ports.localhost.http[application_id] }}:80"
|
||||||
volumes:
|
volumes:
|
||||||
- data:/var/www/html/web/sites/default/files
|
- data:{{ DRUPAL_DOCKER_HTML_PATH }}/sites/default/files
|
||||||
- {{ DRUPAL_MSMTP_ABS }}:/etc/msmtprc
|
- {{ DRUPAL_MSMTP_ABS }}:/etc/msmtprc
|
||||||
- {{ DRUPAL_SETTINGS_LOCAL_ABS }}:{{ DRUPAL_DOCKER_CONF_PATH }}/settings.local.php
|
- {{ DRUPAL_SETTINGS_LOCAL_ABS }}:{{ DRUPAL_DOCKER_CONF_PATH }}/settings.local.php
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ database_type: "mariadb"
|
|||||||
|
|
||||||
DRUPAL_URL: "{{ domains | get_url(application_id, WEB_PROTOCOL) }}"
|
DRUPAL_URL: "{{ domains | get_url(application_id, WEB_PROTOCOL) }}"
|
||||||
DRUPAL_CUSTOM_IMAGE: "drupal_custom"
|
DRUPAL_CUSTOM_IMAGE: "drupal_custom"
|
||||||
DRUPAL_DOCKER_HTML_PATH: "/var/www/html"
|
DRUPAL_DOCKER_HTML_PATH: "/opt/drupal/web"
|
||||||
DRUPAL_DOCKER_CONF_PATH: "/var/www/html/sites/default"
|
DRUPAL_DOCKER_CONF_PATH: "{{ DRUPAL_DOCKER_HTML_PATH }}/sites/default"
|
||||||
DRUPAL_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.drupal.version') }}"
|
DRUPAL_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.drupal.version') }}"
|
||||||
DRUPAL_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.drupal.image') }}"
|
DRUPAL_IMAGE: "{{ applications | get_app_conf(application_id, 'docker.services.drupal.image') }}"
|
||||||
DRUPAL_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.drupal.name') }}"
|
DRUPAL_CONTAINER: "{{ applications | get_app_conf(application_id, 'docker.services.drupal.name') }}"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ oidc_settings:
|
|||||||
oidc_client:
|
oidc_client:
|
||||||
id: "keycloak"
|
id: "keycloak"
|
||||||
label: "Keycloak"
|
label: "Keycloak"
|
||||||
|
plugin: "generic" # use the built-in generic OIDC client plugin
|
||||||
settings:
|
settings:
|
||||||
client_id: "{{ OIDC.CLIENT.ID }}"
|
client_id: "{{ OIDC.CLIENT.ID }}"
|
||||||
client_secret: "{{ OIDC.CLIENT.SECRET }}"
|
client_secret: "{{ OIDC.CLIENT.SECRET }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user