Skip to content

Commit

Permalink
Declare image tags
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok committed Dec 9, 2023
1 parent 61c601d commit c3acbfa
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 95 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/beyond-doubt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: images
run: >
run: >-
ansible-playbook images.yaml
-e binary_storage=${{ env.BINARY_STORAGE }}
-e image_storage=${{ env.IMAGE_STORAGE }}
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
strategy:
fail-fast: false
matrix:
aim: [func]
purpose: [func]
env:
- dev: godel
os: ubuntu-20.04
Expand All @@ -97,27 +97,27 @@ jobs:
devenv: ${{ matrix.env.dev }}
tools: python docker
token: ${{ secrets.GITHUB_TOKEN }}
- run: >
- run: >-
ansible-playbook stacks.yaml -t build
-e image_storage=${{ env.IMAGE_STORAGE }}
-e aim=${{ matrix.aim }}
-e purpose=${{ matrix.purpose }}
-e devenv=${{ matrix.env.dev }}
-e opsenv=${{ matrix.env.ops }}
working-directory: bakers/ansible
- uses: actions/[email protected]
with:
name: solution-${{ matrix.aim }}-${{ matrix.env.ops }}
path: stacks/solution/target/context
name: solution-${{ matrix.purpose }}-${{ matrix.env.ops }}
path: stacks/solution/target/image-context
if-no-files-found: ignore

