mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-11-04 04:08:15 +00:00 
			
		
		
		
	sys-svc-rdbms: Refactor database service templates and add version support for Magento
- Unified Jinja2 variable spacing in tasks and templates
- Introduced database_image and database_version variables in vars/database.yml
- Updated mariadb.yml.j2 and postgres.yml.j2 to use {{ database_image }}:{{ database_version }}
- Ensured env file paths and includes are consistent
- Prepared support for versioned database images (needed for Magento deployment)
Ref: https://chatgpt.com/share/68b96a9d-c100-800f-856f-cd23d1eda2ed
			
			
This commit is contained in:
		@@ -8,10 +8,10 @@
 | 
			
		||||
      path: "{{ docker_compose.directories.env }}"
 | 
			
		||||
      state: directory
 | 
			
		||||
      mode: "0755"
 | 
			
		||||
  - name: "For '{{ application_id }}': Create {{database_env}}"
 | 
			
		||||
  - name: "For '{{ application_id }}': Create {{ database_env }}"
 | 
			
		||||
    template: 
 | 
			
		||||
      src: "env/{{database_type}}.env.j2"
 | 
			
		||||
      dest: "{{database_env}}"
 | 
			
		||||
      src: "env/{{ database_type }}.env.j2"
 | 
			
		||||
      dest: "{{ database_env }}"
 | 
			
		||||
    notify: docker compose up
 | 
			
		||||
  when: not applications | get_app_conf(application_id, 'features.central_database', False)
 | 
			
		||||
 | 
			
		||||
@@ -19,7 +19,7 @@
 | 
			
		||||
  # I don't know why this includes leads to that the application_id in vars/main.yml of the database role isn't used
 | 
			
		||||
  # This is the behaviour which I want, but I'm still wondering why ;)
 | 
			
		||||
  include_role:
 | 
			
		||||
    name: "svc-db-{{database_type}}"
 | 
			
		||||
    name: "svc-db-{{ database_type }}"
 | 
			
		||||
  when: applications | get_app_conf(application_id, 'features.central_database', False)
 | 
			
		||||
 | 
			
		||||
- name: "For '{{ application_id }}': Add Entry for Backup Procedure"
 | 
			
		||||
 
 | 
			
		||||
@@ -5,10 +5,10 @@
 | 
			
		||||
    container_name: {{ application_id | get_entity_name }}-database
 | 
			
		||||
    logging:
 | 
			
		||||
      driver: journald
 | 
			
		||||
    image: mariadb
 | 
			
		||||
    image: {{ database_image }}:{{ database_version }}
 | 
			
		||||
    restart: {{ DOCKER_RESTART_POLICY }}
 | 
			
		||||
    env_file:
 | 
			
		||||
      - {{database_env}}
 | 
			
		||||
      - {{ database_env }}
 | 
			
		||||
    command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW"
 | 
			
		||||
    volumes:
 | 
			
		||||
      - database:/var/lib/mysql
 | 
			
		||||
 
 | 
			
		||||
@@ -2,13 +2,13 @@
 | 
			
		||||
 | 
			
		||||
{% if not applications | get_app_conf(application_id, 'features.central_database', False) %}  
 | 
			
		||||
  {{ database_host }}:
 | 
			
		||||
    image: postgres:{{ applications['svc-db-postgres'].version}}-alpine
 | 
			
		||||
    image: {{ database_image }}:{{ database_version }}
 | 
			
		||||
    container_name: {{ application_id | get_entity_name }}-database
 | 
			
		||||
    env_file:
 | 
			
		||||
      - {{database_env}}
 | 
			
		||||
      - {{ database_env }}
 | 
			
		||||
    restart: {{ DOCKER_RESTART_POLICY }}
 | 
			
		||||
    healthcheck:
 | 
			
		||||
      test: ["CMD-SHELL", "pg_isready -U {{ database_name }}"]
 | 
			
		||||
      test: ["CMD-SHELL", "pg_isready -U {{ database_user }}"]
 | 
			
		||||
      interval: 10s
 | 
			
		||||
      timeout: 5s
 | 
			
		||||
      retries: 6
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ _database_central_name:           "{{ (applications | get_app_conf(_database_id,
 | 
			
		||||
_database_consumer_id:              "{{ database_application_id | d(application_id) }}"
 | 
			
		||||
_database_consumer_entity_name:     "{{ _database_consumer_id | get_entity_name }}"
 | 
			
		||||
_database_central_enabled:          "{{ (applications | get_app_conf(_database_consumer_id, 'features.central_database', False)) if _dbtype else False }}"
 | 
			
		||||
_database_default_version:          "{{ applications | get_app_conf(_database_id, 'docker.services.' ~ _dbtype ~ '.version') }}"
 | 
			
		||||
 | 
			
		||||
# Definition
 | 
			
		||||
 | 
			
		||||
@@ -18,3 +19,5 @@ database_env:       "{{ docker_compose.directories.env }}{{ database_type }}.env
 | 
			
		||||
database_url_jdbc:      "jdbc:{{ database_type if database_type == 'mariadb' else 'postgresql' }}://{{ database_host }}:{{ database_port }}/{{ database_name }}"
 | 
			
		||||
database_url_full:      "{{ database_type }}://{{ database_username }}:{{ database_password }}@{{ database_host }}:{{ database_port }}/{{ database_name }}"
 | 
			
		||||
database_volume:        "{{ _database_consumer_entity_name ~ '_' if not _database_central_enabled }}{{ database_host }}"
 | 
			
		||||
database_image:         "{{ _dbtype }}"
 | 
			
		||||
database_version:       "{{ applications | get_app_conf( _database_consumer_id, 'docker.services.' ~ _dbtype ~ '.version', False, _database_default_version) }}"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user