From 57d4e12146d14884e79f31872856d9de51e7a3cf Mon Sep 17 00:00:00 2001 From: Pavel Vetokhin Date: Sat, 30 Mar 2024 10:42:31 +0300 Subject: [PATCH] Add stacker tool (#422) --- .github/dependabot.yaml | 3 +++ orchestrator/ansible/images.yaml | 8 +++--- orchestrator/ansible/inventory/aliases.yaml | 5 +++- orchestrator/ansible/stacks.yaml | 21 ++++++++-------- orchestrator/ansible/tasks/builder/build.yaml | 1 + .../tasks/{tool => builder}/capture.yaml | 0 .../{tool/build.yaml => builder/publish.yaml} | 8 ++++++ orchestrator/ansible/tasks/gear/capture.yaml | 6 +++-- .../ansible/tasks/pipeline/capture.yaml | 4 +-- .../ansible/tasks/product/capture.yaml | 4 +-- .../ansible/tasks/stacker/capture.yaml | 25 +++++++++++++++++++ .../ansible/tasks/stacker/publish.yaml | 24 ++++++++++++++++++ orchestrator/ansible/tasks/tool/publish.yaml | 8 ------ 13 files changed, 88 insertions(+), 29 deletions(-) create mode 100644 orchestrator/ansible/tasks/builder/build.yaml rename orchestrator/ansible/tasks/{tool => builder}/capture.yaml (100%) rename orchestrator/ansible/tasks/{tool/build.yaml => builder/publish.yaml} (61%) create mode 100644 orchestrator/ansible/tasks/stacker/capture.yaml create mode 100644 orchestrator/ansible/tasks/stacker/publish.yaml delete mode 100644 orchestrator/ansible/tasks/tool/publish.yaml diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index 4e73e8aa..3f59e90e 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -13,6 +13,9 @@ updates: junit-platform: patterns: - "org.junit*" + jetbrains-kotlin: + patterns: + - "org.jetbrains.kotlin*" - package-ecosystem: "github-actions" directory: "/" schedule: diff --git a/orchestrator/ansible/images.yaml b/orchestrator/ansible/images.yaml index bd66d793..198b10a1 100644 --- a/orchestrator/ansible/images.yaml +++ b/orchestrator/ansible/images.yaml @@ -1,6 +1,6 @@ --- - name: ALL IMAGES - hosts: images + hosts: images:builder tasks: - ansible.builtin.include_tasks: # noqa: name[missing] file: tasks/{{ inventory_hostname }}/capture.yaml @@ -11,13 +11,13 @@ file: tasks/{{ inventory_hostname }}/build.yaml when: hostvars[inventory_hostname].image_status is changed -# building everything without exception otherwise purely external libs will not be published +# TODO: build only changed apps and purely external libs which have no dependees - import_playbook: binaries.yaml # noqa: name[play] vars: - maven_phase: "{{ 'deploy' if repo_mode == 'rw' else 'install' }}" + maven_phase: "{{ 'deploy' if repo_mode == 'rw' and hostvars.app.image_status is changed else 'install' }}" when: >- hostvars.app.image_status is changed or - hostvars.tool.image_status is changed + hostvars.builder.image_status is changed - name: ALL IMAGES hosts: images diff --git a/orchestrator/ansible/inventory/aliases.yaml b/orchestrator/ansible/inventory/aliases.yaml index 5a842736..4c1fb9f4 100644 --- a/orchestrator/ansible/inventory/aliases.yaml +++ b/orchestrator/ansible/inventory/aliases.yaml @@ -8,12 +8,15 @@ images: hosts: db: app: - tool: stacks: hosts: gear: pipeline: product: +tools: + hosts: + builder: + stacker: all: vars: ansible_connection: local diff --git a/orchestrator/ansible/stacks.yaml b/orchestrator/ansible/stacks.yaml index 996b3b86..d1611026 100644 --- a/orchestrator/ansible/stacks.yaml +++ b/orchestrator/ansible/stacks.yaml @@ -2,7 +2,7 @@ - import_playbook: images.yaml # noqa: name[play] - name: ALL STACKS - hosts: stacks + hosts: stacks:stacker tasks: - ansible.builtin.include_tasks: # noqa: name[missing] file: tasks/{{ inventory_hostname }}/capture.yaml @@ -16,12 +16,12 @@ - ansible.builtin.import_tasks: # noqa: name[missing] file: tasks/ansible/check.yaml tags: [build] - when: stack_status is changed + when: image_status is changed - ansible.builtin.import_tasks: # noqa: name[missing] file: tasks/gear/build.yaml tags: [build] when: >- - stack_status is changed and + image_status is changed and is_virtual.rc != 0 - name: PIPELINE STACK @@ -30,7 +30,7 @@ - ansible.builtin.import_tasks: # noqa: name[missing] file: tasks/yaml/check.yaml tags: [build] - when: stack_status is changed + when: image_status is changed - name: PRODUCT STACK hosts: product @@ -41,21 +41,22 @@ file: tasks/product/build.yaml tags: [build] when: >- - hostvars.product.stack_status is changed or - hostvars.gear.stack_status is changed + hostvars.product.image_status is changed or + hostvars.stacker.image_status is changed - ansible.builtin.import_tasks: # noqa: name[missing] file: tasks/product/check.yaml tags: [check] when: >- - hostvars.product.stack_status is changed or - hostvars.gear.stack_status is changed + hostvars.product.image_status is changed or + hostvars.stacker.image_status is changed or + hostvars.builder.image_status is changed - name: ALL STACKS - hosts: stacks + hosts: stacks:tools tasks: - ansible.builtin.include_tasks: # noqa: name[missing] file: tasks/{{ inventory_hostname }}/publish.yaml apply: tags: [publish] tags: [publish] - when: hostvars[inventory_hostname].stack_status is changed + when: hostvars[inventory_hostname].image_status is changed diff --git a/orchestrator/ansible/tasks/builder/build.yaml b/orchestrator/ansible/tasks/builder/build.yaml new file mode 100644 index 00000000..7f5ab72d --- /dev/null +++ b/orchestrator/ansible/tasks/builder/build.yaml @@ -0,0 +1 @@ +# build right before publishing diff --git a/orchestrator/ansible/tasks/tool/capture.yaml b/orchestrator/ansible/tasks/builder/capture.yaml similarity index 100% rename from orchestrator/ansible/tasks/tool/capture.yaml rename to orchestrator/ansible/tasks/builder/capture.yaml diff --git a/orchestrator/ansible/tasks/tool/build.yaml b/orchestrator/ansible/tasks/builder/publish.yaml similarity index 61% rename from orchestrator/ansible/tasks/tool/build.yaml rename to orchestrator/ansible/tasks/builder/publish.yaml index 89fb6328..cd1e8318 100644 --- a/orchestrator/ansible/tasks/tool/build.yaml +++ b/orchestrator/ansible/tasks/builder/publish.yaml @@ -14,3 +14,11 @@ image_context: . image_key: "tool/builder/{{ devenv }}" image_tag: "tool/builder:{{ devenv }}" + +- ansible.builtin.import_role: # noqa: name[missing] + name: image + tasks_from: publish + vars: + image_source_tag: "tool/builder:{{ devenv }}" + image_target_tags: + - "{{ image_ns }}/tool/builder:{{ hostvars.builder.package_tag }}" diff --git a/orchestrator/ansible/tasks/gear/capture.yaml b/orchestrator/ansible/tasks/gear/capture.yaml index f3920aac..8abfac36 100644 --- a/orchestrator/ansible/tasks/gear/capture.yaml +++ b/orchestrator/ansible/tasks/gear/capture.yaml @@ -3,6 +3,8 @@ ansible.builtin.command: cmd: git hash-object --stdin stdin: | + {{ lookup('ansible.builtin.pipe', 'git rev-parse :pom.xml') }} + {{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=tool') }} {{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=test') }} {{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=orchestrator') }} {{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=stack/gear/env/' ~ devenv) }} @@ -17,10 +19,10 @@ - name: Capture statuses ansible.builtin.command: cmd: docker {{ docker_entity }} inspect {{ image_ns }}/{{ item }} - register: stack_status + register: image_status failed_when: false changed_when: - - stack_status.rc != 0 + - image_status.rc != 0 loop: - "{{ gear.image }}:{{ stack_tag }}" diff --git a/orchestrator/ansible/tasks/pipeline/capture.yaml b/orchestrator/ansible/tasks/pipeline/capture.yaml index 755ba2e5..9d4f6858 100644 --- a/orchestrator/ansible/tasks/pipeline/capture.yaml +++ b/orchestrator/ansible/tasks/pipeline/capture.yaml @@ -16,9 +16,9 @@ - name: Capture statuses ansible.builtin.command: cmd: docker {{ docker_entity }} inspect {{ image_ns }}/{{ item }} - register: stack_status + register: image_status failed_when: false changed_when: - - stack_status.rc != 0 + - image_status.rc != 0 loop: - "{{ pipeline.image }}:{{ stack_tag }}" diff --git a/orchestrator/ansible/tasks/product/capture.yaml b/orchestrator/ansible/tasks/product/capture.yaml index d36dae65..ef85e1bc 100644 --- a/orchestrator/ansible/tasks/product/capture.yaml +++ b/orchestrator/ansible/tasks/product/capture.yaml @@ -20,10 +20,10 @@ - name: Capture statuses ansible.builtin.command: cmd: docker {{ docker_entity }} inspect {{ image_ns }}/{{ item }} - register: stack_status + register: image_status failed_when: false changed_when: - - stack_status.rc != 0 + - image_status.rc != 0 loop: - "{{ product.image }}:{{ stack_tag }}" diff --git a/orchestrator/ansible/tasks/stacker/capture.yaml b/orchestrator/ansible/tasks/stacker/capture.yaml new file mode 100644 index 00000000..01b9f158 --- /dev/null +++ b/orchestrator/ansible/tasks/stacker/capture.yaml @@ -0,0 +1,25 @@ +--- +- name: Capture CID + ansible.builtin.command: + cmd: git hash-object --stdin + stdin: | + {{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=test') }} + {{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=stack/gear/env/' ~ devenv) }} + {{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=orchestrator/ansible/tasks/product') }} + register: package_cid + changed_when: false + +- name: Declare tag + ansible.builtin.set_fact: + package_tag: "{{ devenv }}-{{ package_cid.stdout[:7] }}" + changed_when: false + +- name: Capture status + ansible.builtin.command: + cmd: docker {{ docker_entity }} inspect {{ image_ns }}/{{ item }} + register: image_status + failed_when: false + changed_when: + - image_status.rc != 0 + loop: + - "tool/stacker:{{ package_tag }}" diff --git a/orchestrator/ansible/tasks/stacker/publish.yaml b/orchestrator/ansible/tasks/stacker/publish.yaml new file mode 100644 index 00000000..7fc6e155 --- /dev/null +++ b/orchestrator/ansible/tasks/stacker/publish.yaml @@ -0,0 +1,24 @@ +--- +- ansible.builtin.import_role: # noqa: name[missing] + name: image + tasks_from: clean + vars: + image_keys: + - "tool/stacker/{{ devenv }}" + +- ansible.builtin.import_role: # noqa: name[missing] + name: image + tasks_from: build + vars: + image_home: "{{ project.dir }}/tool" + image_context: . + image_key: "tool/stacker/{{ devenv }}" + image_tag: "tool/stacker:{{ devenv }}" + +- ansible.builtin.import_role: # noqa: name[missing] + name: image + tasks_from: publish + vars: + image_source_tag: "tool/stacker:{{ devenv }}" + image_target_tags: + - "{{ image_ns }}/tool/stacker:{{ hostvars.stacker.package_tag }}" diff --git a/orchestrator/ansible/tasks/tool/publish.yaml b/orchestrator/ansible/tasks/tool/publish.yaml deleted file mode 100644 index 8eaa0b81..00000000 --- a/orchestrator/ansible/tasks/tool/publish.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- ansible.builtin.import_role: # noqa: name[missing] - name: image - tasks_from: publish - vars: - image_source_tag: "tool/builder:{{ devenv }}" - image_target_tags: - - "{{ image_ns }}/tool/builder:{{ hostvars.tool.package_tag }}"