Skip to content

Commit

Permalink
Stacks in group vars #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok committed Dec 9, 2023
1 parent e61df85 commit 34f7105
Show file tree
Hide file tree
Showing 30 changed files with 188 additions and 207 deletions.
1 change: 1 addition & 0 deletions .dx/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ inventory = inventory
any_errors_fatal = true
display_skipped_hosts = false
unparsed_is_failed = true
callback_result_format = yaml
19 changes: 10 additions & 9 deletions .dx/binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ lib_cid }}
{{ solution.apps[app].cid }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=apps/' ~ app)[:7] }}
# TODO: try to choose better name
register: image_cid
changed_when: false
loop: "{{ solution.apps.keys() }}"
loop: "{{ solution.apps.values()|flatten|map(attribute='binary') }}"
loop_control:
loop_var: app
tags: [always]
Expand All @@ -22,14 +22,15 @@
tags: [always]
- name: Capture statuses
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ app.image.name }}:{{ image_cids[app.name][:7] }}-{{ devenv }}
cmd: docker {{ docker_entity }} inspect {{ app.image }}:{{ image_cids[app.binary][:7] }}-{{ devenv }}
register: image_status
changed_when: image_status.rc != 0
changed_when:
- image_status.rc != 0
failed_when: false
loop: "{{ solution.apps.values() }}"
loop: "{{ solution.apps.values()|flatten }}"
loop_control:
loop_var: app
label: "{{ app.binary.name }}"
label: "{{ app.binary }}"
tags: [always]
- name: Status commands
ansible.builtin.debug:
Expand All @@ -47,8 +48,8 @@
--projects {{
image_status.results
| select('changed')
| map(attribute='app.binary.name')
| map('regex_replace', '^', 'apps/')
| map(attribute='app.binary')
| map('regex_replace', '^', ':')
| join(',')
}}
--also-make
Expand Down
28 changes: 13 additions & 15 deletions .dx/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
tags: [binaries, deps]

- name: Images
hosts: schema
hosts: db
run_once: true
tasks:
- name: Capture statuses
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ schema.image.name }}:{{ schema.image.tag }}
cmd: docker {{ docker_entity }} inspect {{ solution.databases[storage].image }}:{{ solution.databases[storage].cid }}
register: image_status
changed_when: image_status.rc != 0
failed_when: false
loop: "{{ solution.schemas.values() }}"
loop: "{{ solution.schemas.keys() }}"
loop_control:
loop_var: schema
label: "{{ schema.name }}"
loop_var: storage
- name: Status commands
ansible.builtin.debug:
msg: "{{ image_status.results|map(attribute='cmd')|map('join', ' ') }}"
Expand All @@ -26,14 +25,13 @@
ansible.builtin.include_role:
name: image
vars:
image_tag: "{{ schema.image.tag }}"
image_name: "{{ schema.image.name }}"
image_home: "{{ playbook_dir }}/../schemas/{{ solution.storage.vendor }}"
image_tag: "{{ solution.databases[storage].cid }}"
image_name: "{{ solution.databases[storage].image }}"
image_home: "{{ playbook_dir }}/../databases/{{ storage }}"
image_push: "{{ image_storage != 'local' }}"
loop: "{{ image_status.results|select('changed')|map(attribute='schema') }}"
loop: "{{ image_status.results|select('changed')|map(attribute='storage') }}"
loop_control:
loop_var: schema
label: "{{ schema.name }}"
loop_var: storage

- name: Images
hosts: app
Expand All @@ -56,15 +54,15 @@
ansible.builtin.include_role:
name: image
vars:
image_tag: "{{ image_cids[app.name][:7] }}-{{ devenv }}"
image_name: "{{ app.image.name }}"
image_home: "{{ playbook_dir }}/../apps/{{ app.binary.name }}"
image_tag: "{{ image_cids[app.binary][:7] }}-{{ devenv }}"
image_name: "{{ app.image }}"
image_home: "{{ playbook_dir }}/../apps/{{ app.binary }}"
image_context: target/docker-context
image_push: "{{ image_storage != '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.name }}"
label: "{{ app.binary }}"
when: image_status is changed
14 changes: 5 additions & 9 deletions .dx/inventory/aliases.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
---
all:
hosts:
app:
schema:
test:
vars:
ansible_connection: local
codebase:
hosts:
java:
ansible:
github:
vars:
ansible_connection: local
stack:
hosts:
solution:
toolchain:
all:
hosts:
db:
app:
test:
vars:
ansible_connection: local
11 changes: 11 additions & 0 deletions .dx/inventory/group_vars/all/aims.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
aim: toy
aims:
toy:
storage: postgres
apps:
- sepuling
func:
storage: postgres
apps:
- sepuling
20 changes: 0 additions & 20 deletions .dx/inventory/group_vars/all/all.yaml

This file was deleted.

