From 3c18ed01f2dd425fb20e252bc5ba70f09329510c Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sun, 3 Dec 2023 12:33:04 +0200 Subject: [PATCH] Add support for installing arbitrary packages in the customized container image Related to https://github.com/mother-of-all-self-hosting/ansible-role-nextcloud/pull/12 --- defaults/main.yml | 16 +++++++++++++++- tasks/validate_config.yml | 9 +++++++++ templates/customizations/Dockerfile.j2 | 14 ++------------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 4d4a05e..d2c4355 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -87,6 +87,8 @@ nextcloud_container_image_customizations_enabled: | nextcloud_container_image_customizations_php_imageick_installation_enabled or nextcloud_container_image_customizations_samba_enabled + or + nextcloud_container_image_customizations_packages_to_install | length > 0 ) }} @@ -97,12 +99,24 @@ nextcloud_container_image_customizations_enabled: | # https://github.com/nextcloud/server/issues/13099 # Tread wisely! nextcloud_container_image_customizations_php_imageick_installation_enabled: false -nextcloud_container_image_customizations_php_imageick_installation_package: "libmagickcore-6.q16-6-extra" +nextcloud_container_image_customizations_php_imageick_installation_packages: ['libmagickcore-6.q16-6-extra'] # Samba (SMB) support for Windows fileshares can be setup using the toggle below, which # installs the smbclient package per the example here https://github.com/nextcloud/docker/blob/master/.examples/dockerfiles/smb/apache/Dockerfile # Also see ../../templates/customizations/Dockerfile.j2 nextcloud_container_image_customizations_samba_enabled: false +nextcloud_container_image_customizations_samba_packages: ['procps', 'smbclient'] + +# A list of packages to install in the customized Nextcloud container image. +# To add your own, use `nextcloud_container_image_customizations_packages_to_install_custom` +nextcloud_container_image_customizations_packages_to_install: "{{ (nextcloud_container_image_customizations_packages_to_install_auto + nextcloud_container_image_customizations_packages_to_install_custom) | unique }}" +nextcloud_container_image_customizations_packages_to_install_auto: | + {{ + (nextcloud_container_image_customizations_php_imageick_installation_packages if nextcloud_container_image_customizations_php_imageick_installation_enabled else []) + + + (nextcloud_container_image_customizations_samba_packages if nextcloud_container_image_customizations_samba_enabled else []) + }} +nextcloud_container_image_customizations_packages_to_install_custom: [] # nextcloud_container_image_customizations_dockerfile_body_custom contains your custom Dockerfile steps # for building your customized Nextcloud image based on the original (upstream) image (`nextcloud_container_image`). diff --git a/tasks/validate_config.yml b/tasks/validate_config.yml index 4425ac3..48ade02 100644 --- a/tasks/validate_config.yml +++ b/tasks/validate_config.yml @@ -14,6 +14,15 @@ - nextcloud_database_username - nextcloud_database_password +- name: (Deprecation) Catch and report renamed Nextcloud variables + ansible.builtin.fail: + msg: >- + Your configuration contains a variable, which now has a different name. + Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`). + when: "vars | dict2items | selectattr('key', 'match', item.old) | list | items2dict" + with_items: + - {'old': 'nextcloud_container_image_customizations_php_imageick_installation_package', 'new': ''} + - when: nextcloud_container_labels_traefik_enabled | bool block: - name: Fail if required Nextcloud Traefik settings not defined diff --git a/templates/customizations/Dockerfile.j2 b/templates/customizations/Dockerfile.j2 index a57ff36..60f14e1 100644 --- a/templates/customizations/Dockerfile.j2 +++ b/templates/customizations/Dockerfile.j2 @@ -1,17 +1,7 @@ FROM {{ nextcloud_container_image }} -{% set packages_to_install = [] %} - -{% if nextcloud_container_image_customizations_php_imageick_installation_enabled %} -{% set packages_to_install = packages_to_install + [nextcloud_container_image_customizations_php_imageick_installation_package] %} -{% endif %} - -{% if nextcloud_container_image_customizations_samba_enabled %} -{% set packages_to_install = packages_to_install + ['procps', 'smbclient'] %} -{% endif %} - -{% if packages_to_install | length > 0 %} -RUN apt -y update && apt -y install {{ packages_to_install | join(' ') }} && rm -rf /var/lib/apt/lists/* +{% if nextcloud_container_image_customizations_packages_to_install | length > 0 %} +RUN apt -y update && apt -y install {{ nextcloud_container_image_customizations_packages_to_install | join(' ') }} && rm -rf /var/lib/apt/lists/* {% endif %} {{ nextcloud_container_image_customizations_dockerfile_body_custom }}