-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
282 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,57 @@ | ||
--- | ||
- import_playbook: binaries.yaml # noqa: name[play] | ||
vars: | ||
maven_phase: "{{ 'install' if binary_repo == 'local' else 'deploy' }}" | ||
tags: [binaries, deps] | ||
|
||
- name: Images | ||
- name: Building | ||
hosts: db | ||
run_once: true | ||
tasks: | ||
- name: Capture statuses | ||
ansible.builtin.command: | ||
cmd: >- | ||
docker {{ docker_entity }} inspect | ||
{{ image_ns }}/{{ product.databases[storage].image }}:{{ product.databases[storage].cid }} | ||
register: image_status | ||
changed_when: image_status.rc != 0 | ||
failed_when: false | ||
loop: "{{ product.schemas.keys() }}" | ||
loop_control: | ||
loop_var: storage | ||
- name: Status commands | ||
ansible.builtin.debug: | ||
msg: "{{ image_status.results|map(attribute='cmd')|map('join', ' ') }}" | ||
when: image_status is changed | ||
- name: Create images | ||
ansible.builtin.include_role: | ||
- ansible.builtin.import_tasks: # noqa: name[missing] | ||
file: tasks/db/status.yaml | ||
tags: [always] | ||
- ansible.builtin.import_role: # noqa: name[missing] | ||
name: image | ||
tasks_from: clean | ||
vars: | ||
image_tag: "{{ product.databases[storage].cid }}" | ||
image_name: "{{ image_ns }}/{{ product.databases[storage].image }}" | ||
image_home: "{{ project.dir }}/db/{{ storage }}" | ||
image_key: "{{ product.databases[storage].image }}" | ||
image_push: "{{ image_repo != 'local' }}" | ||
loop: "{{ image_status.results|select('changed')|map(attribute='storage') }}" | ||
loop_control: | ||
loop_var: storage | ||
image_keys: >- | ||
{{ image_status.results | ||
| select('changed') | ||
| map(attribute='db.image') | ||
| map('regex_replace', '$', '/' ~ devenv) | ||
}} | ||
when: image_status is changed | ||
- ansible.builtin.import_tasks: # noqa: name[missing] | ||
file: tasks/db/build.yaml | ||
when: image_status is changed | ||
|
||
- name: Images | ||
- name: Building & Checking | ||
hosts: app | ||
run_once: true | ||
tasks: | ||
- name: Analyze coverage | ||
ansible.builtin.command: | ||
cmd: >- | ||
mvn | ||
--no-snapshot-updates | ||
--batch-mode | ||
--projects tool | ||
clean | ||
antrun:run@coverage | ||
chdir: "{{ project.dir }}" | ||
strip_empty_ends: false | ||
changed_when: true | ||
when: image_status is changed | ||
- name: Create images | ||
ansible.builtin.include_role: | ||
- ansible.builtin.import_tasks: # noqa: name[missing] | ||
file: tasks/app/status.yaml | ||
tags: [always] | ||
- ansible.builtin.import_role: # noqa: name[missing] | ||
name: image | ||
tasks_from: clean | ||
vars: | ||
image_tag: "{{ image_tags[app.binary] }}" | ||
image_name: "{{ image_ns }}/{{ app.image }}" | ||
image_home: "{{ project.dir }}/app/{{ app.binary }}" | ||
image_context: target/image-context | ||
image_key: "{{ app.image }}/{{ devenv }}" | ||
image_push: "{{ image_repo != 'local' }}" | ||
image_args: | ||
JAVA_RELEASE: "{{ dev[devenv].jdk.release }}" | ||
loop: "{{ image_status.results|select('changed')|map(attribute='app') }}" | ||
loop_control: | ||
loop_var: app | ||
label: "{{ app.binary }}" | ||
image_keys: >- | ||
{{ image_status.results | ||
| select('changed') | ||
| map(attribute='app.image') | ||
| map('regex_replace', '$', '/' ~ devenv) | ||
}} | ||
when: image_status is changed | ||
- ansible.builtin.import_tasks: # noqa: name[missing] | ||
file: tasks/app/build-and-check.yaml | ||
vars: | ||
maven_phase: "{{ 'install' if binary_repo == 'local' else 'deploy' }}" | ||
when: image_status is changed | ||
|
||
- name: Publishing | ||
hosts: image | ||
run_once: true | ||
tasks: | ||
- ansible.builtin.import_tasks: # noqa: name[missing] | ||
file: tasks/db/publish.yaml | ||
when: hostvars.db.image_status is changed | ||
- ansible.builtin.import_tasks: # noqa: name[missing] | ||
file: tasks/app/publish.yaml | ||
when: hostvars.app.image_status is changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ stack: | |
hosts: | ||
gear: | ||
product: | ||
all: | ||
image: | ||
hosts: | ||
db: | ||
app: | ||
all: | ||
vars: | ||
ansible_connection: local |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
- name: Enforce variables | ||
ansible.builtin.assert: | ||
quiet: true | ||
that: | ||
- image_keys is defined | ||
|
||
- name: Kill containers | ||
ansible.builtin.shell: | ||
cmd: docker container rm -f $(docker ps -aq --filter label=image.key={{ item }}) | ||
strip_empty_ends: false | ||
changed_when: false | ||
failed_when: false | ||
loop: "{{ image_keys }}" | ||
|
||
- name: Remove images | ||
ansible.builtin.shell: | ||
cmd: docker image rm -f $(docker images -q --filter label=image.key={{ item }}) | ||
strip_empty_ends: false | ||
changed_when: false | ||
failed_when: false | ||
loop: "{{ image_keys }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,21 @@ | ||
--- | ||
- name: Check vars | ||
- name: Enforce variables | ||
ansible.builtin.assert: | ||
quiet: true | ||
that: | ||
- image_name is defined | ||
- image_home is defined | ||
- image_key is defined | ||
|
||
- name: Kill containers | ||
ansible.builtin.shell: | ||
cmd: docker container rm -f $(docker ps -aq --filter label=image.key={{ image_key }}) | ||
strip_empty_ends: false | ||
changed_when: false | ||
failed_when: false | ||
no_log: true | ||
|
||
- name: Remove outdated | ||
ansible.builtin.shell: | ||
cmd: docker image rm -f $(docker images -q --filter label=image.key={{ image_key }}) | ||
strip_empty_ends: false | ||
changed_when: false | ||
failed_when: false | ||
no_log: true | ||
|
||
- name: Build fresh | ||
- name: Build image | ||
ansible.builtin.command: | ||
cmd: >- | ||
docker build {{ image_context }} --file Dockerfile | ||
--tag {{ image_name }}:{{ image_tag }} | ||
docker build {{ image_context }} | ||
--file {{ image_home }}/Dockerfile | ||
--label image.key={{ image_key }} | ||
--tag {{ image_name }}:{{ image_tag }} | ||
{% for key, value in image_args.items() %} | ||
--build-arg {{ key }}={{ value }} | ||
{% endfor %} | ||
chdir: "{{ image_home }}" | ||
strip_empty_ends: false | ||
changed_when: true | ||
|
||
- name: Push built | ||
ansible.builtin.command: | ||
cmd: docker image push {{ image_name }}:{{ image_tag }} | ||
strip_empty_ends: false | ||
changed_when: true | ||
when: image_push|bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.