12 changes: 4 additions & 8 deletions .dx/inventory/group_vars/all/envs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ ops:
vendor: postgres
version: 14.9
mapping_mode: my_batis
runtime:
release: 17
app:
lang: java
config:
mapping_mode: lightbend_config
Expand All @@ -35,8 +34,7 @@ ops:
vendor: postgres
version: 15.4
mapping_mode: my_batis
runtime:
release: 19
app:
lang: kotlin
config:
mapping_mode: lightbend_config
Expand All @@ -45,8 +43,7 @@ ops:
vendor: postgres
version: 15.4
mapping_mode: spring_data
runtime:
release: 19
app:
lang: kotlin
config:
mapping_mode: spring_config
Expand All @@ -55,8 +52,7 @@ ops:
vendor: postgres
version: 16.0
mapping_mode: spring_data
runtime:
release: 21
app:
lang: java
config:
mapping_mode: spring_config
48 changes: 26 additions & 22 deletions .dx/inventory/group_vars/all/stacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,40 @@ toolchain:
image:
name: "{{ image_repo }}/stack/toolchain"

app_name: "sepuling-{{ ops[opsenv].runtime.lang }}"

solution:
name: "{{ project_name }}"
name: "{{ project.name }}"
cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=stacks/solution')[:7] }}"
image:
name: "{{ image_repo }}/stack/solution-{{ usecase }}"
name: "{{ image_repo }}/stack/solution-{{ aim }}"
config:
file_name: "application.{{ config_exts[ops[opsenv].config.mapping_mode] }}"
mapping_mode: "{{ ops[opsenv].config.mapping_mode }}"
storage: "{{ ops[opsenv].storage }}"
database:
name: "{{ project_name }}"
schemas:
sepulkarium:
name: sepulkarium
image:
name: "{{ image_repo }}/schema/{{ ops[opsenv].storage.vendor }}"
tag: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=schemas/' ~ ops[opsenv].storage.vendor)[:7] }}"
storages:
postgres:
image: "docker.io/library/postgres"
dba:
username: "postgres"
password: "password"
owner:
name: "{{ project_name }}"
password: "{{ project_name }}"
username: "{{ project.name }}"
password: "{{ project.name }}"
databases:
postgres:
name: "{{ project.name }}"
cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=databases/postgres')[:7] }}"
image: "{{ image_repo }}/database/postgres"
schemas:
postgres:
- name: sepulkarium
apps:
sepuling:
name: sepuling
cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=apps/' ~ app_name)[:7] }}"
binary:
name: "{{ app_name }}"
image:
name: "{{ image_repo }}/app/{{ app_name }}"
java:
- service: sepuling
image: "{{ image_repo }}/app/sepuling-java"
binary: sepuling-java
kotlin:
- service: sepuling
image: "{{ image_repo }}/app/sepuling-kotlin"
binary: sepuling-kotlin

config_exts:
lightbend_config: conf
Expand Down
11 changes: 11 additions & 0 deletions .dx/inventory/group_vars/all/vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
project:
name: bezmen
org: smecalculus

binary_storage: local
image_storage: local

image_repo: "{{ image_storage }}/{{ project.org }}/{{ project.name }}"

docker_entity: "{{ 'image' if image_storage == 'local' else 'manifest' }}"
7 changes: 4 additions & 3 deletions .dx/tasks/solution/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
ansible.builtin.template:
src: "{{ stack_dir }}/{{ solution.config.mapping_mode }}.j2"
dest: "{{ stack_dir }}/target/context/application.{{ config_exts[solution.config.mapping_mode] }}"
lstrip_blocks: yes
trim_blocks: yes
mode: "644"
vars:
# TODO: multiple schemas in config
schema: "{{ solution.schemas.values()|first }}"

- name: Build spec
ansible.builtin.template:
src: "{{ stack_dir }}/compose.j2"
dest: "{{ stack_dir }}/target/context/compose.yaml"
lstrip_blocks: yes
trim_blocks: yes
mode: "644"
8 changes: 4 additions & 4 deletions .dx/tasks/solution/status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ lib_cid }}
{{ app_cid }}
{{ schema_cid }}
{{ solution.cid }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=apps')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=databases')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=stacks/solution')[:7] }}
register: stack_cid
changed_when: false

Expand Down
4 changes: 2 additions & 2 deletions .dx/tasks/solution/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.command:
cmd: docker rm -f env-db
changed_when: false
when: hostvars.schema.image_status|default({}) is changed
when: hostvars.db.image_status|default({}) is changed

- name: Create stand
ansible.builtin.command:
Expand All @@ -28,7 +28,7 @@
--batch-mode
--threads 2
--projects tests/e2e
--activate-profiles {{ usecase }}
--activate-profiles {{ aim }}
--also-make
clean
test
Expand Down
8 changes: 4 additions & 4 deletions .dx/tasks/toolchain/status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ dx_cid }}
{{ env_cid }}
{{ tool_cid }}
{{ test_cid }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=.dx')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=envs')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=tools')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=tests')[:7] }}
register: stack_cid
changed_when: false

Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ updates:
patterns:
- "org.junit*"
- package-ecosystem: "docker"
directory: "/schemas/postgres"
directory: "/databases/postgres"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
Expand Down
Loading

0 comments on commit 34f7105

Please sign in to comment.