Compare commits

...

10 Commits

Author SHA1 Message Date
Corbin Bartsch
d68d96015e
Allow null values for labels and ports, convert to empty lists 2024-06-18 20:20:22 -04:00
Corbin Bartsch
df476f1c61
Add example usage to README 2024-06-18 20:19:12 -04:00
Corbin Bartsch
14a67f676b
Insert newline before fragment or image 2024-06-18 20:16:52 -04:00
Corbin Bartsch
4fc2d8547f
Attempt to fix newline before image templating 2024-06-18 20:16:52 -04:00
Corbin Bartsch
c8a2518b31
Replace tabs with spaces 2024-06-18 20:16:52 -04:00
Simon Caron
23ab24282c
Renamed network variable to docker_network 2024-06-18 20:16:51 -04:00
Simon Caron
effb62c3e6
Add Support for Networks String List 2024-06-18 20:16:51 -04:00
Simon Caron
ec7c196064
Add support for docker-compose networks & container network
Signed-off-by: Simon Caron <simon.caron.8@gmail.com>
2024-06-18 20:16:51 -04:00
Corbin Bartsch
5eca1af323
Add initial fragment support 2024-06-18 20:16:51 -04:00
Corbin Bartsch
e98f0e954e
Linting 2024-06-18 20:14:59 -04:00
8 changed files with 95 additions and 11 deletions

10
.ansible-lint Normal file
View File

@ -0,0 +1,10 @@
---
exclude_paths:
- .github/
- molecule/
warn_list:
- internal-error
# vi: ft=yaml

View File

@ -1,3 +1,4 @@
---
name: Release
on:
workflow_dispatch:
@ -9,7 +10,6 @@ env:
GALAXY_USERNAME: IronicBadger
jobs:
release:
name: Release
runs-on: ubuntu-latest
@ -29,4 +29,5 @@ jobs:
- name: Trigger a new import on Galaxy.
run: >-
ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }}
$(echo ${{ env.GALAXY_USERNAME }}) $(echo ${{ github.repository }} | cut -d/ -f2)
$(echo ${{ env.GALAXY_USERNAME }})
$(echo ${{ github.repository }} | cut -d/ -f2)

8
.yamllint Normal file
View File

@ -0,0 +1,8 @@
---
extends: default
ignore: |
.github/
# vi: ft=yaml

View File

@ -79,4 +79,21 @@ containers:
mem_limit: 128m
ports:
- "4242:4242"
- service_name: netbox
active: true
image: docker.io/netboxcommunity/netbox:v3.6-2.7.0
anchor: netbox
user: "unit:root"
- service_name: netbox-worker
active: true
fragment: netbox
command:
- /opt/netbox/venv/bin/python
- /opt/netbox/netbox/manage.py
- rqworker
- service_name: netbox-housekeeping
active: true
fragment: netbox
command:
- /opt/netbox/housekeeping.sh
```

View File

@ -1,4 +1,4 @@
---
docker_compose_generator_output_path: "~"
docker_compose_generator_uid: "1000"
docker_compose_generator_gid: "1000"
docker_compose_generator_gid: "1000"

View File

@ -1,9 +1,11 @@
---
galaxy_info:
role_name: docker_compose_generator
namespace: ironicbadger
author: Alex Kretzschmar
description: Create a docker-compose.yml file
issue_tracker_url: https://github.com/ironicbadger/ansible-role-create-users/issues
issue_tracker_url: "https://github.com/ironicbadger/\
ansible-role-create-users/issues"
license: GPLv2
min_ansible_version: 2.4
platforms:

View File

@ -1,12 +1,14 @@
---
- name: ensure destination for compose file exists
file:
- name: Ensure destination for compose file exists
ansible.builtin.file:
path: "{{ docker_compose_generator_output_path }}"
state: directory
mode: 0755
- name: write docker-compose file
template:
src: ../templates/docker-compose.yml.j2
- name: Write docker-compose file
ansible.builtin.template:
src: docker-compose.yml.j2
dest: "{{ docker_compose_generator_output_path }}/docker-compose.yml"
owner: "{{ docker_compose_generator_uid }}"
group: "{{ docker_compose_generator_gid }}"
group: "{{ docker_compose_generator_gid }}"
mode: 0644

View File

@ -3,8 +3,13 @@
services:
{% for container in containers %}
{% if container.active %}
{{ container.service_name }}:
{{ container.service_name }}:{% if container.anchor is defined %} &{{ container.anchor }}{% endif %}
{% if container.fragment is defined %}
<<: *{{ container.fragment }}
{% else %}
image: {{ container.image }}
{% endif %}
container_name: {{ container.container_name | default(container.service_name) }}
{% if container.extra_hosts is defined %}
extra_hosts:
@ -15,6 +20,24 @@ services:
{% if container.network_mode is defined %}
network_mode: {{ container.network_mode }}
{% endif %}
{% if container.networks is defined %}
networks:
{% if container.networks is iterable and (container.networks is not string and container.networks is not mapping) %}
{% for network in container.networks %}
- {{ network }}
{% endfor %}
{% else %}
{% for network, params in container.networks.items() %}
{{ network }}:
{% if params.aliases is defined %}
aliases:
{% for alias in params.aliases %}
- {{ alias }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if container.build is defined %}
build: {{ container.build }}
{% endif %}
@ -49,12 +72,19 @@ services:
{% endfor %}
{% endif %}
{% if container.labels is defined %}
{% if container.labels is none %}
labels: []
{% else %}
labels:
{% for label in container.labels %}
- {{ label }}
{% endfor %}
{% endif %}
{% endif %}
{% if container.ports is defined %}
{% if container.ports is none %}
ports: []
{% else %}
ports:
{% for port in container.ports %}
- {{ port }}
@ -200,3 +230,17 @@ services:
{% endif %}
{% endif %}
{% endfor %}
{% if docker_networks is defined %}
networks:
{% for network in docker_networks %}
{% if network.active %}
{{ network.network_name }}:
{% if network.external is defined %}
external: {{ network.external }}
{% endif %}
{% if network.driver is defined %}
driver: {{ network.driver }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}