From 1d887d3278ec6d3b22341042f1cc802a6d5bbf20 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 8 Dec 2023 00:34:48 +0100 Subject: [PATCH] implemented discourse draft --- playbook-servers.yml | 9 ++ roles/docker-discourse/README.md | 0 roles/docker-discourse/handlers/main.yml | 12 ++ roles/docker-discourse/meta/main.yml | 2 + roles/docker-discourse/tasks/main.yml | 53 +++++++++ roles/docker-discourse/templates/app.yml.j2 | 109 ++++++++++++++++++ .../templates/docker-compose.yml.j2 | 34 ++++++ roles/docker-discourse/vars/main.yml | 1 + 8 files changed, 220 insertions(+) create mode 100644 roles/docker-discourse/README.md create mode 100644 roles/docker-discourse/handlers/main.yml create mode 100644 roles/docker-discourse/meta/main.yml create mode 100644 roles/docker-discourse/tasks/main.yml create mode 100644 roles/docker-discourse/templates/app.yml.j2 create mode 100644 roles/docker-discourse/templates/docker-compose.yml.j2 create mode 100644 roles/docker-discourse/vars/main.yml diff --git a/playbook-servers.yml b/playbook-servers.yml index 59b1eb67..a6b99990 100644 --- a/playbook-servers.yml +++ b/playbook-servers.yml @@ -202,6 +202,15 @@ domain: listmonk.{{top_domain}} http_port: 8019 +- name: setup discourse + hosts: discourse + become: true + roles: + - role: docker-discourse + vars: + domain: discourse.{{top_domain}} + http_port: 8020 + - name: setup akaunting hosts hosts: akaunting become: true diff --git a/roles/docker-discourse/README.md b/roles/docker-discourse/README.md new file mode 100644 index 00000000..e69de29b diff --git a/roles/docker-discourse/handlers/main.yml b/roles/docker-discourse/handlers/main.yml new file mode 100644 index 00000000..b9d8cc4e --- /dev/null +++ b/roles/docker-discourse/handlers/main.yml @@ -0,0 +1,12 @@ +--- +#- name: recreate discourse +# command: +# cmd: docker-compose up -d --force-recreate +# chdir: "{{docker_compose_instance_directory}}" +# environment: +# COMPOSE_HTTP_TIMEOUT: 600 +# DOCKER_CLIENT_TIMEOUT: 600 +- name: recreate discourse + command: + cmd: ./launcher rebuild app + chdir: "{{docker_compose_instance_directory}}" diff --git a/roles/docker-discourse/meta/main.yml b/roles/docker-discourse/meta/main.yml new file mode 100644 index 00000000..d3606e63 --- /dev/null +++ b/roles/docker-discourse/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: +- nginx-docker-reverse-proxy diff --git a/roles/docker-discourse/tasks/main.yml b/roles/docker-discourse/tasks/main.yml new file mode 100644 index 00000000..c047f7db --- /dev/null +++ b/roles/docker-discourse/tasks/main.yml @@ -0,0 +1,53 @@ +--- +- name: "include tasks nginx-docker-proxy-domain.yml" + include_tasks: nginx-docker-proxy-domain.yml + +- name: "create {{docker_compose_instance_directory}}" + file: + path: "{{docker_compose_instance_directory}}" + state: directory + mode: 0755 + +#- name: add docker-compose.yml +# template: src=docker-compose.yml.j2 dest={{docker_compose_instance_directory}}docker-compose.yml +# notify: recreate discourse + +- name: register directory + stat: + path: "{{docker_compose_instance_directory}}" + register: docker_compose_instance_directory_register + +- name: checkout repository + ansible.builtin.shell: git checkout . + become: true + args: + chdir: "{{docker_compose_instance_directory}}" + when: docker_compose_instance_directory_register.stat.exists + +- name: pull docker repository + git: + repo: "https://github.com/discourse/discourse_docker.git" + dest: "{{docker_compose_instance_directory}}" + update: yes + notify: recreate discourse + become: true + register: git_result + ignore_errors: true + +- name: Warn if repo is not reachable + debug: + msg: "Warning: Repository is not reachable." + when: git_result.failed + +- name: set chmod 700 for {{docker_compose_instance_directory}}/containers + ansible.builtin.file: + path: "{{docker_compose_instance_directory}}/containers" + mode: '700' + state: directory + +- name: copy configuration + template: + src: app.yml.j2 + dest: "{{docker_compose_instance_directory}}/containers/app.yml" + force: no + notify: recreate discourse \ No newline at end of file diff --git a/roles/docker-discourse/templates/app.yml.j2 b/roles/docker-discourse/templates/app.yml.j2 new file mode 100644 index 00000000..7a97751d --- /dev/null +++ b/roles/docker-discourse/templates/app.yml.j2 @@ -0,0 +1,109 @@ +## this is the all-in-one, standalone Discourse Docker container template +## +## After making changes to this file, you MUST rebuild +## /var/discourse/launcher rebuild app +## +## BE *VERY* CAREFUL WHEN EDITING! +## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT! +## visit http://www.yamllint.com/ to validate this file as needed + +templates: + - "templates/postgres.template.yml" + - "templates/redis.template.yml" + - "templates/web.template.yml" + ## Uncomment the next line to enable the IPv6 listener + #- "templates/web.ipv6.template.yml" + - "templates/web.ratelimited.template.yml" + ## Uncomment these two lines if you wish to add Lets Encrypt (https) + #- "templates/web.ssl.template.yml" + #- "templates/web.letsencrypt.ssl.template.yml" + +## which TCP/IP ports should this container expose? +## If you want Discourse to share a port with another webserver like Apache or nginx, +## see https://meta.discourse.org/t/17247 for details +expose: + - "127.0.0.1:{{http_port}}:80" # http + #- "443:443" # https + +params: + db_default_text_search_config: "pg_catalog.english" + + ## Set db_shared_buffers to a max of 25% of the total memory. + ## will be set automatically by bootstrap based on detected RAM, or you can override + db_shared_buffers: "4096MB" + + ## can improve sorting performance, but adds memory usage per-connection + #db_work_mem: "40MB" + + ## Which Git revision should this container use? (default: tests-passed) + #version: tests-passed + +env: + LC_ALL: en_US.UTF-8 + LANG: en_US.UTF-8 + LANGUAGE: en_US.UTF-8 + # DISCOURSE_DEFAULT_LOCALE: en + + ## How many concurrent web requests are supported? Depends on memory and CPU cores. + ## will be set automatically by bootstrap based on detected CPUs, or you can override + UNICORN_WORKERS: 8 + + ## TODO: The domain name this Discourse instance will respond to + ## Required. Discourse will not work with a bare IP number. + DISCOURSE_HOSTNAME: localhost + + ## Uncomment if you want the container to be started with the same + ## hostname (-h option) as specified above (default "$hostname-$config") + #DOCKER_USE_HOSTNAME: true + + ## TODO: List of comma delimited emails that will be made admin and developer + ## on initial signup example 'user1@example.com,user2@example.com' + DISCOURSE_DEVELOPER_EMAILS: {{administrator_email}} + + ## TODO: The SMTP mail server used to validate new accounts and send notifications + # SMTP ADDRESS, username, and password are required + # WARNING the char '#' in SMTP password can cause problems! + DISCOURSE_SMTP_ADDRESS: {{system_email_domain}} + DISCOURSE_SMTP_PORT: 587 + DISCOURSE_SMTP_USER_NAME: {{system_email}} + DISCOURSE_SMTP_PASSWORD: {{system_email_password}} + DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true) + DISCOURSE_SMTP_DOMAIN: {{system_email_domain}} + DISCOURSE_NOTIFICATION_EMAIL: {{system_email}} + + ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate + #LETSENCRYPT_ACCOUNT_EMAIL: administrator@veen.world + + ## The http or https CDN address for this Discourse instance (configured to pull) + ## see https://meta.discourse.org/t/14857 for details + #DISCOURSE_CDN_URL: https://discourse-cdn.example.com + + ## The maxmind geolocation IP address key for IP address lookup + ## see https://meta.discourse.org/t/-/137387/23 for details + #DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456 + +## The Docker container is stateless; all data is stored in /shared +volumes: + - volume: + host: /var/discourse/shared/standalone + guest: /shared + - volume: + host: /var/discourse/shared/standalone/log/var-log + guest: /var/log + +## Plugins go here +## see https://meta.discourse.org/t/19157 for details +hooks: + after_code: + - exec: + cd: $home/plugins + cmd: + - git clone https://github.com/discourse/docker_manager.git + +## Any custom commands to run after building +run: + - exec: echo "Beginning of custom commands" + ## 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'" + - exec: echo "End of custom commands" diff --git a/roles/docker-discourse/templates/docker-compose.yml.j2 b/roles/docker-discourse/templates/docker-compose.yml.j2 new file mode 100644 index 00000000..d0fe2d93 --- /dev/null +++ b/roles/docker-discourse/templates/docker-compose.yml.j2 @@ -0,0 +1,34 @@ +version: '3' + +services: + discourse: + image: discourse/base:release + depends_on: + - database + - redis + volumes: + - data:/shared + environment: + DISCOURSE_DB_HOST: database + DISCOURSE_DB_NAME: discourse + DISCOURSE_DB_USERNAME: discourse + DISCOURSE_DB_PASSWORD: {{discourse_database_password}} + DISCOURSE_REDIS_HOST: redis + ports: + - "127.0.0.1:{{http_port}}:80" + database: + image: postgres:latest + environment: + POSTGRES_DB: discourse + POSTGRES_USER: discourse + POSTGRES_PASSWORD: {{discourse_database_password}} + volumes: + - database:/var/lib/postgresql/data + redis: + image: redis:latest + volumes: + - redis_data:/data +volumes: + database: + data: + redis_data: \ No newline at end of file diff --git a/roles/docker-discourse/vars/main.yml b/roles/docker-discourse/vars/main.yml new file mode 100644 index 00000000..024b3cfb --- /dev/null +++ b/roles/docker-discourse/vars/main.yml @@ -0,0 +1 @@ +docker_compose_instance_directory: "{{path_docker_compose_instances}}discourse/"