stack-testing:
name: Stack testing (${{ matrix.shard }}, ${{ matrix.aim }}, ${{ matrix.env.ops }})
name: Stack testing (${{ matrix.shard }}, ${{ matrix.purpose }}, ${{ matrix.env.ops }})
timeout-minutes: 15
needs: [stack-building]
strategy:
fail-fast: false
matrix:
aim: [func]
purpose: [func]
shard: [0, 1]
env:
- dev: godel
Expand All @@ -143,12 +143,12 @@ jobs:
- uses: actions/[email protected]
continue-on-error: true # it's ok because stack building can be skipped
with:
name: solution-${{ matrix.aim }}-${{ matrix.env.ops }}
path: stacks/solution/target/context
- run: >
name: solution-${{ matrix.purpose }}-${{ matrix.env.ops }}
path: stacks/solution/target/image-context
- run: >-
ansible-playbook stacks.yaml -t test
-e image_storage=${{ env.IMAGE_STORAGE }}
-e aim=${{ matrix.aim }}
-e purpose=${{ matrix.purpose }}
-e reminder=${{ matrix.shard }}
-e modulus=2
-e devenv=${{ matrix.env.dev }}
Expand All @@ -160,18 +160,18 @@ jobs:
- uses: actions/[email protected]
if: ${{ !cancelled() }}
with:
name: e2e-test-report-${{ matrix.shard }}-${{ matrix.aim }}-${{ matrix.env.ops }}
name: e2e-test-report-${{ matrix.shard }}-${{ matrix.purpose }}-${{ matrix.env.ops }}
path: tests/e2e/target/surefire-reports/*.xml
if-no-files-found: ignore

stack-publishing:
name: Stack publishing (${{ matrix.aim }}, ${{ matrix.env.ops }})
name: Stack publishing (${{ matrix.purpose }}, ${{ matrix.env.ops }})
timeout-minutes: 5
needs: [stack-testing]
strategy:
fail-fast: false
matrix:
aim: [func]
purpose: [func]
env:
- dev: godel
os: ubuntu-20.04
Expand All @@ -198,12 +198,12 @@ jobs:
- uses: actions/[email protected]
continue-on-error: true # it's ok because stack building can be skipped
with:
name: solution-${{ matrix.aim }}-${{ matrix.env.ops }}
path: stacks/solution/target/context
- run: >
name: solution-${{ matrix.purpose }}-${{ matrix.env.ops }}
path: stacks/solution/target/image-context
- run: >-
ansible-playbook stacks.yaml -t package
-e image_storage=${{ env.IMAGE_STORAGE }}
-e aim=${{ matrix.aim }}
-e purpose=${{ matrix.purpose }}
-e opsenv=${{ matrix.env.ops }}
working-directory: bakers/ansible
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/convincing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: images
run: >
run: >-
ansible-playbook images.yaml
-e binary_storage=maven.pkg.github.com
-e image_storage=ghcr.io
Expand Down
39 changes: 19 additions & 20 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,31 @@ ansible-playbook stacks.yaml

=== Низкая сложность

- Новая документация для контрибьюторов или потенциальных пользователей шаблона
- Новый рефакторинг, снижающий сложность и/или повышающий идиоматичность
- Новая правка, устраняющая ошибку и/или повышающая безопасность
- Новый тест, увеличивающий покрытие
- Рефакторинг, снижающий сложность и/или повышающий идиоматичность.
- Добавление теста, увеличивающего покрытие.
- Правка ворнинга на любом из этапов сборки.
- Дополнение или правка документации.
- Правка ошибки и/или уязвимости.

=== Средняя сложность

- Новая метрика качества кодовой базы (в т.ч. новые архитектурные тесты)
- Новый уровень качества по одной из существующих метрик
- Новая заморозка версии в dev или ops окружении
- Новая база данных (сейчас только PostgreSQL)
- Новое dev или ops окружение
- Новая метрика качества кодовой базы (в т.ч. архитектурные тесты).
- Новый уровень качества по одной из существующих метрик.
- Заморозка версии инструмента в dev или ops окружении.
- Новая база данных. Сейчас только PostgreSQL.
- Новое dev или ops окружение.

=== Высокая сложность

- Новый фреймворк или инструмент в рамках существующего режима
- Новый инструмент сборки бинарников (сейчас только Maven)
- Новый инструмент управления образами (сейчас только Docker)
- Новый инструмент раскатки стеков (сейчас только Docker Compose)
- Новая цель использования для существующего стека
- Новый инструмент построения дерева хешей (сейчас связка Git и Ansible)
- Новый инструмент сборки бинарников. Сейчас только Apache Maven.
- Новый инструмент управления образами. Сейчас только Docker Engine.
- Новый инструмент раскатки стеков. Сейчас только Docker Compose.
- Новое целевое использование (purpose) существующего стека.
- Новая обвязка построения дерева хешей. Сейчас связка Git и Ansible.

=== Непредсказуемая сложность

- Новый инструмент готовки (сейчас только Ansible)
- Новый язык программирования (сейчас только Java и Kotlin)
- Новая операционная система в dev и/или ops окружении (сейчас только Ubuntu)
- Новый этап конвейера (сейчас только интеграция)
- Новая схема именования для dev и/или ops окружения
- Новая обвязка готовки (baker). Сейчас только Ansible.
- Новый язык программирования. Сейчас только Java и Kotlin.
- Новая операционная система в dev и/или ops окружении. Сейчас только Ubuntu.
- Новый этап конвейера (pipeline). Сейчас только интеграция (CI).
6 changes: 3 additions & 3 deletions apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<configuration>
<includeScope>runtime</includeScope>
<excludeGroupIds>${project.groupId}</excludeGroupIds>
<outputDirectory>${project.build.directory}/docker-context/lib</outputDirectory>
<outputDirectory>${project.build.directory}/image-context/lib</outputDirectory>
</configuration>
</execution>
<execution>
Expand All @@ -98,7 +98,7 @@
<configuration>
<includeScope>runtime</includeScope>
<includeGroupIds>${project.groupId}</includeGroupIds>
<outputDirectory>${project.build.directory}/docker-context/bin</outputDirectory>
<outputDirectory>${project.build.directory}/image-context/bin</outputDirectory>
</configuration>
</execution>
<execution>
Expand All @@ -113,7 +113,7 @@
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<outputDirectory>${project.build.directory}/docker-context/bin</outputDirectory>
<outputDirectory>${project.build.directory}/image-context/bin</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
Expand Down
23 changes: 15 additions & 8 deletions bakers/ansible/binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@
hosts: app
run_once: true
tasks:
- name: Capture cid's
- name: Capture cids
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs')[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=apps/' ~ app)[:7] }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs') }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=apps/' ~ app) }}
# TODO: try to choose better name
register: image_cid
changed_when: false
loop: "{{ solution.apps.values()|flatten|map(attribute='binary') }}"
loop_control:
loop_var: app
tags: [always]
- name: Declare cid's
- name: Declare tags
ansible.builtin.set_fact:
image_cids: "{{ image_cid.results|items2dict(key_name='app', value_name='stdout') }}"
image_tags: >-
{{ dict(image_cid.results
|map(attribute='stdout')
|map('truncate', 7, True, '')
|map('regex_replace', '^', devenv ~ '-')
|zip(image_cid.results|map(attribute='app'))
|map('reverse'))
}}
tags: [always]
- name: Capture statuses
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ app.image }}:{{ image_cids[app.binary][:7] }}-{{ devenv }}
cmd: docker {{ docker_entity }} inspect {{ app.image }}:{{ image_tags[app.binary] }}
register: image_status
changed_when:
- image_status.rc != 0
Expand All @@ -39,7 +46,7 @@
tags: [always]
- name: Create binaries
ansible.builtin.command:
cmd: >
cmd: >-
mvn
--no-snapshot-updates
--fail-fast
Expand Down Expand Up @@ -67,7 +74,7 @@
tasks:
- name: Create binaries
ansible.builtin.command:
cmd: >
cmd: >-
mvn
--no-snapshot-updates
--batch-mode
Expand Down
4 changes: 2 additions & 2 deletions bakers/ansible/codebase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
tasks:
- name: Analyze
ansible.builtin.command:
cmd: >
cmd: >-
mvn
--no-snapshot-updates
--batch-mode
Expand All @@ -22,7 +22,7 @@
- name: Analyze
ansible.builtin.command:
# list all top level playbooks
cmd: >
cmd: >-
ansible-lint
toolchain.yaml
codebase.yaml
Expand Down
8 changes: 4 additions & 4 deletions bakers/ansible/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
tasks:
- name: Capture statuses
ansible.builtin.command:
cmd: >
cmd: >-
docker
{{ docker_entity }}
inspect
Expand Down Expand Up @@ -43,7 +43,7 @@
tasks:
- name: Analyze coverage
ansible.builtin.command:
cmd: >
cmd: >-
mvn
--no-snapshot-updates
--batch-mode
Expand All @@ -58,10 +58,10 @@
ansible.builtin.include_role:
name: image
vars:
image_tag: "{{ image_cids[app.binary][:7] }}-{{ devenv }}"
image_tag: "{{ image_tags[app.binary] }}"
image_name: "{{ app.image }}"
image_home: "{{ project.dir }}/apps/{{ app.binary }}"
image_context: target/docker-context
image_context: target/image-context
image_push: "{{ image_storage != 'local' }}"
image_args:
JAVA_RELEASE: "{{ dev[devenv].jdk.release }}"
Expand Down
7 changes: 2 additions & 5 deletions bakers/ansible/inventory/group_vars/all/stacks.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
---
toolchain:
image:
name: "{{ image_repo }}/stack/toolchain"
image: "{{ image_repo }}/stack/toolchain"

solution:
name: "{{ project.name }}"
cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=stacks/solution')[:7] }}"
image:
name: "{{ image_repo }}/stack/solution-{{ aim }}"
image: "{{ image_repo }}/stack/solution"
config:
file_name: "application.{{ config_exts[ops[opsenv].config.mapping_mode] }}"
mapping_mode: "{{ ops[opsenv].config.mapping_mode }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
aim: toy
aims:
purpose: toy
usage:
toy:
storage: postgres
apps:
Expand Down
2 changes: 1 addition & 1 deletion bakers/ansible/roles/image/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

- name: Build fresh
ansible.builtin.command:
cmd: >
cmd: >-
docker build {{ image_context }}
-f Dockerfile
-t {{ image_name }}:{{ image_tag }}
Expand Down
4 changes: 2 additions & 2 deletions bakers/ansible/stacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/solution/build.yaml
tags: [build]
when: >
when: >-
hostvars.solution.stack_status is changed or
hostvars.toolchain.stack_status is changed
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/solution/test.yaml
tags: [test]
when: >
when: >-
hostvars.solution.stack_status is changed or
hostvars.toolchain.stack_status is changed
Expand Down
6 changes: 3 additions & 3 deletions bakers/ansible/tasks/solution/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

- name: Create directories
ansible.builtin.file:
path: "{{ stack_dir }}/target/context"
path: "{{ stack_dir }}/target/image-context"
state: directory
recurse: true

- name: Build conf
ansible.builtin.template:
src: "{{ stack_dir }}/{{ solution.config.mapping_mode }}.j2"
dest: "{{ stack_dir }}/target/context/application.{{ config_exts[solution.config.mapping_mode] }}"
dest: "{{ stack_dir }}/target/image-context/application.{{ config_exts[solution.config.mapping_mode] }}"
lstrip_blocks: yes
trim_blocks: yes
mode: "644"

- name: Build spec
ansible.builtin.template:
src: "{{ stack_dir }}/compose.j2"
dest: "{{ stack_dir }}/target/context/compose.yaml"
dest: "{{ stack_dir }}/target/image-context/compose.yaml"
lstrip_blocks: yes
trim_blocks: yes
mode: "644"
6 changes: 3 additions & 3 deletions bakers/ansible/tasks/solution/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
- ansible.builtin.import_role: # noqa: name[missing]
name: image
vars:
image_tag: "{{ stack_cid.stdout[:7] }}-{{ opsenv }}"
image_name: "{{ solution.image.name }}"
image_tag: "{{ solution_tag }}"
image_name: "{{ solution.image }}"
image_home: "{{ project.dir }}/stacks/solution"
image_context: target/context
image_context: target/image-context
image_push: "{{ image_storage != 'local' }}"
Loading

0 comments on commit c3acbfa

Please sign in to comment.