From 16d04d3c6204a3279522492ebaa36c1532fbd4ce Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 5 Dec 2023 22:17:47 +0100 Subject: [PATCH] Updated role --- roles/docker-mybb/README.md | 43 +++++++++++++++++-- roles/docker-mybb/handlers/main.yml | 2 +- roles/docker-mybb/tasks/main.yml | 18 +++++--- .../templates/docker-compose.yml.j2 | 16 ++++--- roles/docker-mybb/vars/main.yml | 7 ++- 5 files changed, 65 insertions(+), 21 deletions(-) diff --git a/roles/docker-mybb/README.md b/roles/docker-mybb/README.md index 8aa00579..baa7c9ea 100644 --- a/roles/docker-mybb/README.md +++ b/roles/docker-mybb/README.md @@ -1,7 +1,42 @@ -# role mybb -## install plugins -Extract the plugins to /mnt. -Execute: +# Docker MyBB Role + +This README documents the Ansible role for setting up a MyBB forum using Docker. The role automates the deployment of MyBB, a free and open-source forum software, using Docker containers and manages the necessary configurations and dependencies. + +## Role Name: Docker MyBB + +### Dependencies +- nginx-docker-reverse-proxy + +### Variables +- `docker_compose_instance_directory`: The directory where Docker Compose files for MyBB are stored. +- `conf_d_docker_directory`: Directory for Docker Nginx configuration. +- `default_conf_server_file`: The default Nginx configuration file for the server. +- `conf_d_server_directory`: The Nginx server's configuration directory. + +### Tasks +1. **Domain Certificate Retrieval:** Automates the process of obtaining SSL certificates for the specified domain using Certbot. +2. **Nginx Configuration:** Handles the configuration of Nginx for the MyBB domain. +3. **Directory Creation:** Ensures the creation of necessary directories including parent directories as required. +4. **MyBB and Nginx Configuration:** Manages the configuration for MyBB and Nginx, including setting up the `default.conf` file. +5. **Docker Compose Setup:** Adds and manages the `docker-compose.yml` file necessary for running MyBB with Docker. + +### Usage + +#### Install Plugins +To install MyBB plugins, extract them to a mounted volume and sync using the provided `docker run` command ```bash docker run --rm -v mybb-data:/target/ -v /mnt/:/origin/ "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv /origin/inc/plugins/ /target/" ``` + +#### Running the Role +Execute the Ansible playbook containing this role to set up MyBB in a Docker environment. + +### Docker Compose Configuration +The `docker-compose.yml.j2` template outlines the services required for MyBB, including the application server, Nginx web server, and database (MariaDB). + +### Additional Information +- For detailed configuration and customization, refer to the contents of the `default.conf` template and the `docker-compose.yml.j2` template. +- Ensure that the environment variables and paths are correctly set as per your system's configuration. + +### Created with ChatGPT +This README was created with the assistance of ChatGPT, based on a conversation held at this [link](https://chat.openai.com/share/83828f9a-b817-48d8-86ed-599f64850b4d). ChatGPT provided guidance on structuring this document and outlining the key components of the Docker MyBB role. \ No newline at end of file diff --git a/roles/docker-mybb/handlers/main.yml b/roles/docker-mybb/handlers/main.yml index b6b70804..dab482fc 100644 --- a/roles/docker-mybb/handlers/main.yml +++ b/roles/docker-mybb/handlers/main.yml @@ -2,7 +2,7 @@ - name: recreate mybb command: cmd: docker-compose -p mybb up -d --force-recreate - chdir: "{{path_docker_compose_files}}mybb/" + chdir: "{{docker_compose_instance_directory}}" environment: COMPOSE_HTTP_TIMEOUT: 600 DOCKER_CLIENT_TIMEOUT: 600 diff --git a/roles/docker-mybb/tasks/main.yml b/roles/docker-mybb/tasks/main.yml index ca91da95..53a1555f 100644 --- a/roles/docker-mybb/tasks/main.yml +++ b/roles/docker-mybb/tasks/main.yml @@ -3,20 +3,26 @@ command: certbot certonly --agree-tos --email {{administrator_email}} --non-interactive --webroot -w /var/lib/letsencrypt/ -d {{domain}} - name: configure {{domain}}.conf - template: src=roles/nginx-docker-reverse-proxy/templates/domain.conf.j2 dest=/etc/nginx/conf.d/{{domain}}.conf + template: + src: "roles/nginx-docker-reverse-proxy/templates/domain.conf.j2" + dest: "/etc/nginx/conf.d/{{domain}}.conf" notify: restart nginx -- name: create data folder +- name: "create {{conf_d_docker_directory}} and parent directories" file: - path: "{{conf_d_docker_path}}" + path: "{{conf_d_docker_directory}}" state: directory mode: 0755 + recurse: yes -- name: "create {{default_conf_docker_path}}" - template: src="default.conf" dest="{{default_conf_docker_path}}" +- name: "create {{default_conf_server_file}}" + template: + src: "default.conf" + dest: "{{default_conf_server_file}}" + notify: recreate mybb - name: add docker-compose.yml template: src: "docker-compose.yml.j2" dest: "{{docker_compose_instance_directory}}docker-compose.yml" - notify: recreate matomo + notify: recreate mybb diff --git a/roles/docker-mybb/templates/docker-compose.yml.j2 b/roles/docker-mybb/templates/docker-compose.yml.j2 index 4cfe692a..20e09031 100644 --- a/roles/docker-mybb/templates/docker-compose.yml.j2 +++ b/roles/docker-mybb/templates/docker-compose.yml.j2 @@ -1,14 +1,16 @@ services: application: - log_driver: journald + logging: + driver: journald image: mybb/mybb:latest restart: always links: - database volumes: - - mybb-data:/var/www/html + - data:/var/www/html server: - log_driver: journald + logging: + driver: journald links: - application image: nginx:mainline @@ -16,15 +18,17 @@ services: ports: - "127.0.0.1:{{http_port}}:80" volumes: - - "{{conf_d_docker_path}}:{{conf_d_path}}" - - "mybb-data:/var/www/html:ro" + - "{{conf_d_server_directory}}:{{conf_d_docker_directory}}:ro" + - "data:/var/www/html:ro" database: - log_driver: journald + logging: + driver: journald image: mariadb environment: MYSQL_DATABASE: "mybb" MYSQL_USER: "mybb" MYSQL_PASSWORD: "{{mybb_database_password}}" + MARIADB_ROOT_PASSWORD: "{{mybb_database_password}}" MARIADB_AUTO_UPGRADE: "1" volumes: - database:/var/lib/mysql diff --git a/roles/docker-mybb/vars/main.yml b/roles/docker-mybb/vars/main.yml index 9d9c42eb..36c875b8 100644 --- a/roles/docker-mybb/vars/main.yml +++ b/roles/docker-mybb/vars/main.yml @@ -1,6 +1,5 @@ --- docker_compose_instance_directory: "{{path_docker_compose_files}}mybb/" -conf_d_path: "/etc/nginx/conf.d/" -conf_d_docker_path: "/etc/docker/applications/mybb{{conf_d_path}}" -default_conf_docker_path: "{{conf_d_docker_path}}default.conf" - +conf_d_server_directory: "{{docker_compose_instance_directory}}conf.d/" +default_conf_server_file: "{{conf_d_docker_directory}}default.conf" +conf_d_docker_directory: "/etc/nginx/conf.d/" \ No newline at end of file