diff --git a/roles/web-app-nextcloud/tasks/addons/integration_gitlab.yml b/roles/web-app-nextcloud/tasks/addons/integration_gitlab.yml index b91887219e..3bec48c98f 100644 --- a/roles/web-app-nextcloud/tasks/addons/integration_gitlab.yml +++ b/roles/web-app-nextcloud/tasks/addons/integration_gitlab.yml @@ -1,17 +1,9 @@ --- - name: 🔍 Resolve GitLab integration provisioning facts set_fact: - nextcloud_gl_container: "{{ lookup('config', 'web-app-gitlab', 'services.webservice.name') }}" nextcloud_gl_nc_base_url: "{{ lookup('tls', 'web-app-nextcloud', 'url.base') | regex_replace('/$', '') }}" changed_when: false -- name: 🔍 Probe whether the GitLab partner container is running - command: > # nocheck: container-exec-resolver this IS the bare-name partner probe gate, compose co-location - container inspect --type container -f '{% raw %}{{.State.Running}}{% endraw %}' {{ nextcloud_gl_container }} - register: integration_gitlab_partner_running - changed_when: false - failed_when: false - - name: 📖 Read persisted integration_gitlab OAuth client id shell: > {{ NEXTCLOUD_DOCKER_EXEC_OCC }} config:app:get integration_gitlab client_id @@ -28,9 +20,9 @@ no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" - name: 🔧 Provision the GitLab <-> Nextcloud OAuth coupling - include_tasks: "{{ [role_path, 'tasks/addons/integration_gitlab_provision.yml'] | path_join }}" + include_tasks: integration_gitlab_provision.yml when: >- - (integration_gitlab_partner_running.stdout | trim) == 'true' + IS_STACK_HOST | bool and ( (nextcloud_gl_client_id_current.stdout | trim) | length == 0 or (nextcloud_gl_client_secret_current.stdout | trim) | length == 0 diff --git a/roles/web-app-nextcloud/tasks/addons/integration_gitlab_provision.yml b/roles/web-app-nextcloud/tasks/addons/integration_gitlab_provision.yml index 8042c85024..ee2c0e8d87 100644 --- a/roles/web-app-nextcloud/tasks/addons/integration_gitlab_provision.yml +++ b/roles/web-app-nextcloud/tasks/addons/integration_gitlab_provision.yml @@ -1,23 +1,32 @@ --- +- name: "🔍 Resolve GitLab webservice hosting node + container id" + ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" + vars: + resolve_service_key: webservice + resolve_service_name: "{{ lookup('container_service', 'web-app-gitlab', 'webservice') }}" + resolve_output_prefix: NEXTCLOUD_GITLAB + resolve_compose_cid: "{{ NEXTCLOUD_GITLAB_CONTAINER_ADDRESS }}" + resolve_converge_retries: 120 + resolve_converge_delay: 5 + +- name: ⏳ Wait for the GitLab web endpoint + wait_for: + host: "{{ lookup('domain', 'web-app-gitlab') }}" + port: 80 + delay: 5 + timeout: "{{ lookup('timeout', 600) | int }}" + - name: 🔧 Provision the GitLab OAuth application for Nextcloud and capture credentials - ansible.builtin.command: - argv: - - container - - exec - - -i - - -e - - "NC_BASE_URL={{ nextcloud_gl_nc_base_url }}" - - -e - - "NC_REDIRECT_PATH=/apps/integration_gitlab/oauth-redirect" - - -e - - "NC_HAS_SECRET={{ nextcloud_gl_client_secret_current.stdout | trim }}" - - "{{ nextcloud_gl_container }}" # nocheck: container-exec-resolver runs only behind the bare-name partner probe gate, compose co-location - - /srv/gitlab/bin/rails - - runner - - -e - - production - - "-" + ansible.builtin.shell: + cmd: >- + container exec -i + -e 'NC_BASE_URL={{ nextcloud_gl_nc_base_url }}' + -e 'NC_REDIRECT_PATH=/apps/integration_gitlab/oauth-redirect' + -e 'NC_HAS_SECRET={{ nextcloud_gl_client_secret_current.stdout | trim }}' + {{ NEXTCLOUD_GITLAB_LOCAL_CID | quote }} + /srv/gitlab/bin/rails runner -e production - stdin: "{{ lookup('file', 'gitlab/provision_oauth_app.rb') }}" + delegate_to: "{{ NEXTCLOUD_GITLAB_HOST_NODE }}" register: nextcloud_gl_provision changed_when: "'CLIENT_ID=' in nextcloud_gl_provision.stdout" retries: 12 @@ -53,19 +62,13 @@ integration_gitlab client_id/client_secret app config to re-provision. - name: 🔐 Store integration_gitlab OAuth credentials Nextcloud-encrypted (ICrypto, lazy) - ansible.builtin.command: - argv: - - container - - exec - - -i - - -u - - "{{ NEXTCLOUD_DOCKER_USER }}" - - -e - - "NC_APP_ID=integration_gitlab" - - -e - - "NC_ENC_B64={{ {'client_id': nextcloud_gl_client_id, 'client_secret': nextcloud_gl_client_secret} | to_json | b64encode }}" - - "{{ NEXTCLOUD_CONTAINER }}" # nocheck: container-exec-resolver runs only behind the bare-name partner probe gate, compose co-location - - php + ansible.builtin.shell: + cmd: >- + container exec -i -u {{ NEXTCLOUD_DOCKER_USER }} + -e 'NC_APP_ID=integration_gitlab' + -e 'NC_ENC_B64={{ {'client_id': nextcloud_gl_client_id, 'client_secret': nextcloud_gl_client_secret} | to_json | b64encode }}' + {{ NEXTCLOUD_LOCAL_CID | quote }} + php stdin: "{{ lookup('file', 'set_encrypted_appconfig.php') }}" register: nextcloud_gl_enc_set changed_when: "'OK' in nextcloud_gl_enc_set.stdout" diff --git a/roles/web-app-nextcloud/vars/main.yml b/roles/web-app-nextcloud/vars/main.yml index 7e3ad575bb..a222d1c168 100644 --- a/roles/web-app-nextcloud/vars/main.yml +++ b/roles/web-app-nextcloud/vars/main.yml @@ -42,6 +42,7 @@ NEXTCLOUD_CONTAINER_ADDRESS: "{{ lookup('container_address', application_id, NEX NEXTCLOUD_OPENPROJECT_CONTAINER_ADDRESS: "{{ lookup('container_address', 'web-app-openproject', 'web') }}" NEXTCLOUD_ZAMMAD_CONTAINER_ADDRESS: "{{ lookup('container_address', 'web-app-zammad', 'railsserver') }}" +NEXTCLOUD_GITLAB_CONTAINER_ADDRESS: "{{ lookup('container_address', 'web-app-gitlab', 'webservice') }}" NEXTCLOUD_PROXY_SERVICE: "proxy" NEXTCLOUD_PROXY_CONTAINER: "{{ lookup('config', application_id, 'services.' ~ NEXTCLOUD_PROXY_SERVICE ~ '.name') }}"