Skip to content

Commit

Permalink
Introduce dev & ops envs (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok authored Oct 8, 2023
1 parent b3577dd commit 799f0ef
Show file tree
Hide file tree
Showing 37 changed files with 196 additions and 121 deletions.
23 changes: 23 additions & 0 deletions .dx/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
= Окружения

== Эксплуатация (opsenv)

shannon:: Клод Шеннон
lamport:: Лесли Лампорт

== Разработка (devenv)

church:: Алонзо Чёрч
turing:: Алан Тьюринг

== В запасе

brouwer:: Бертус Брауэр
godel:: Курт Гёдель
gentzen:: Герхард Генцен
girard:: Рене Жирар
milner:: Робин Мильнер
martin-lof:: Пер Мартин-Лёф
honda:: Кохэй Хонда
voevodsky:: Владимир Воеводский
nakamoto:: Сатоши Накомото
2 changes: 1 addition & 1 deletion .dx/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@
chdir: "{{ playbook_dir }}/.."
strip_empty_ends: false
changed_when: true
when: focus == 'pipeline'
when: focus != 'solution'
3 changes: 2 additions & 1 deletion .dx/codebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
--batch-mode
{% if focus == 'solution' %}
--projects apps/sepuling
{% elif focus == 'pipeline' %}
{% elif focus == 'toolchain' %}
--projects tests/e2e
{% endif %}
--also-make
Expand All @@ -30,6 +30,7 @@
# list all top level playbooks
cmd: >
ansible-lint
toolchain.yaml
codebase.yml
stacks.yml
strip_empty_ends: false
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions .dx/envs/dev/church/vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
maven_version:
min: 3.8.0
max: 3.10.0

docker_version:
min: 24.0.0
max: 25.0.0
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions .dx/envs/dev/turing/vars.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
maven_version:
min: 3.8.0
max: 3.10.0

docker_version:
min: 24.0.0
max: 25.0.0
6 changes: 6 additions & 0 deletions .dx/envs/ops/lamport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
postgres_version: 16.0
config_mapping_mode: spring_config
config_file_name:
source: lamport.yaml
target: application.yaml
6 changes: 6 additions & 0 deletions .dx/envs/ops/shannon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
postgres_version: 15.4
config_mapping_mode: lightbend_config
config_file_name:
source: shannon.conf
target: application.conf
16 changes: 6 additions & 10 deletions .dx/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
organization: smecalculus
project: bezmen

opsenv: lamport
devenv: turing

usage: toy
prefs: turing

lib_cid: "{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=libs')[:7] }}"
lib_cids:
Expand All @@ -20,20 +22,14 @@ 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 }}
app_version: 0.1.0-{{ app_cid }}

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] }}"
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] }}"

# solution - focus on solution changes
# pipeline - focus on pipeline changes
# toolchain - focus on toolchain changes
# null - without any particular focus
focus: null

Expand All @@ -45,8 +41,8 @@ app_images:
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 }}"
solution: "{{ image_repo }}/{{ organization }}/{{ project }}/stack/solution-{{ usage }}-{{ opsenv }}"
toolchain: "{{ image_repo }}/{{ organization }}/{{ project }}/stack/toolchain-{{ devenv }}"

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

Expand Down
2 changes: 1 addition & 1 deletion .dx/inventory/aliases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ codebase:
stack:
hosts:
solution:
pipeline:
toolchain:
vars:
ansible_connection: local
12 changes: 6 additions & 6 deletions .dx/stacks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
tags: [always]

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

- name: Testing
Expand All @@ -27,13 +27,13 @@
tags: [build]
when: >
hostvars.solution.stack_status is changed or
hostvars.pipeline.stack_status is changed
hostvars.toolchain.stack_status is changed
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/solution/test.yml
tags: [test]
when: >
hostvars.solution.stack_status is changed or
hostvars.pipeline.stack_status is changed
hostvars.toolchain.stack_status is changed
- name: Packaging
hosts: solution
Expand All @@ -45,10 +45,10 @@
when: stack_status is changed

- name: Packaging
hosts: pipeline
hosts: toolchain
run_once: true
tasks:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/pipeline/package.yml
file: tasks/toolchain/package.yml
tags: [package]
when: stack_status is changed
39 changes: 17 additions & 22 deletions .dx/tasks/solution/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,37 @@
state: directory
recurse: true

- name: Capture env
ansible.builtin.include_vars:
file: envs/ops/{{ opsenv }}.yaml
name: ops

- name: Build conf
ansible.builtin.command:
cmd: >
cp props/{{ ops.config_file_name.source }}
target/context/{{ ops.config_file_name.target }}
chdir: "{{ playbook_dir }}/../solutions"
changed_when: true

- name: Build spec
vars:
config_files:
turing: application.yaml
church: application.conf
config_mapping_modes:
turing: spring_config
church: lightbend_config
ansible.builtin.command:
cmd: >
docker compose
--file usages/basis.yml
--file usages/{{ usage }}.yml
--profile {{ prefs }}
--profile {{ opsenv }}
config
--output target/context/compose.yml
--no-path-resolution
strip_empty_ends: false
chdir: "{{ playbook_dir }}/../solutions"
environment:
POSTGRES_VERSION: "{{ ops.postgres_version }}"
SCHEMA_TAG: "{{ schema_cids.postgres }}"
SCHEMA_IMAGE: "{{ schema_images.postgres }}"
SEPULING_TAG: "{{ hostvars.app.image_cids.sepuling[:7] }}"
SEPULING_IMAGE: "{{ app_images.sepuling }}"
CONFIG_FILE_NAME: "{{ config_files[prefs] }}"
CONFIG_MAPPING_MODE: "{{ config_mapping_modes[prefs] }}"
changed_when: true

