Skip to content

Commit

Permalink
Add resilience focus
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok committed Mar 3, 2024
1 parent 0072477 commit b7ac883
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/work_proposal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
strategy:
fail-fast: false
matrix:
focus: [api]
focus: [api, resilience]
env:
- dev: godel
ops: marx
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
strategy:
fail-fast: false
matrix:
focus: [api]
focus: [api, resilience]
shard: [0, 1]
env:
- dev: godel
Expand Down Expand Up @@ -173,7 +173,7 @@ jobs:
strategy:
fail-fast: false
matrix:
focus: [api]
focus: [api, resilience]
env:
- dev: godel
ops: marx
Expand Down
26 changes: 15 additions & 11 deletions baker/ansible/tasks/product/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Remove artifacts
- name: Clean artifacts
ansible.builtin.file:
path: "{{ stack_dir }}/target"
path: "{{ stack_dir }}/target/{{ focus }}"
state: absent
changed_when: false

Expand All @@ -12,18 +12,22 @@
recurse: true
changed_when: false

- name: Build conf
ansible.builtin.template:
src: "{{ stack_dir }}/focus/{{ focus }}/{{ ops.config.mapping_mode }}.j2"
dest: "{{ stack_dir }}/target/{{ focus }}/{{ ops.config.file_name }}"
lstrip_blocks: yes
trim_blocks: yes
- name: Copy configs
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ stack_dir }}/target/{{ focus }}/"
mode: "644"
changed_when: false
with_fileglob:
- "{{ stack_dir }}/focus/{{ focus }}/*.conf"

- name: Build spec
- name: Render templates
ansible.builtin.template:
src: "{{ stack_dir }}/focus/{{ focus }}/compose.j2"
dest: "{{ stack_dir }}/target/{{ focus }}/compose.yaml"
src: "{{ item }}"
dest: "{{ stack_dir }}/target/{{ focus }}/{{ item | basename | splitext | first }}"
lstrip_blocks: yes
trim_blocks: yes
mode: "644"
changed_when: false
with_fileglob:
- "{{ stack_dir }}/focus/{{ focus }}/*.jinja"
12 changes: 1 addition & 11 deletions baker/ansible/tasks/product/check.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
---
- name: Remove storages
ansible.builtin.command:
cmd: docker container rm -fv storage-{{ vendor }}
changed_when: false
loop: "{{ product.databases.keys() }}"
loop_control:
loop_var: vendor
when: hostvars.db.image_status is changed

- name: Create network
- name: Create networks
ansible.builtin.shell:
cmd: docker network inspect gear || docker network create gear
strip_empty_ends: false
Expand All @@ -19,7 +10,6 @@
cmd: >-
docker compose
--file compose.yaml
--profile {{ opsenv }}
up
--remove-orphans
--quiet-pull
Expand Down
4 changes: 2 additions & 2 deletions baker/ansible/tasks/product/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
tasks_from: clean
vars:
image_keys:
- "{{ product.image }}/{{ opsenv }}"
- "product/{{ focus }}/{{ opsenv }}"

- ansible.builtin.import_role: # noqa: name[missing]
name: image
tasks_from: build
vars:
image_home: "{{ project.dir }}/{{ product.image }}"
image_context: target/{{ focus }}
image_key: "{{ product.image }}/{{ opsenv }}"
image_key: "product/{{ focus }}/{{ opsenv }}"
image_tag: "{{ product.image }}:{{ opsenv }}"

