-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_stack.yml
78 lines (72 loc) · 3.29 KB
/
generate_stack.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# SPDX-License-Identifier: AGPL-3.0-only
#
# Komponist - Generate Your Favourite Compose Stack With the Least Effort
#
# Copyright (C) 2023 Shantanoo "Shan" Desai <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# generate-stack.yml: Ansible Playbook that generates Komponist Stack Files
---
- name: Komponist Stack Generation Playbook
hosts: localhost
vars_files:
- vars/config.yml
- vars/creds.yml
tasks:
- name: "(KOMPONIST) Generating Directory for Production-Ready Files"
ansible.builtin.file:
name: "{{ komponist.deploy_dir }}"
state: directory
mode: "0755"
- name: "(KOMPONIST) Generating Configuration / Compose Files from Templates"
ansible.builtin.include_tasks: "tasks/configure-{{ item }}.yml"
with_items:
- "{{ komponist.configuration.keys() }}"
- name: "(KOMPONIST) Validation and Generation of docker-compose.yml"
block:
- name: "(DockerCompose) Validating Docker Compose Services"
ansible.builtin.command:
cmd: docker compose {{ compose_files }} config --no-interpolate --no-path-resolution --quiet
args:
chdir: "{{ komponist.deploy_dir }}"
vars:
compose_files: >-
{{ komponist.configuration.keys() | map('regex_replace', '^(.*)$', ' -f docker-compose.\1.yml') | join | trim }}
register: docker_compose_validity
changed_when: docker_compose_validity.rc != 0
- name: "(DockerCompose) Generating docker-compose.yml file if all services are valid"
ansible.builtin.command:
cmd: >
docker compose -p {{ komponist.configuration.project_name | default('komponist') }} {{ compose_files }} config
--no-interpolate
--no-path-resolution
-o docker-compose.yml
args:
chdir: "{{ komponist.deploy_dir }}"
vars:
compose_files: >-
{{ komponist.configuration.keys() | map('regex_replace', '^(.*)$', ' -f docker-compose.\1.yml') | join | trim }}
changed_when: docker_compose_validity.rc != 0
- name: "(KOMPONIST) Update the header for generated docker-compose.yml file"
ansible.builtin.blockinfile:
block: "{{ lookup('ansible.builtin.template', 'templates/license_header.txt.j2') }}"
path: "{{ komponist.deploy_dir }}/docker-compose.yml"
insertbefore: "BOF"
marker: ""
- name: "(KOMPONIST) Generating the .env file for the Project"
ansible.builtin.template:
src: config/komponist.env.j2
dest: "{{ komponist.deploy_dir }}/.env"
mode: "0755"