Skip to content

Commit

Permalink
Introduce focus concept
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok committed Sep 6, 2023
1 parent 7dbfd1a commit 8f01f2f
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 65 deletions.
16 changes: 9 additions & 7 deletions .dx/binaries.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
---
- name: Binaries
hosts: lib
run_once: true
tasks:
- name: Capture status
ansible.builtin.command:
# todo: try to implement more lightweight check
cmd: >
mvn
{% if repository_mode == 'offline' %}
{% if maven_host == 'local' %}
--offline
{% else %}
--define remoteRepositories=github::::https://maven.pkg.github.com/smecalculus/bezmen
--define remoteRepositories=github::::https://{{ maven_host }}/smecalculus/bezmen
{% endif %}
dependency:get
--define transitive=false
Expand All @@ -33,7 +34,7 @@
--threads 2C
--define revision={{ lib_version }}
clean
{% if repository_mode == 'read_write' %}
{% if focus == 'solution' %}
deploy
{% else %}
install
Expand All @@ -44,19 +45,20 @@

- name: Binaries
hosts: app
run_once: true
tasks:
- name: Capture tag
- name: Capture cid
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ lib_cid }}
{{ app_cid }}
register: image_tag
register: image_cid
changed_when: false
tags: [always]
- name: Capture statuses
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ item.value }}:{{ image_tag.stdout[:7] }}
cmd: docker {{ docker_entity }} inspect {{ item.value }}:{{ image_cid.stdout[:7] }}
register: image_status
changed_when: image_status.rc != 0
failed_when: false
Expand Down Expand Up @@ -90,7 +92,7 @@
when: image_status is changed

- name: Coverage
hosts: lib:app
hosts: tool
run_once: true
tasks:
- name: Generate reports
Expand Down
27 changes: 12 additions & 15 deletions .dx/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@ app_version: 0.1.0-{{ app_cid }}
usage: toy
prefs: turing

# How to work with private remote repositories?
# offline - no pull, nor push packages
# read_only - can pull packages
# read_write - can pull and push packages
repository_mode: offline
# solution - focus on solution changes
# pipeline - focus on pipeline changes
# none - without any particular focus
focus: none

docker_registry: ghcr.io
docker_repo: smecalculus
maven_host: local
docker_host: local

docker_entity: "{{ 'image' if repository_mode == 'offline' else 'manifest' }}"
docker_repo: smecalculus
docker_entity: "{{ 'image' if docker_host == 'local' else 'manifest' }}"

schema_images:
postgres: "{{ docker_registry }}/{{ docker_repo }}/schema-postgres"
postgres: "{{ docker_host }}/{{ docker_repo }}/schema-postgres"
app_images:
foo: "{{ docker_registry }}/{{ docker_repo }}/app-foo"
solution_image: "{{ docker_registry }}/{{ docker_repo }}/solution-{{ usage }}-{{ prefs }}"
pipeline_image: "{{ docker_registry }}/{{ docker_repo }}/pipeline-{{ environ }}"

capture_solution: true
capture_pipeline: true
foo: "{{ docker_host }}/{{ docker_repo }}/app-foo"
solution_image: "{{ docker_host }}/{{ docker_repo }}/solution-{{ usage }}-{{ prefs }}"
pipeline_image: "{{ docker_host }}/{{ docker_repo }}/pipeline-{{ environ }}"
10 changes: 7 additions & 3 deletions .dx/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- name: Images
hosts: schema
run_once: true
tasks:
- name: Capture statuses
ansible.builtin.command:
Expand All @@ -25,10 +26,12 @@
image_tag: "{{ schema_cid }}"
image_name: "{{ item.value }}"
image_home: "{{ playbook_dir }}/../schemas/{{ item.key }}"
image_push: "{{ focus == 'solution' }}"
loop: "{{ image_status.results|select('changed')|map(attribute='item') }}"

- name: Images
hosts: app
run_once: true
tasks:
- name: Test integrations
ansible.builtin.command:
Expand All @@ -52,9 +55,10 @@
ansible.builtin.include_role:
name: image
vars:
image_tag: "{{ hostvars.app.image_tag.stdout[:7] }}"
image_tag: "{{ image_cid.stdout[:7] }}"
image_name: "{{ item.value }}"
image_home: "{{ playbook_dir }}/../apps/{{ item.key }}"
image_context: target/docker-context
loop: "{{ hostvars.app.image_status.results|select('changed')|map(attribute='item') }}"
when: hostvars.app.image_status is changed
image_push: "{{ focus == 'solution' }}"
loop: "{{ image_status.results|select('changed')|map(attribute='item') }}"
when: image_status is changed
6 changes: 4 additions & 2 deletions .dx/inventory/aliases.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
all:
hosts:
system:
solution:
lib:
app:
schema:
solution:
pipeline:
dx:
test:
pipeline:
tool:
vars:
ansible_connection: local
1 change: 1 addition & 0 deletions .dx/roles/image/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
image_tag: latest
image_context: .
image_push: false
2 changes: 1 addition & 1 deletion .dx/roles/image/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
cmd: docker image push {{ image_name }}:{{ image_tag }}
strip_empty_ends: false
changed_when: true
when: repository_mode == 'read_write'
when: image_push|bool
48 changes: 31 additions & 17 deletions .dx/solution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,53 @@
- import_playbook: images.yml # noqa: name[play]
tags: [images, deps]