- ansible.builtin.import_role: # noqa: name[missing]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ product {
protocol {
mode = {{ ops.storage.vendor }}
{{ ops.storage.vendor }} {
url = "jdbc:postgresql://storage:5432/{{ database.name }}"
url = "jdbc:postgresql://storage-{{ ops.storage.vendor }}:5432/{{ database.name }}"
schema = "{{ schema.name }}"
username = "{{ storage.owner.username }}"
password = "{{ storage.owner.password }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
{% set storage = product.storages[ops.storage.vendor] %}
{% set database = product.databases[ops.storage.vendor] %}
{% set schema = product.schemas[ops.storage.vendor] %}
---
product:
messaging:
mapping:
Expand All @@ -10,7 +10,7 @@ product:
protocol:
mode: {{ ops.storage.vendor }}
{{ ops.storage.vendor }}:
url: "jdbc:postgresql://storage:5432/{{ database.name }}"
url: "jdbc:postgresql://storage-{{ ops.storage.vendor }}:5432/{{ database.name }}"
schema: "{{ schema.name }}"
username: "{{ storage.owner.username }}"
password: "{{ storage.owner.password }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{% set storage = product.storages[ops.storage.vendor] %}
{% set database = product.databases[ops.storage.vendor] %}
{% set schema = product.schemas[ops.storage.vendor] %}
{% set app = product.apps[ops.app.name] %}
---
name: focus-api
name: {{ project.name }}

networks:
product:
name: product
external: false
gear:
name: gear
external: true

configs:
product_config:
file: ./{{ ops.config.file_name }}
product:
file: {{ ops.config.file_name }}

services:
{% set storage = product.storages[ops.storage.vendor] %}
storage:
container_name: storage-{{ ops.storage.vendor }}
storage-{{ ops.storage.vendor }}:
container_name: {{ project.name }}-storage-{{ ops.storage.vendor }}
image: {{ storage.image }}:{{ ops.storage.version }}-alpine
networks:
- product
ports:
- 5432:5432
- "5432:5432"
environment:
POSTGRES_USER: "{{ storage.dba.username }}"
POSTGRES_PASSWORD: "{{ storage.dba.password }}"
Expand All @@ -29,23 +33,22 @@ services:
interval: 10s
timeout: 5s
retries: 5
labels:
image.key: db/{{ ops.storage.vendor }}/{{ devenv }}

{% set database = product.databases[ops.storage.vendor] %}
database:
container_name: database-{{ database.name }}
database-{{ database.name }}:
container_name: {{ project.name }}-database-{{ database.name }}
image: {{ image_ns }}/db/{{ ops.storage.vendor }}:{{ hostvars.db.image_tags[ops.storage.vendor] }}
networks:
- product
depends_on:
storage:
storage-{{ ops.storage.vendor }}:
condition: service_healthy
labels:
image.key: db/{{ ops.storage.vendor }}/{{ devenv }}
networks:
- product
command: >-
--show-banner=false
--classpath=/liquibase/changelog
--changelog-file=dba/changelog.yaml
--url=jdbc:postgresql://storage:5432/postgres
--url=jdbc:postgresql://storage-{{ ops.storage.vendor }}:5432/postgres
--liquibase-schema-name=public
--default-schema-name=public
--username={{ storage.dba.username }}
Expand All @@ -55,47 +58,47 @@ services:
-Ddatabase.name={{ database.name }}
-Downer.username={{ storage.owner.username }}
-Downer.password={{ storage.owner.password }}
labels:
image.key: db/{{ ops.storage.vendor }}/{{ devenv }}

{% set schema = product.schemas[ops.storage.vendor] %}
{{ schema.name }}:
container_name: schema-{{ schema.name }}
schema-{{ schema.name }}:
container_name: {{ project.name }}-schema-{{ schema.name }}
image: {{ image_ns }}/db/{{ ops.storage.vendor }}:{{ hostvars.db.image_tags[ops.storage.vendor] }}
networks:
- product
depends_on:
database:
database-{{ database.name }}:
condition: service_completed_successfully
labels:
image.key: db/{{ ops.storage.vendor }}/{{ devenv }}
networks:
- product
command: >-
--show-banner=false
--classpath=/liquibase/changelog
--changelog-file=owner/changelog.yaml
--url=jdbc:postgresql://storage:5432/{{ database.name }}
--url=jdbc:postgresql://storage-{{ ops.storage.vendor }}:5432/{{ database.name }}
--liquibase-schema-name=public
--default-schema-name={{ schema.name }}
--username={{ storage.owner.username }}
--password={{ storage.owner.password }}
update
-Dschema.name={{ schema.name }}
labels:
image.key: db/{{ ops.storage.vendor }}/{{ devenv }}

{% set app = product.apps[ops.app.name] %}
{{ app.service }}:
container_name: app-{{ app.service }}
app-{{ app.service }}:
container_name: {{ project.name }}-app-{{ app.service }}
image: {{ image_ns }}/app/{{ ops.app.name }}:{{ hostvars.app.image_tags[ops.app.name] }}
depends_on:
schema-{{ schema.name }}:
condition: service_completed_successfully
networks:
- product
- gear
ports:
- 8080:8080
- "8080:8080"
configs:
- source: product_config
- source: product
target: /home/app/{{ ops.config.file_name }}
command: >-
--product.config.mapping.mode={{ ops.config.mapping_mode }}
--spring.config.location=optional:file:application.yaml
depends_on:
{{ schema.name }}:
condition: service_completed_successfully
labels:
image.key: app/{{ ops.app.name }}/{{ devenv }}
24 changes: 24 additions & 0 deletions stack/product/focus/resilience/application.conf.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% set storage = product.storages[ops.storage.vendor] %}
{% set database = product.databases[ops.storage.vendor] %}
{% set schema = product.schemas[ops.storage.vendor] %}
product {
messaging {
mapping {
modes = [spring_mvc, spring_management]
}
}
storage {
protocol {
mode = {{ ops.storage.vendor }}
{{ ops.storage.vendor }} {
url = "jdbc:postgresql://{{ ops.storage.vendor }}-primary:5432,{{ ops.storage.vendor }}-secondary:5432/{{ database.name }}"
schema = "{{ schema.name }}"
username = "{{ storage.owner.username }}"
password = "{{ storage.owner.password }}"
}
}
mapping {
mode = {{ ops.storage.mapping_mode }}
}
}
}
18 changes: 18 additions & 0 deletions stack/product/focus/resilience/application.yaml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% set storage = product.storages[ops.storage.vendor] %}
{% set database = product.databases[ops.storage.vendor] %}
{% set schema = product.schemas[ops.storage.vendor] %}
---
product:
messaging:
mapping:
modes: [spring_mvc, spring_management]
storage:
protocol:
mode: {{ ops.storage.vendor }}
{{ ops.storage.vendor }}:
url: "jdbc:postgresql://{{ ops.storage.vendor }}-primary:5432,{{ ops.storage.vendor }}-secondary:5432/{{ database.name }}"
schema: "{{ schema.name }}"
username: "{{ storage.owner.username }}"
password: "{{ storage.owner.password }}"
mapping:
mode: {{ ops.storage.mapping_mode }}
Loading

0 comments on commit b7ac883

Please sign in to comment.