Compare commits

...

7 Commits

8 changed files with 101 additions and 22 deletions

View File

@ -1,6 +1,6 @@
namespace: finallycoffee
name: nextcloud
version: 0.2.0
version: 0.3.0
readme: README.md
authors:
- Johanna Dorothea Reichmann <transcaffeine@finallycoffee.eu>

View File

@ -6,3 +6,9 @@ regardless of wether the `apache` or `fpm` docker image is used.
It provides various common (optimization) configuration options
and creates a user on the host which is mapped into the container,
so the host file permissions remain comprehensible.
## Configuration
- `nextcloud_socket_path`: Setting this (to, for example, `{{ nextcloud_basepath }}/socket`),
will make FPM listen on `{{ nextcloud_socket_path }}/nextcloud.sock` on the host, enabling
you to use FPM to interface with nextcloud.

View File

@ -9,6 +9,7 @@ nextcloud_data_path: "{{ nextcloud_basepath }}/data"
# Where user data like media, documents etc are persisted
nextcloud_storage_path: "{{ nextcloud_basepath }}/storage"
nextcloud_fpm_config_path: "{{ nextcloud_basepath }}/fpm-config"
#nextcloud_socket_path: "{{ nextcloud_basepath }}/socket"
nextcloud_background_job_mode: cron
@ -32,6 +33,7 @@ nextcloud_container_base_volumes:
- "{{ nextcloud_data_path }}:/var/www/html:z"
- "{{ nextcloud_fpm_config_path }}/opcache.ini:/usr/local/etc/php/conf.d/opcache-recommended.ini:z"
- "{{ nextcloud_fpm_config_path }}/fpm.ini:/usr/local/etc/php-fpm.d/www.conf:z"
- "{{ nextcloud_fpm_config_path }}/fpm-docker.ini:/usr/local/etc/php-fpm.d/zz-docker.conf:z"
- "{{ nextcloud_basepath }}/nextcloud-passwd:/etc/passwd:z"
- "{{ nextcloud_basepath }}/nextcloud-group:/etc/group:z"
nextcloud_container_extra_volumes: []

View File

@ -0,0 +1,30 @@
---
- name: Ensure {{ key }} is set to {{ value }}
block:
- name: Check value of {{ key }}
community.docker.docker_container_exec:
container: "{{ nextcloud_container_name }}"
command: "{{ nextcloud_occ_command }} config:{{ type }}:get {{ scope }} {{ entry }}"
user: "{{ nextcloud_user_info.uid }}"
tty: yes
register: nextcloud_current_config_entry
changed_when: false
- name: Set {{ key }} to {{ value }}
community.docker.docker_container_exec:
container: "{{ nextcloud_container_name }}"
command: "{{ nextcloud_occ_command }} config:{{ type }}:set {{ scope }} {{ entry }} --value={{ value }} -n"
user: "{{ nextcloud_user_info.uid }}"
tty: yes
when: nextcloud_current_config_entry.stdout != value
notify: restart-nextcloud
vars:
entry_path: "{{ key.split('.') }}"
type: "{{ entry_path | first }}"
scope: "{{ entry_path[1] if entry_path | length > 2 else '' }}"
entry: >-
{{
entry_path[1] if entry_path|length == 2 else
(entry_path[2:] | join(" "))
}}

View File

