Skip to content

Commit

Permalink
Module and package structure (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok authored Sep 20, 2023
1 parent 8d4d2e1 commit 71d1608
Show file tree
Hide file tree
Showing 148 changed files with 722 additions and 879 deletions.
93 changes: 31 additions & 62 deletions .dx/binaries.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,36 @@
---
- name: Binaries
hosts: lib
run_once: true
tasks:
- name: Capture status
ansible.builtin.command:
# todo: try to implement more lightweight check
cmd: >
mvn
{% if binary_repo == 'local' %}
--offline
{% else %}
--define remoteRepositories=github::::https://{{ binary_repo }}/smecalculus/bezmen
{% endif %}
dependency:get
--define transitive=false
--define artifact=org.smecalculus.bezmen:libs:{{ lib_version }}:pom
chdir: "{{ playbook_dir }}/../libs"
register: binary_status
changed_when: binary_status.rc != 0
failed_when: false
- name: Status command
ansible.builtin.debug:
msg: "{{ binary_status.cmd|join(' ') }}"
when: binary_status is changed
- name: Create binaries
ansible.builtin.command:
cmd: >
mvn
--no-snapshot-updates
--fail-fast
--batch-mode
--threads 1C
clean
{% if focus == 'solution' %}
deploy
{% else %}
install
{% endif %}
--define revision={{ lib_version }}
chdir: "{{ playbook_dir }}/../libs"
changed_when: true
when: binary_status is changed

- name: Binaries
hosts: app
run_once: true
tasks:
- name: Capture cid
- name: Capture cid's
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ lib_cid }}
{{ app_cid }}
{{ app_cids[app] }}
{% for lib in app_deps[app] %}
{{ lib_cids[lib] }}
{% endfor %}
# TODO: try to choose better name
register: image_cid
changed_when: false
loop: "{{ app_images.keys() }}"
loop_control:
loop_var: app
tags: [always]
- name: Declare cid's
ansible.builtin.set_fact:
image_cids: "{{ image_cid.results|items2dict(key_name='app', value_name='stdout') }}"
tags: [always]
- name: Capture statuses
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ item.value }}:{{ image_cid.stdout[:7] }}
cmd: docker {{ docker_entity }} inspect {{ app_images[app] }}:{{ image_cids[app][:7] }}
register: image_status
changed_when: image_status.rc != 0
failed_when: false
loop: "{{ app_images|dict2items }}"
loop: "{{ image_cids.keys() }}"
loop_control:
label: "{{ item.key }}"
loop_var: app
tags: [always]
- name: Status commands
ansible.builtin.debug:
Expand All @@ -80,18 +45,21 @@
--fail-fast
--batch-mode
--threads 1C
{% if not hostvars.lib.binary_status|default({}) is changed %}
--projects {{ image_status.results|select('changed')|map(attribute='item.key')|join(',') }}
{% endif %}
--projects {{
image_status.results
| select('changed')
| map(attribute='app')
| map('regex_replace', '^', 'apps/')
| join(',')
}}
--also-make
clean
{% if up_to_images|default(false) %}
verify
{% if focus == 'solution' and up_to_images|default(false) %}
deploy
{% else %}
package
{% endif %}
--define revision={{ app_version }}
--define lib.version={{ lib_version }}
chdir: "{{ playbook_dir }}/../apps"
chdir: "{{ playbook_dir }}/.."
strip_empty_ends: false
changed_when: true
when: image_status is changed
Expand All @@ -106,10 +74,11 @@
mvn
--no-snapshot-updates
--batch-mode
--projects tools,tests
--also-make
clean
test-compile
--define lib.version={{ lib_version }}
chdir: "{{ playbook_dir }}/../tests"
package
chdir: "{{ playbook_dir }}/.."
strip_empty_ends: false
changed_when: true
when: hostvars.lib.binary_status|default({}) is changed
when: focus == 'pipeline'
18 changes: 15 additions & 3 deletions .dx/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ usage: toy
prefs: turing

