From 8d2c481569d8fe900425da9d4b33e3843bc18319 Mon Sep 17 00:00:00 2001 From: Magnus Andersson Date: Wed, 24 Apr 2024 20:44:41 +0200 Subject: [PATCH 1/3] Frontend node: Use netork mode host with dockerhost2 --- manifests/app_type.pp | 3 +++ templates/application/config.php.erb | 4 ++++ templates/application/docker-compose_nextcloud.yml.erb | 5 +++++ templates/proxysql/docker-compose_proxysql.yml.erb | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/manifests/app_type.pp b/manifests/app_type.pp index e3ae1ec..f25ded7 100644 --- a/manifests/app_type.pp +++ b/manifests/app_type.pp @@ -60,6 +60,9 @@ define sunetdrive::app_type ( } else { $php_memory_limit_mb = 512 } + if $::facts['dockerhost2'] == 'yes' { + $hostnet = 'yes' + } # These are encrypted values from local.eyaml diff --git a/templates/application/config.php.erb b/templates/application/config.php.erb index 1ded59e..738e4c9 100644 --- a/templates/application/config.php.erb +++ b/templates/application/config.php.erb @@ -25,7 +25,11 @@ $CONFIG = array ( 'csrf.disabled' => true, 'datadirectory' => '/var/www/html/data', 'davstorage.request_timeout' => 86401, +<%- if @hostnet -%> + 'dbhost' => '127.0.0.1', +<%- else -%> 'dbhost' => '<%= @dbhost %>', +<%- end -%> 'dbname' => '<%= @dbname %>', 'dbpassword' => '<%= @mysql_user_password %>', 'dbport' => '3306', diff --git a/templates/application/docker-compose_nextcloud.yml.erb b/templates/application/docker-compose_nextcloud.yml.erb index d46b4e2..33c7572 100644 --- a/templates/application/docker-compose_nextcloud.yml.erb +++ b/templates/application/docker-compose_nextcloud.yml.erb @@ -6,6 +6,9 @@ services: image: docker.sunet.se/drive/nextcloud-custom:<%= @nextcloud_version %> restart: always container_name: nextcloud_app_1 +<%- if @hostnet -%> + network_mode: host +<%- end -%> environment: - NC_PASS=<%= @admin_password%> volumes: @@ -28,9 +31,11 @@ services: <% if @location =~ /^kau/ -%> - /mnt:/opt/tmp/ <%- end -%> +<%- if ! @hostnet -%> networks: - default - proxysql_proxysql +<%- end -%> dns: - 89.46.20.75 - 89.46.21.29 diff --git a/templates/proxysql/docker-compose_proxysql.yml.erb b/templates/proxysql/docker-compose_proxysql.yml.erb index 42ac263..30b5571 100644 --- a/templates/proxysql/docker-compose_proxysql.yml.erb +++ b/templates/proxysql/docker-compose_proxysql.yml.erb @@ -5,6 +5,9 @@ services: proxysql: image: docker.sunet.se/drive/proxysql:<%= @proxysql_version %> container_name: proxysql_proxysql_1 +<%- if @hostnet -%> + network_mode: host +<%- end -%> ports: - 3306:3306 - 6032:6032 @@ -15,8 +18,10 @@ services: - 89.46.20.75 - 89.46.21.29 - 89.32.32.32 +<%- if ! @hostnet -%> networks: - proxysql +<%- end -%> restart: unless-stopped volumes: - proxysql:/var/lib/proxysql @@ -26,6 +31,8 @@ services: volumes: proxysql: +<%- if @hostnet -%> networks: proxysql: driver: bridge +<%- end -%> From d5c6b9a5fd72cf9d4edeaa012f5f7106d382e591 Mon Sep 17 00:00:00 2001 From: Magnus Andersson Date: Wed, 24 Apr 2024 20:52:26 +0200 Subject: [PATCH 2/3] proxysql: Do not create docker network with network_mode: host --- templates/proxysql/docker-compose_proxysql.yml.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/proxysql/docker-compose_proxysql.yml.erb b/templates/proxysql/docker-compose_proxysql.yml.erb index 30b5571..7c39583 100644 --- a/templates/proxysql/docker-compose_proxysql.yml.erb +++ b/templates/proxysql/docker-compose_proxysql.yml.erb @@ -31,7 +31,7 @@ services: volumes: proxysql: -<%- if @hostnet -%> +<%- if ! @hostnet -%> networks: proxysql: driver: bridge From c774d677453a86c82feb51f527ea24c73babf7ec Mon Sep 17 00:00:00 2001 From: Magnus Andersson Date: Wed, 24 Apr 2024 21:32:25 +0200 Subject: [PATCH 3/3] App and proxysql: Fixes for network_type: host --- manifests/proxysql.pp | 3 +++ templates/application/docker-compose_nextcloud.yml.erb | 4 ++++ templates/proxysql/docker-compose_proxysql.yml.erb | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/manifests/proxysql.pp b/manifests/proxysql.pp index 1c2b7fb..fc45669 100644 --- a/manifests/proxysql.pp +++ b/manifests/proxysql.pp @@ -26,6 +26,9 @@ class sunetdrive::proxysql ( $mysql_user = safe_hiera('mysql_user') $transaction_persistent = 1 + if $::facts['dockerhost2'] == 'yes' { + $hostnet = 'yes' + } file { '/usr/local/bin/proxysql': ensure => file, diff --git a/templates/application/docker-compose_nextcloud.yml.erb b/templates/application/docker-compose_nextcloud.yml.erb index 33c7572..054ebe5 100644 --- a/templates/application/docker-compose_nextcloud.yml.erb +++ b/templates/application/docker-compose_nextcloud.yml.erb @@ -40,11 +40,15 @@ services: - 89.46.20.75 - 89.46.21.29 - 89.32.32.32 +<%- if !@hostnet -%> ports: - 443:443 +<%- end -%> command: sh -c 'tail -f /var/www/html/data/nextcloud.log | tee -a /proc/1/fd/2 & apachectl -D FOREGROUND' tty: true +<%- if !@hostnet -%> networks: proxysql_proxysql: external: true +<%- end -%> diff --git a/templates/proxysql/docker-compose_proxysql.yml.erb b/templates/proxysql/docker-compose_proxysql.yml.erb index 7c39583..6159526 100644 --- a/templates/proxysql/docker-compose_proxysql.yml.erb +++ b/templates/proxysql/docker-compose_proxysql.yml.erb @@ -7,18 +7,19 @@ services: container_name: proxysql_proxysql_1 <%- if @hostnet -%> network_mode: host -<%- end -%> +<%- else -%> ports: - 3306:3306 - 6032:6032 - 6080:6080 +<%- end -%> environment: INITIALIZE: 1 dns: - 89.46.20.75 - 89.46.21.29 - 89.32.32.32 -<%- if ! @hostnet -%> +<%- if !@hostnet -%> networks: - proxysql <%- end -%> @@ -31,7 +32,7 @@ services: volumes: proxysql: -<%- if ! @hostnet -%> +<%- if !@hostnet -%> networks: proxysql: driver: bridge