Skip to content

Commit da4b4d0

Browse files
refactor: use include spec for docker compose
instead of generating a compose file from `docker compose config` use the compose files as if they are headers and they are included in an entrypoint `compose.yml` file. adapt the jsonschema file for tests. closes #120 Signed-off-by: Shantanoo 'Shan' Desai <[email protected]>
1 parent 8ce9fbf commit da4b4d0

File tree

4 files changed

+954
-734
lines changed

4 files changed

+954
-734
lines changed

generate_stack.yml

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Komponist - Generate Your Favourite Compose Stack With the Least Effort
44
#
5-
# Copyright (C) 2023 Shantanoo "Shan" Desai <[email protected]>
5+
# Copyright (C) 2025 Shantanoo "Shan" Desai <[email protected]>
66
#
77
# This program is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU Affero General Public License as published
@@ -38,42 +38,29 @@
3838
with_items:
3939
- "{{ komponist.configuration.keys() }}"
4040

41-
- name: "(KOMPONIST) Validation and Generation of docker-compose.yml"
42-
block:
43-
- name: "(DockerCompose) Validating Docker Compose Services"
44-
ansible.builtin.command:
45-
cmd: docker compose {{ compose_files }} config --no-interpolate --no-path-resolution --quiet
46-
args:
47-
chdir: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}"
48-
vars:
49-
compose_files: >-
50-
{{ komponist.configuration.keys() | map('regex_replace', '^(.*)$', ' -f docker-compose.\1.yml') | join | trim }}
51-
register: docker_compose_validity
52-
changed_when: docker_compose_validity.rc != 0
41+
- name: "(KOMPONIST) Generating Entrypoint compose.yml file from Templates"
42+
ansible.builtin.template:
43+
src: templates/services/compose.yml.j2
44+
dest: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}/compose.yml"
45+
mode: "0644"
5346

54-
- name: "(DockerCompose) Generating docker-compose.yml file if all services are valid"
55-
ansible.builtin.command:
56-
cmd: >
57-
docker compose -p {{ komponist.configuration.project_name | default('komponist') }} {{ compose_files }} config
58-
--no-interpolate
59-
--no-path-resolution
60-
-o docker-compose.yml
61-
args:
62-
chdir: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}"
63-
vars:
64-
compose_files: >-
65-
{{ komponist.configuration.keys() | map('regex_replace', '^(.*)$', ' -f docker-compose.\1.yml') | join | trim }}
66-
changed_when: docker_compose_validity.rc != 0
47+
- name: "(KOMPONIST) Validating Docker Compose Services"
48+
ansible.builtin.command:
49+
cmd: docker compose config --no-interpolate --no-path-resolution --quiet
50+
args:
51+
chdir: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}"
52+
register: docker_compose_validity
53+
changed_when: docker_compose_validity.rc != 0
6754

68-
- name: "(KOMPONIST) Update the header for generated docker-compose.yml file"
69-
ansible.builtin.blockinfile:
70-
block: "{{ lookup('ansible.builtin.template', 'templates/license_header.txt.j2') }}"
71-
path: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}/docker-compose.yml"
72-
insertbefore: "BOF"
73-
marker: ""
55+
- name: "(KOMPONIST) Update the header for generated docker-compose.yml file"
56+
ansible.builtin.blockinfile:
57+
block: "{{ lookup('ansible.builtin.template', 'templates/license_header.txt.j2') }}"
58+
path: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}/compose.yml"
59+
insertbefore: "BOF"
60+
marker: ""
7461

75-
- name: "(KOMPONIST) Generating the .env file for the Project"
76-
ansible.builtin.template:
77-
src: config/komponist.env.j2
78-
dest: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}/.env"
79-
mode: "0644"
62+
- name: "(KOMPONIST) Generating the .env file for the Project"
63+
ansible.builtin.template:
64+
src: config/komponist.env.j2
65+
dest: "{{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}/.env"
66+
mode: "0644"

templates/services/compose.yml.j2

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-License-Identifier: AGPL-3.0-only
2+
#
3+
# Komponist - Generate Your Favourite Compose Stack With the Least Effort
4+
#
5+
# Copyright (C) 2025 Shantanoo "Shan" Desai <sdes[email protected]>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
{{ ansible_managed | comment }}
21+
22+
{# compose.yml.j2: Jinja2 Template for Main Compose Entrypoint File #}
23+
24+
name: {{ komponist.project_name | default('komponist') }}
25+
26+
include:
27+
{%for service in komponist.configuration.keys() %}
28+
- {{ komponist.deploy_dir | default(ansible_user_dir + '/.komponist') }}/docker-compose.{{ service }}.yml
29+
{% endfor %}

0 commit comments

Comments
 (0)