-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.yml
57 lines (53 loc) · 1.71 KB
/
build.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
---
- name: "Generate Dockerfiles and build container images"
hosts: "{{ target | default('all') }}"
gather_facts: true
vars:
build_dir: "../build"
tasks:
- name: "Import variable files"
ansible.builtin.include_vars:
file: "{{ lookup('ansible.builtin.first_found', params) }}"
vars:
params:
files:
- "{{ inventory_hostname }}.yml"
- "{{ build_image }}.yml"
paths:
- 'vars'
skip: false
- name: "Create build directory"
ansible.builtin.file:
path: "{{ build_dir }}/{{ build_image }}"
state: directory
mode: '0755'
- name: "Generate Dockerfile"
ansible.builtin.template:
src: Dockerfile.j2
dest: "{{ build_dir }}/{{ build_image }}/{{ inventory_hostname }}"
mode: '0644'
- name: "Generate image list per registry"
no_log: false
ansible.builtin.set_fact:
_images: "{{ _images | default([]) + [{'tag': tag, 'image': build_image} | combine(push_registries)] }}"
loop: "{{ build_tags }}"
loop_control:
loop_var: tag
vars:
_images: []
- name: "Build container images and push to registries"
no_log: true
containers.podman.podman_image:
name: "{{ item.name }}/{{ item.username }}/molecule-{{ item.image }}"
build:
file: "{{ build_dir }}/{{ build_image }}/{{ inventory_hostname }}"
force_rm: true
format: docker
force: true
path: "{{ build_dir }}/{{ build_image }}"
state: build
tag: "{{ item.tag }}"
push: true
username: "{{ item.username }}"
password: "{{ item.password }}"
loop: "{{ _images }}"