web-app-discourse: fix admin creation, pin repo version, add self-signed CA support

- Pin Discourse repository to configurable version instead of implicit HEAD
- Add TLS/self-signed CA env + volume injection to container config
- Make force_https depend on resolved TLS state
- Replace fragile printf-based admin creation with safe heredoc
- Ensure admin user creation works with arbitrary password characters
- Expose DISCOURSE_VERSION via role vars for reproducible deploys

https://chatgpt.com/share/6980a49e-3000-800f-b6a4-cb6a3e15a3d8
This commit is contained in:
kevinveenbirkenbach committed 2026-02-02 14:20:18 +01:00
1 parent a8191463a5
commit 63d12da368
4 files changed
+46 -12

No files matched your search

+2 -1
View File
@@ -36,9 +36,10 @@ docker:
redis:
backup:
disabled: true
enabled: true
enabled: true
discourse:
name: "discourse"
version: "v2026.2.0-latest"
image: "local_discourse/<< defaults_applications[web-app-discourse].docker.services.discourse.name >>" # Necessary to define this for the docker 2 loc backup
backup:
no_stop_required: true
+7 -6
View File
@@ -13,12 +13,13 @@
- name: pull docker repository
git:
repo: "{{ DISCOURSE_REPOSITORY_URL }}"
dest: "{{ DISCOURSE_REPOSITORY_DIR }}"
update: yes
depth: 1
notify: recreate discourse
become: true
repo: "{{ DISCOURSE_REPOSITORY_URL }}"
dest: "{{ DISCOURSE_REPOSITORY_DIR }}"
version: "{{ DISCOURSE_VERSION }}"
update: yes
depth: 1
notify: recreate discourse
become: true
ignore_errors: true
- name: set chmod 700 for '{{ DISCOURSE_CONTAINERS_DIR }}'
@@ -94,6 +94,11 @@ env:
## see https://meta.discourse.org/t/-/137387/23 for details
#DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456
{% if DISCOURSE_TLS_SELFSIGNED_ENABLED | bool %}
CA_TRUST_CERT: {{ CA_ROOT.cert_host }}
CA_TRUST_NAME: {{ domains | get_domain(application_id) }}
{% endif %}
## The Docker container is stateless; all data is stored in /shared
volumes:
- volume:
@@ -103,6 +108,15 @@ volumes:
host: /var/discourse/shared/standalone/log/var-log
guest: /var/log
{% if DISCOURSE_TLS_SELFSIGNED_ENABLED | bool %}
- volume:
host: {{ CA_ROOT.cert_host }}
guest: {{ CA_ROOT.cert_host }}
- volume:
host: {{ PATH_CA_TRUST }}
guest: {{ PATH_CA_TRUST }}
{% endif %}
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
@@ -123,7 +137,10 @@ hooks:
## Any custom commands to run after building
run:
- exec: echo "Beginning of custom commands"
- exec: rails r "SiteSetting.force_https = true"
- exec: rails r "SiteSetting.force_https = {{ DISCOURSE_TLS_ENABLED | bool | string | lower }}"
{% if DISCOURSE_TLS_SELFSIGNED_ENABLED | bool %}
- exec: {{ PATH_CA_TRUST }}
{% endif %}
## If you want to set the 'From' email address for your first registration, uncomment and change:
## After getting the first signup email, re-comment the line. It only needs to run once.
#- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
@@ -134,10 +151,6 @@ run:
- exec: rails r "SiteSetting.username_change_period = 0" # Deactivate changing of username
# Activate Administrator User
#- exec: printf '{{ users.administrator.email }}\n{{users.administrator.password}}\n{{users.administrator.password}}\nY\n' | rake admin:create
#- exec: rails r "User.find_by_email('{{ users.administrator.email }}').update(username: '{{users.administrator.username}}')"
# The following code is just an inspiration, how to connect with the oidc account. as long as this is not set the admini account needs to be manually connected with oidc
# docker exec -it {{ DISCOURSE_CONTAINER }} rails runner "user = User.find_by_email('test@infinito.nexus'); UserAuth.create(user_id: user.id, provider: 'oidc', uid: 'eindeutige_oidc_id', info: { name: user.username, email: user.email })"
@@ -151,6 +164,19 @@ run:
- exec: rails r "SiteSetting.openid_connect_rp_initiated_logout = true"
{% endif %}
# Activate Administrator User (always yes, non-interactive)
- exec: |
cat <<'EOF' | rake admin:create
{{ users.administrator.email }}
{{ users.administrator.password }}
{{ users.administrator.password }}
Y
Y
EOF
- exec: >
rails r "User.find_by_email('{{ users.administrator.email }}')&.update!(username: '{{ users.administrator.username }}')"
{% if DISCOURSE_LDAP_ENABLED | bool %}
# Enable LDAP authentication
- exec: rails r "SiteSetting.ldap_auth_enabled = true"
+6
View File
@@ -14,6 +14,7 @@ DISCOURSE_PLUGINS: "{{ applications | get_app_conf(application_
DISCOURSE_PG_NETWORK: "{{ applications | get_app_conf('svc-db-' ~ DISCOURSE_DATABASE_TYPE, 'docker.network' ) }}"
DISCOURSE_REDIS_HOST: "{{ application_id | get_entity_name }}-redis"
DISCOURSE_REPOSITORY_URL: "{{ applications | get_app_conf(application_id, 'docker.services.discourse.repository') }}"
DISCOURSE_VERSION: "{{ applications | get_app_conf(application_id, 'docker.services.discourse.version') }}"
## Directories
DISCOURSE_REPOSITORY_DIR: "{{ docker_compose.directories.services }}{{ applications | get_app_conf( application_id, 'repository') }}/"
@@ -33,3 +34,8 @@ DISCOURSE_LOCAL: "C.UTF-8"
DISCOURSE_OIDC_ENABLED: "{{ applications | get_app_conf(application_id, 'docker.services.oidc.enabled') }}"
DISCOURSE_OIDC_LOGOUT_REDIRECT_URL: "{{ lookup('tls_resolve', application_id, want='url.base') }}"
# TLS
DISCOURSE_TLS_ENABLED: "{{ lookup('tls_resolve', application_id, want='enabled') | bool }}"
DISCOURSE_TLS_SELFSIGNED: "{{ lookup('tls_resolve', application_id, want='mode') == 'self_signed' }}"
DISCOURSE_TLS_SELFSIGNED_ENABLED: "{{ ( DISCOURSE_TLS_ENABLED | bool ) and ( DISCOURSE_TLS_SELFSIGNED | bool ) }}"