@ -7,6 +7,19 @@
system: yes
register: nextcloud_user_info
- name: Map nextcloud socket path if defined
set_fact:
nextcloud_paths: "{{ nextcloud_paths + [ socket_dir ] }}"
nextcloud_container_base_volumes: "{{ nextcloud_container_base_volumes + [ socket_map ] }}"
vars:
socket_dir:
path: "{{ nextcloud_socket_path }}"
mode: "0755"
owner: "{{ nextcloud_user_info.uid|default(nextcloud_user) }}"
group: "{{ nextcloud_user_info.uid|default(nextcloud_user) }}"
socket_map: "{{ nextcloud_socket_path }}:{{ nextcloud_container_php_socket_path }}:z"
when: nextcloud_socket_path is defined and nextcloud_socket_path is string
- name: Ensure nextcloud directories exist and have correct permissions
file:
path: "{{ item.path }}"
@ -43,6 +56,16 @@
notify:
- reload-nextcloud
- name: Template PHP FPM docker-specific configuration
template:
src: nextcloud-fpm-docker.ini.j2
dest: "{{ nextcloud_fpm_config_path }}/fpm-docker.ini"
mode: "0640"
owner: "root"
group: "root"
notify:
- reload-nextcloud
- name: Template modified /etc/passwd for nextcloud container
template:
src: nextcloud-passwd.j2
@ -85,7 +108,8 @@
notify:
- reload-systemd
- meta: flush_handlers
- name: Flush handlers now to ensure systemd can know about the timer before it's enabled
meta: flush_handlers
- name: Ensure docker container for nextcloud is running
docker_container:
@ -111,22 +135,10 @@
state: started
when: nextcloud_background_job_mode == 'cron'
- name: Check nextcloud background job mode
community.docker.docker_container_exec:
container: "{{ nextcloud_container_name }}"
command: "{{ nextcloud_occ_command }} config:app:get core backgroundjobs_mode"
user: "{{ nextcloud_user_info.uid }}"
tty: yes
register: nextcloud_current_backgroundjob_mode
# As nextcloud might still be starting, retry this task
retries: 5
delay: 5
changed_when: false
- name: Set nextcloud background job mode to {{ nextcloud_background_job_mode }}
community.docker.docker_container_exec:
container: "{{ nextcloud_container_name }}"
command: "{{ nextcloud_occ_command }} config:app:set core backgroundjobs_mode {{ nextcloud_background_job_mode }}"
user: "{{ nextcloud_user_info.uid }}"
tty: yes
when: nextcloud_current_backgroundjob_mode.stdout != nextcloud_background_job_mode
- name: Configure nextcloud
include_tasks:
file: configure-single-setting.yml
vars:
key: "{{ item.key | replace('[', '.') | replace(']', '.') }}"
value: "{{ item.value }}"
loop: "{{ lookup('ansible.utils.to_paths', nextcloud_config ) | dict2items }}"

View File

@ -0,0 +1,2 @@
[global]
daemonize = no

View File

@ -3,7 +3,14 @@
user = www-data
group = www-data
listen = 127.0.0.1:9000
{% if nextcloud_socket_path is defined and nextcloud_socket_path is string %}
listen = {{ nextcloud_container_php_socket_path }}/nextcloud.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
{% else %}
;listen = 0.0.0.0:9000
{% endif %}
pm = dynamic
pm.max_children = {{ nextcloud_fpm_max_children }}

View File

@ -25,4 +25,24 @@ nextcloud_container_base_environment_yaml: |+2
PHP_MEMORY_LIMIT: "{{ nextcloud_php_memory_limit }}"
PHP_UPLOAD_LIMIT: "{{ nextcloud_php_upload_limit }}"
nextcloud_config: "{{ nextcloud_base_config | from_yaml | combine(nextcloud_extra_config|default({}), recursive=True, list_merge='append') }}"
nextcloud_base_config: |+2
{% if nextcloud_database_type != 'sqlite' %}
system:
dbhost: "{{ nextcloud_database_host }}"
dbuser: "{{ nextcloud_database_user }}"
dbpassword: "{{ nextcloud_database_pass }}"
dbname: "{{ nextcloud_database_name }}"
dbtype: "{{ nextcloud_database_types[nextcloud_database_type] }}"
{% endif %}
app:
core:
backgroundjobs_mode: "{{ nextcloud_background_job_mode }}"
nextcloud_occ_command: "php occ"
nextcloud_container_php_socket_path: /var/run/php
nextcloud_database_types:
postgres: pgsql
mysql: mysql
mariadb: mysql
sqlite: sqlite3