lib_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs')[:7] }}"
lib_cids:
client: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/client')[:7] }}"
construction: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/construction')[:7] }}"
data: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/data')[:7] }}"
essentials: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/essentials')[:7] }}"
messaging: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/messaging')[:7] }}"
testing: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs/testing')[:7] }}"
app_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=apps')[:7] }}"
app_cids:
foo: "{{ lookup('ansible.builtin.pipe', 'git rev-parse HEAD:apps/foo')[:7] }}"
schema_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=schemas')[:7] }}"
schema_cids:
postgres: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=schemas/postgres')[:7] }}"
solution_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=solutions')[:7] }}"

lib_version: 0.1.0-{{ lib_cid }}
Expand All @@ -18,7 +29,7 @@ test_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=tests')[:7
environ: green

dx_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=.dx')[:7] }}"
tool_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=.tools')[:7] }}"
tool_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=tools')[:7] }}"
environ_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=.environs/' ~ environ)[:7] }}"
pipeline_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=.github')[:7] }}"

Expand All @@ -32,12 +43,13 @@ image_repo: local

app_images:
foo: "{{ image_repo }}/{{ organization }}/{{ project }}/app/foo"

schema_images:
postgres: "{{ image_repo }}/{{ organization }}/{{ project }}/schema/postgres"

stack_images:
solution: "{{ image_repo }}/{{ organization }}/{{ project }}/stack/solution-{{ usage }}-{{ prefs }}"
pipeline: "{{ image_repo }}/{{ organization }}/{{ project }}/stack/pipeline-{{ environ }}"

docker_entity: "{{ 'image' if image_repo == 'local' else 'manifest' }}"

app_deps:
foo: [essentials, construction, client, messaging, data]
28 changes: 16 additions & 12 deletions .dx/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
tasks:
- name: Capture statuses
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ item.value }}:{{ schema_cid }}
cmd: docker {{ docker_entity }} inspect {{ schema_images[schema] }}:{{ schema_cids[schema] }}
register: image_status
changed_when: image_status.rc != 0
failed_when: false
loop: "{{ schema_images|dict2items }}"
loop: "{{ schema_images.keys() }}"
loop_control:
label: "{{ item.key }}"
loop_var: schema
- name: Status commands
ansible.builtin.debug:
msg: "{{ image_status.results|map(attribute='cmd')|map('join', ' ') }}"
Expand All @@ -25,11 +25,13 @@
ansible.builtin.include_role:
name: image
vars:
image_tag: "{{ schema_cid }}"
image_name: "{{ item.value }}"
image_home: "{{ playbook_dir }}/../schemas/{{ item.key }}"
image_tag: "{{ schema_cids[schema] }}"
image_name: "{{ schema_images[schema] }}"
image_home: "{{ playbook_dir }}/../schemas/{{ schema }}"
image_push: "{{ focus == 'solution' }}"
loop: "{{ image_status.results|select('changed')|map(attribute='item') }}"
loop: "{{ image_status.results|select('changed')|map(attribute='schema') }}"
loop_control:
loop_var: schema

- name: Images
hosts: app
Expand All @@ -43,18 +45,20 @@
--batch-mode
clean
antrun:run@coverage
chdir: "{{ playbook_dir }}/../.tools"
chdir: "{{ playbook_dir }}/../tools"
strip_empty_ends: false
changed_when: true
when: image_status is changed
- name: Create images
ansible.builtin.include_role:
name: image
vars:
image_tag: "{{ image_cid.stdout[:7] }}"
image_name: "{{ item.value }}"
image_home: "{{ playbook_dir }}/../apps/{{ item.key }}"
image_tag: "{{ image_cids[app][:7] }}"
image_name: "{{ app_images[app] }}"
image_home: "{{ playbook_dir }}/../apps/{{ app }}"
image_context: target/docker-context
image_push: "{{ focus == 'solution' }}"
loop: "{{ image_status.results|select('changed')|map(attribute='item') }}"
loop: "{{ image_status.results|select('changed')|map(attribute='app') }}"
loop_control:
loop_var: app
when: image_status is changed
9 changes: 7 additions & 2 deletions .dx/inventory/aliases.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
all:
hosts:
lib:
app:
schema:
test:
dx:
vars:
ansible_connection: local
codebase:
hosts:
java:
ansible:
github:
vars:
ansible_connection: local
stack:
Expand Down
53 changes: 18 additions & 35 deletions .dx/sources.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Sources
hosts: lib
- name: Codebase
hosts: java
run_once: true
tasks:
- name: Analyze
Expand All @@ -9,44 +9,20 @@
mvn
--no-snapshot-updates
--batch-mode
{% if focus == 'solution' %}
--projects apps/foo
{% elif focus == 'pipeline' %}
--projects tests/e2e
{% endif %}
--also-make
enforcer:enforce
spotless:check
chdir: "{{ playbook_dir }}/../libs"
chdir: "{{ playbook_dir }}/.."
strip_empty_ends: false
changed_when: false

