|
1 | 1 | ---
|
2 | 2 | - name: Create Dockerfile, images and build containers
|
3 | 3 | hosts: localhost
|
4 |
| - connection: local |
5 | 4 | gather_facts: false
|
6 | 5 | tasks:
|
7 | 6 | - name: Create Dockerfile
|
|
24 | 23 |
|
25 | 24 | - name: Build containers
|
26 | 25 | include_tasks: build_containers.yml
|
27 |
| - with_items: ['amd64', 'arm64'] |
| 26 | + with_items: "{{ dockerhub_image_architectures }}" |
28 | 27 |
|
29 | 28 |
|
30 | 29 | - name: Execute Java role in Docker containers
|
31 | 30 | hosts: jdk_containers
|
32 |
| - connection: local |
| 31 | + connection: localhost |
| 32 | + gather_facts: True |
33 | 33 | vars:
|
34 | 34 | - java_jdk_vendor: "{{ jdk_vendor if jdk_vendor is defined and jdk_vendor is not sameas None and jdk_vendor != '' else 'openjdk' }}"
|
35 | 35 | - java_open_jdk_version: "{{ jdk_version if jdk_version is defined and jdk_version is not sameas None and jdk_version != '' }}"
|
36 | 36 | - java_open_jdk_version_major: "{{ jdk_major if jdk_major is defined and jdk_major is not sameas None and jdk_major != ''}}"
|
37 |
| - roles: |
38 |
| - - java_role |
39 |
| - |
| 37 | + tasks: |
| 38 | + - name: Execute role |
| 39 | + include_tasks: execute_role.yml |
40 | 40 |
|
41 | 41 | - name: Deploy images to DockerHub
|
42 | 42 | hosts: localhost
|
43 | 43 | connection: local
|
44 |
| - gather_facts: false |
| 44 | + gather_facts: True |
45 | 45 | tasks:
|
46 | 46 |
|
| 47 | + - name: Check failed containers |
| 48 | + set_fact: |
| 49 | + failed_architectures: "{{ failed_architectures + [ item ] }}" |
| 50 | + with_items: "{{ groups['jdk_containers'] }}" |
| 51 | + when: "{{ hostvars[item]['failed_execution'] is defined and hostvars[item]['failed_execution'] == True }}" |
| 52 | + |
47 | 53 | - name: Deploy images
|
48 | 54 | include_tasks: deploy_images.yml
|
49 |
| - with_items: ['amd64', 'arm64'] |
| 55 | + with_items: "{{ dockerhub_image_architectures }}" |
50 | 56 |
|
51 | 57 |
|
52 | 58 | - name: Deploy multiarch manifest to DockerHub and cleanup
|
|
56 | 62 | tasks:
|
57 | 63 |
|
58 | 64 | - name: Create manifest
|
59 |
| - command: docker manifest create idealista/jdk:{{ docker_tag }} |
60 |
| - --amend idealista/jdk:{{ docker_tag + '-amd64' }} |
61 |
| - --amend idealista/jdk:{{ docker_tag + '-arm64' }} |
| 65 | + command: docker manifest create idealista/jdk:{{ docker_tag }} |
| 66 | + {% for architecture in dockerhub_image_architectures %} |
| 67 | + {% if failed_architectures is not defined or not failed_architectures | join('|') | regex_search(architecture) %} |
| 68 | + --amend idealista/jdk:{{ docker_tag + '-' + architecture }} |
| 69 | + {% endif %} |
| 70 | + {% endfor %} |
62 | 71 |
|
63 | 72 | - name: Push manifest
|
64 | 73 | command: docker manifest push idealista/jdk:{{ docker_tag }}
|
65 | 74 |
|
66 | 75 | - name: Delete builder
|
67 | 76 | command: docker buildx rm multiarch
|
| 77 | + |
| 78 | + - name: Example using fail and when together |
| 79 | + fail: |
| 80 | + msg: Atleast one of the architectures could not be uploaded see logs for more information. |
| 81 | + when: failed_architectures is defined and failed_architectures | length != 0 |
| 82 | + |
0 commit comments