mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 02:10:05 +00:00 
			
		
		
		
	Optimized docker handlers for espocrm and wordpress
This commit is contained in:
		
							
								
								
									
										1
									
								
								roles/cmp-docker-oauth2/defaults/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								roles/cmp-docker-oauth2/defaults/main.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| docker_compose_flush_handlers: false # Set to true in the vars/main.yml of the including role to autoflush after docker compose routine | ||||
| @@ -2,6 +2,8 @@ | ||||
| - name: "load docker, db and proxy for {{application_id}}" | ||||
|   include_role:  | ||||
|     name: cmp-db-docker-proxy | ||||
|   vars: | ||||
|     docker_compose_flush_handlers:  true | ||||
|  | ||||
| - name: Check if config.php exists in EspoCRM | ||||
|   command: docker exec --user root {{ espocrm_name }} test -f {{ espocrm_config_file }} | ||||
| @@ -15,7 +17,6 @@ | ||||
|  | ||||
| - name: Flush handlers to make DB available before password reset | ||||
|   meta: flush_handlers | ||||
|   when: docker_compose_flush_handlers | bool | ||||
|  | ||||
| - name: Set OIDC scopes in EspoCRM config (inside web container) | ||||
|   ansible.builtin.shell: | | ||||
|   | ||||
| @@ -1,10 +1,16 @@ | ||||
| # General | ||||
| application_id:                 "web-app-espocrm" | ||||
|  | ||||
| # Database | ||||
| database_type:                  "mariadb" | ||||
|  | ||||
| # Webserver | ||||
| location_ws:                        "/ws" | ||||
| ws_port:                        "{{ ports.localhost.websocket[application_id] }}" | ||||
| client_max_body_size:           "100m" | ||||
| vhost_flavour:                  "ws_generic" | ||||
| docker_compose_flush_handlers:  true | ||||
|  | ||||
| # Espocrm | ||||
| espocrm_version:                "{{ applications | get_app_conf(application_id, 'docker.services.espocrm.version', True) }}" | ||||
| espocrm_image:                  "{{ applications | get_app_conf(application_id, 'docker.services.espocrm.image', True) }}" | ||||
| espocrm_name:                   "{{ applications | get_app_conf(application_id, 'docker.services.espocrm.name', True) }}" | ||||
|   | ||||
| @@ -1,24 +1,24 @@ | ||||
| # The seeds need to be executed as root, because www-data isn't allowed to create files in the wordpress directory | ||||
|  | ||||
| - name: Update DB host in wp-config.php | ||||
| - name: Update DB host in {{ wordpress_config_file }} | ||||
|   command: > | ||||
|     docker exec --user root {{ wordpress_container }} | ||||
|     sed -i "s/define(\s*'DB_HOST'\s*,\s*'[^']*'\s*);/define( 'DB_HOST', '{{ database_host }}:{{ database_port }}' );/i" {{ wordpress_docker_conf_path }} | ||||
|   notify: docker compose restart | ||||
|  | ||||
| - name: Update DB name in wp-config.php | ||||
| - name: Update DB name in {{ wordpress_config_file }} | ||||
|   command: > | ||||
|     docker exec --user root {{ wordpress_container }} | ||||
|     sed -i "s/define(\s*'DB_NAME'\s*,\s*'[^']*'\s*);/define( 'DB_NAME', '{{ database_name }}' );/i" {{ wordpress_docker_conf_path }} | ||||
|   notify: docker compose restart | ||||
|  | ||||
| - name: Update DB user in wp-config.php | ||||
| - name: Update DB user in {{ wordpress_config_file }} | ||||
|   command: > | ||||
|     docker exec --user root {{ wordpress_container }} | ||||
|     sed -i "s/define(\s*'DB_USER'\s*,\s*'[^']*'\s*);/define( 'DB_USER', '{{ database_username }}' );/i" {{ wordpress_docker_conf_path }} | ||||
|   notify: docker compose restart | ||||
|  | ||||
| - name: Update DB password in wp-config.php | ||||
| - name: Update DB password in {{ wordpress_config_file }} | ||||
|   command: > | ||||
|     docker exec --user root {{ wordpress_container }} | ||||
|     sed -i "s/define(\s*'DB_PASSWORD'\s*,\s*'[^']*'\s*);/define( 'DB_PASSWORD', '{{ database_password }}' );/i" {{ wordpress_docker_conf_path }} | ||||
|   | ||||
| @@ -2,6 +2,8 @@ | ||||
| - name: "load docker and db for {{application_id}}" | ||||
|   include_role:  | ||||
|     name: cmp-db-docker | ||||
|   vars: | ||||
|     docker_compose_flush_handlers: false | ||||
|    | ||||
| - name: "Include role srv-proxy-6-6-domain for {{ application_id }}" | ||||
|   include_role: | ||||
| @@ -25,13 +27,16 @@ | ||||
|     dest: "{{ host_msmtp_conf }}" | ||||
|   notify: docker compose up | ||||
|  | ||||
| - name: Check if wp-config.php exists in WordPress | ||||
|   command: docker exec -u {{ wordpress_user }} {{ wordpress_container }} test -f {{ wordpress_docker_html_path }}/wp-config.php | ||||
| - name: Flush handlers to make {{ wordpress_config_file }} available before patch | ||||
|   meta: flush_handlers | ||||
|  | ||||
| - name: Check if {{ wordpress_config_file }} exists in WordPress | ||||
|   command: docker exec -u {{ wordpress_user }} {{ wordpress_container }} test -f {{ wordpress_config_path }} | ||||
|   register: wp_config_file_exists | ||||
|   changed_when: false | ||||
|   failed_when: false | ||||
|  | ||||
| - name: Patch WordPress wp-config.php with updated DB credentials | ||||
| - name: Patch WordPress {{ wordpress_config_file }} with updated DB credentials | ||||
|   include_tasks: 01_patch_config.yml | ||||
|   when: wp_config_file_exists.rc == 0 | ||||
|  | ||||
|   | ||||
| @@ -7,11 +7,13 @@ host_msmtp_conf:            "{{docker_compose.directories.config}}msmtprc.conf" | ||||
| wordpress_max_upload_size:  "{{ applications | get_app_conf(application_id, 'max_upload_size') }}" | ||||
| wordpress_custom_image:     "wordpress_custom" | ||||
| wordpress_docker_html_path: "/var/www/html" | ||||
| wordpress_docker_conf_path: "{{ wordpress_docker_html_path }}/wp-config.php" | ||||
| wordpress_docker_conf_path: "{{ wordpress_config_path }}" | ||||
| wordpress_version:          "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.version', True) }}" | ||||
| wordpress_image:            "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.image', True) }}" | ||||
| wordpress_container:        "{{ applications | get_app_conf(application_id, 'docker.services.wordpress.name', True) }}" | ||||
| wordpress_volume:           "{{ applications | get_app_conf(application_id, 'docker.volumes.data', True) }}" | ||||
| wordpress_domains:          "{{ applications | get_app_conf(application_id, 'server.domains.canonical', True) }}" | ||||
| wordpress_plugins:          "{{ applications | get_app_conf(application_id, 'plugins', True) | dict2items }}" | ||||
| wordpress_user:             "www-data" | ||||
| wordpress_user:             "www-data" | ||||
| wordpress_config_file:      "wp-config.php" | ||||
| wordpress_config_path:      "{{ wordpress_docker_html_path }}/{{ wordpress_config_file }}" | ||||
		Reference in New Issue
	
	Block a user