- name: Build conf
vars:
config_extensions:
turing: yaml
church: conf
ansible.builtin.command:
cmd: >
cp prefs/{{ prefs }}.{{ config_extensions[prefs] }}
target/context/application.{{ config_extensions[prefs] }}
chdir: "{{ playbook_dir }}/../solutions"
CONFIG_FILE_NAME: "{{ ops.config_file_name.target }}"
CONFIG_MAPPING_MODE: "{{ ops.config_mapping_mode }}"
changed_when: true
7 changes: 3 additions & 4 deletions .dx/tasks/solution/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
# todo: think about backward compatibility aspect
- name: Remove stand (or part of it)
ansible.builtin.command:
cmd: docker rm -f env-db
Expand All @@ -11,7 +10,7 @@
cmd: >
docker compose
--file compose.yml
--profile {{ prefs }}
--profile {{ opsenv }}
up
--remove-orphans
--quiet-pull
Expand All @@ -27,13 +26,13 @@
mvn
--no-snapshot-updates
--batch-mode
--threads 1C
--threads 2
--projects tests/e2e
--activate-profiles {{ usage }}
--also-make
clean
test
--define prefs={{ prefs }}
--define props={{ opsenv }}
{% if reminder is defined %}
--define bezmen.sharding.reminder={{ reminder }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name: image
vars:
image_tag: "{{ stack_cid.stdout[:7] }}"
image_name: "{{ stack_images.pipeline }}"
image_name: "{{ stack_images.toolchain }}"
image_home: "{{ playbook_dir }}/../.github"
image_context: .
image_push: "{{ focus == 'pipeline' }}"
image_push: "{{ focus != 'solution' }}"
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
stdin: |
{{ dx_cid }}
{{ tool_cid }}
{{ environ_cid }}
{{ test_cid }}
register: stack_cid
changed_when: false

- name: Capture status
ansible.builtin.command:
cmd: docker {{ docker_entity }} inspect {{ stack_images.pipeline }}:{{ stack_cid.stdout[:7] }}
cmd: docker {{ docker_entity }} inspect {{ stack_images.toolchain }}:{{ stack_cid.stdout[:7] }}
register: stack_status
changed_when:
- stack_status.rc != 0
Expand Down
34 changes: 34 additions & 0 deletions .dx/toolchain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Toolchain
hosts: toolchain
tasks:
- name: Capture dev env
ansible.builtin.include_vars:
file: envs/dev/{{ devenv }}/vars.yaml
name: dev

- name: Capture maven version
ansible.builtin.command:
cmd: mvn --version --quiet
register: maven_version
changed_when: false
- name: Check maven version
ansible.builtin.assert:
quiet: true
that:
- maven_version.stdout is version(dev.maven_version.min, '>=', version_type='semver')
- maven_version.stdout is version(dev.maven_version.max, '<', version_type='semver')
msg: "{{ dev.maven_version.min }} <= maven < {{ dev.maven_version.max }}"

- name: Capture docker version
ansible.builtin.command:
cmd: docker version --format {{'{{.Server.Version}}'}}
register: docker_version
changed_when: false
- name: Check docker version
ansible.builtin.assert:
quiet: true
that:
- docker_version.stdout is version(dev.docker_version.min, '>=', version_type='semver')
- docker_version.stdout is version(dev.docker_version.max, '<', version_type='semver')
msg: "{{ dev.docker_version.min }} <= docker < {{ dev.docker_version.max }}"
13 changes: 8 additions & 5 deletions .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
name: Prepare tools
description: Tools preparation action for specific environment
description: Tools preparation for specific environment
inputs:
name:
description: Environment name
description: Env name
required: true
default: green
default: turing
tools:
description: Tools to prepare
required: true
Expand All @@ -18,21 +18,24 @@ runs:
- id: dotenv
uses: falti/[email protected]
with:
path: .environs/${{ inputs.name }}/.env
path: .dx/envs/dev/${{ inputs.name }}/.env
- uses: actions/[email protected]
if: ${{ contains(inputs.tools, 'python') }}
with:
python-version: ${{ steps.dotenv.outputs.python_version }}
cache: 'pip'
- shell: bash
if: ${{ contains(inputs.tools, 'python') }}
run: pip install -r .environs/${{ inputs.name }}/requirements.txt
run: pip install -r .dx/envs/dev/${{ inputs.name }}/requirements.txt
- uses: actions/[email protected]
if: ${{ contains(inputs.tools, 'java') }}
with:
distribution: 'temurin'
java-version: ${{ steps.dotenv.outputs.java_version }}
cache: 'maven'
- shell: bash
run: ansible-playbook toolchain.yaml
working-directory: .dx
- uses: docker/[email protected]
if: ${{ contains(inputs.tools, 'docker') }}
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ updates:
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/.environs/green"
directory: "/.dx/envs/dev/turing"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/.environs/amber"
directory: "/.dx/envs/dev/church"
schedule:
interval: "weekly"
ignore:
Expand Down
Loading

0 comments on commit 799f0ef

Please sign in to comment.