- name: Solution & Pipeline
- name: Capturing
hosts: solution
run_once: true
tasks:
- name: Capture solution
ansible.builtin.import_tasks:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/solution/status.yml
tags: [always]
- name: Capture pipeline
ansible.builtin.import_tasks:

- name: Capturing
hosts: pipeline
run_once: true
tasks:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/pipeline/status.yml
tags: [always]
- name: Compile solution
ansible.builtin.import_tasks:

- name: Testing
hosts: system
run_once: true
tasks:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/solution/compile.yml
tags: [compile]
when: >
solution_status is changed or
pipeline_status is changed
- name: Test solution
ansible.builtin.import_tasks:
hostvars.solution.solution_status is changed or
hostvars.pipeline.pipeline_status is changed
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/solution/test.yml
tags: [test]
when: >
solution_status is changed or
pipeline_status is changed
- name: Package solution
ansible.builtin.import_tasks:
hostvars.solution.solution_status is changed or
hostvars.pipeline.pipeline_status is changed
- name: Packaging
hosts: solution
run_once: true
tasks:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/solution/package.yml
tags: [package]
when: solution_status is changed
- name: Package pipeline
ansible.builtin.import_tasks:

- name: Packaging
hosts: pipeline
run_once: true
tasks:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/pipeline/package.yml
tags: [package]
when: pipeline_status is changed
4 changes: 4 additions & 0 deletions .dx/sources.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Sources
hosts: lib
run_once: true
tasks:
- name: Analyze
ansible.builtin.command:
Expand All @@ -16,6 +17,7 @@

- name: Sources
hosts: app
run_once: true
tasks:
- name: Analyze
ansible.builtin.command:
Expand All @@ -30,6 +32,7 @@

- name: Sources
hosts: test
run_once: true
tasks:
- name: Analyze
ansible.builtin.command:
Expand All @@ -44,6 +47,7 @@

- name: Sources
hosts: pipeline
run_once: true
tasks:
- name: Analyze
ansible.builtin.command:
Expand Down
3 changes: 2 additions & 1 deletion .dx/tasks/pipeline/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
- ansible.builtin.import_role: # noqa: name[missing]
name: image
vars:
image_tag: "{{ pipeline_tag.stdout[:7] }}"
image_tag: "{{ pipeline_cid.stdout[:7] }}"
image_name: "{{ pipeline_image }}"
image_home: "{{ playbook_dir }}/../.github"
image_context: .
image_push: "{{ focus == 'pipeline' }}"
7 changes: 3 additions & 4 deletions .dx/tasks/pipeline/status.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
---
- name: Capture pipeline tag
- name: Capture cid
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ dx_cid }}
{{ env_cid }}
{{ tool_cid }}
{{ test_cid }}
register: pipeline_tag
register: pipeline_cid
changed_when: false

- name: Capture pipeline status
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ pipeline_image }}:{{ pipeline_tag.stdout[:7] }}
cmd: docker {{ docker_entity }} inspect {{ pipeline_image }}:{{ pipeline_cid.stdout[:7] }}
register: pipeline_status
changed_when:
- capture_pipeline|bool
- pipeline_status.rc != 0
failed_when: false

Expand Down
2 changes: 1 addition & 1 deletion .dx/tasks/solution/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
environment:
SCHEMA_TAG: "{{ schema_cid }}"
SCHEMA_IMAGE: "{{ schema_images.postgres }}"
FOO_TAG: "{{ hostvars.app.image_tag.stdout[:7] }}"
FOO_TAG: "{{ hostvars.app.image_cid.stdout[:7] }}"
FOO_IMAGE: "{{ app_images.foo }}"
changed_when: true

Expand Down
3 changes: 2 additions & 1 deletion .dx/tasks/solution/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
- ansible.builtin.import_role: # noqa: name[missing]
name: image
vars:
image_tag: "{{ solution_tag.stdout[:7] }}"
image_tag: "{{ solution_cid.stdout[:7] }}"
image_name: "{{ solution_image }}"
image_home: "{{ playbook_dir }}/../solutions"
image_context: target/context
image_push: "{{ focus == 'solution' }}"
7 changes: 3 additions & 4 deletions .dx/tasks/solution/status.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Capture solution tag
- name: Capture cid
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
Expand All @@ -8,15 +8,14 @@
{{ schema_cid }}
{{ solution_cid }}
{{ test_cid }}
register: solution_tag
register: solution_cid
changed_when: false

- name: Capture solution status
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ solution_image }}:{{ solution_tag.stdout[:7] }}
cmd: docker {{ docker_entity }} inspect {{ solution_image }}:{{ solution_cid.stdout[:7] }}
register: solution_status
changed_when:
- capture_solution|bool
- solution_status.rc != 0
failed_when: false

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/pipeline-beyond-doubt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: >
ansible-playbook solution.yml
-e maven_host=maven.pkg.github.com
-e docker_host=ghcr.io
-e environ=${{ matrix.environ.name }}
-e repository_mode=read_write
-e capture_solution=false
-e focus=pipeline
-e usage=toy
-e prefs=turing
working-directory: .dx
Expand Down
Loading

0 comments on commit 8f01f2f

Please sign in to comment.