- name: Sources
hosts: app
run_once: true
tasks:
- name: Analyze
ansible.builtin.command:
cmd: >
mvn
--no-snapshot-updates
--batch-mode
spotless:check
chdir: "{{ playbook_dir }}/../apps"
strip_empty_ends: false
changed_when: false

- name: Sources
hosts: test
run_once: true
tasks:
- name: Analyze
ansible.builtin.command:
cmd: >
mvn
--no-snapshot-updates
--batch-mode
spotless:check
chdir: "{{ playbook_dir }}/../tests"
strip_empty_ends: false
changed_when: false

- name: Sources
hosts: pipeline
- name: Codebase
hosts: ansible
run_once: true
tasks:
- name: Analyze
Expand All @@ -58,8 +34,15 @@
stacks.yml
strip_empty_ends: false
changed_when: false
when: focus != 'solution'

- name: Codebase
hosts: github
run_once: true
tasks:
- name: Analyze
ansible.builtin.command:
cmd: yamllint ../.github
strip_empty_ends: false
changed_when: false
when: focus != 'solution'
4 changes: 2 additions & 2 deletions .dx/tasks/solution/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
strip_empty_ends: false
chdir: "{{ playbook_dir }}/../solutions"
environment:
SCHEMA_TAG: "{{ schema_cid }}"
SCHEMA_TAG: "{{ schema_cids.postgres }}"
SCHEMA_IMAGE: "{{ schema_images.postgres }}"
FOO_TAG: "{{ hostvars.app.image_cid.stdout[:7] }}"
FOO_TAG: "{{ hostvars.app.image_cids.foo[:7] }}"
FOO_IMAGE: "{{ app_images.foo }}"
changed_when: true

Expand Down
10 changes: 6 additions & 4 deletions .dx/tasks/solution/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@
mvn
--no-snapshot-updates
--batch-mode
--projects e2e
--threads 1C
--projects tests/e2e
--activate-profiles {{ usage }}
--define lib.version={{ lib_version }}
--also-make
clean
test
--define prefs={{ prefs }}
{% if test_failure_ignore is defined %}
--define maven.test.failure.ignore={{ test_failure_ignore }}
{% endif %}
--define prefs={{ prefs }}
{% if reminder is defined %}
--define bezmen.sharding.reminder={{ reminder }}
{% endif %}
{% if modulus is defined %}
--define bezmen.sharding.modulus={{ modulus }}
{% endif %}
chdir: "{{ playbook_dir }}/../tests"
--define skipUnits=true
chdir: "{{ playbook_dir }}/.."
strip_empty_ends: false
changed_when: true
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ updates:
schedule:
interval: "weekly"
ignore:
- dependency-name: "org.smecalculus.bezmen:*"
- dependency-name: "smecalculus.bezmen:*"
- package-ecosystem: "maven"
directory: "/tests"
schedule:
interval: "weekly"
ignore:
- dependency-name: "org.smecalculus.bezmen:*"
- dependency-name: "smecalculus.bezmen:*"
- package-ecosystem: "maven"
directory: "/.tools"
directory: "/tools"
schedule:
interval: "weekly"
- package-ecosystem: "docker"
Expand Down
Loading

0 comments on commit 71d1608

Please sign in to comment.