Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/build check publish #358

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions .github/workflows/beyond-doubt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:

env:
IMAGE_NAME: stack/gear
BINARY_REPO: maven.pkg.github.com
IMAGE_REPO: ghcr.io

jobs:
up-to-images:
Expand Down Expand Up @@ -57,8 +55,7 @@ jobs:
${{ env.IMAGE_NAME }}:${{ matrix.env.dev }}
ansible-playbook images.yaml -v
-e devenv=${{ matrix.env.dev }}
-e binary_repo=${{ env.BINARY_REPO }}
-e image_repo=${{ env.IMAGE_REPO }}
-e repo_mode=rw
- uses: mikepenz/[email protected]
if: ${{ !cancelled() && (steps.images.outcome == 'success' || steps.images.outcome == 'failure') }}
with:
Expand Down Expand Up @@ -105,10 +102,10 @@ jobs:
run: >-
docker run --rm
--volume $(pwd):$(pwd)
--volume /var/run/docker.sock:/var/run/docker.sock
--workdir $(pwd)/baker/ansible
${{ env.IMAGE_NAME }}:${{ matrix.env.dev }}
ansible-playbook stacks.yaml -t build
-e image_repo=${{ env.IMAGE_REPO }}
-e devenv=${{ matrix.env.dev }}
-e purpose=${{ matrix.purpose }}
-e opsenv=${{ matrix.env.ops }}
Expand All @@ -118,8 +115,8 @@ jobs:
path: stack/product/target/image-context
if-no-files-found: ignore

stack-testing:
name: Stack testing (${{ matrix.shard }}, ${{ matrix.purpose }}, ${{ matrix.env.ops }})
stack-checking:
name: Stack checking (${{ matrix.shard }}, ${{ matrix.purpose }}, ${{ matrix.env.ops }})
timeout-minutes: 15
needs: [stack-building]
strategy:
Expand Down Expand Up @@ -149,7 +146,7 @@ jobs:
with:
name: product-${{ matrix.purpose }}-${{ matrix.env.ops }}
path: stack/product/target/image-context
- name: Run ansible-playbook stacks.yaml -t test
- name: Run ansible-playbook stacks.yaml -t check
run: >-
docker run --rm
--network gear
Expand All @@ -158,8 +155,7 @@ jobs:
--volume /var/run/docker.sock:/var/run/docker.sock
--workdir $(pwd)/baker/ansible
${{ env.IMAGE_NAME }}:${{ matrix.env.dev }}
ansible-playbook stacks.yaml -t test
-e image_repo=${{ env.IMAGE_REPO }}
ansible-playbook stacks.yaml -t check
-e devenv=${{ matrix.env.dev }}
-e purpose=${{ matrix.purpose }}
-e opsenv=${{ matrix.env.ops }}
Expand All @@ -175,7 +171,7 @@ jobs:
stack-publishing:
name: Stack publishing (${{ matrix.purpose }}, ${{ matrix.env.ops }})
timeout-minutes: 10
needs: [stack-testing]
needs: [stack-checking]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -204,24 +200,24 @@ jobs:
with:
name: product-${{ matrix.purpose }}-${{ matrix.env.ops }}
path: stack/product/target/image-context
- name: Run ansible-playbook stacks.yaml -t package
- name: Run ansible-playbook stacks.yaml -t publish
run: >-
docker run --rm
--volume $(pwd):$(pwd)
--volume /var/run/docker.sock:/var/run/docker.sock
--volume ~/.docker/config.json:/root/.docker/config.json:ro
--workdir $(pwd)/baker/ansible
${{ env.IMAGE_NAME }}:${{ matrix.env.dev }}
ansible-playbook stacks.yaml -t package -v
-e image_repo=${{ env.IMAGE_REPO }}
ansible-playbook stacks.yaml -t publish -v
-e devenv=${{ matrix.env.dev }}
-e purpose=${{ matrix.purpose }}
-e opsenv=${{ matrix.env.ops }}
-e repo_mode=rw

stack-reporting:
name: Stack reporting
timeout-minutes: 5
needs: [stack-testing]
needs: [stack-checking]
if: ${{ !cancelled() && (contains(needs.*.result, 'success') || contains(needs.*.result, 'failure')) }}
runs-on: ubuntu-22.04
permissions:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/convincing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ jobs:
${{ env.IMAGE_NAME }}:${{ matrix.env.dev }}
ansible-playbook images.yaml -v
-e devenv=${{ matrix.env.dev }}
-e binary_repo=maven.pkg.github.com
-e image_repo=ghcr.io
-e repo_mode=rw
- uses: mikepenz/[email protected]
if: ${{ !cancelled() && (steps.images.outcome == 'success' || steps.images.outcome == 'failure') }}
with:
Expand Down
40 changes: 34 additions & 6 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>dep-copy</id>
<phase>package</phase>
<id>deps-jars</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
Expand All @@ -78,8 +78,8 @@
</configuration>
</execution>
<execution>
<id>lib-copy</id>
<phase>package</phase>
<id>libs-jars</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
Expand All @@ -90,8 +90,8 @@
</configuration>
</execution>
<execution>
<id>app-copy</id>
<phase>package</phase>
<id>app-jar</id>
<phase>pre-integration-test</phase>
<goals>
<goal>copy</goal>
</goals>
Expand All @@ -108,6 +108,34 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>app-image</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>docker</executable>
<arguments>
<argument>build</argument>
<argument>${project.build.directory}/image-context</argument>
<argument>--file</argument>
<argument>${project.basedir}/Dockerfile</argument>
<argument>--tag</argument>
<argument>app/${project.artifactId}:${devenv}</argument>
<argument>--label</argument>
<argument>image.key=app/${project.artifactId}/${devenv}</argument>
<argument>--build-arg</argument>
<argument>JAVA_RELEASE=${maven.compiler.release}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
4 changes: 4 additions & 0 deletions app/sepuling-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4 changes: 4 additions & 0 deletions app/sepuling-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
72 changes: 5 additions & 67 deletions baker/ansible/binaries.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,9 @@
---
- name: Binaries
- name: Building & Checking
hosts: app
run_once: true
tasks:
- name: Capture cids
ansible.builtin.command:
cmd: git hash-object --stdin
stdin: |
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=lib') }}
{{ lookup('ansible.builtin.pipe', 'git write-tree --prefix=app/' ~ app) }}
register: image_cid
changed_when: false
loop: "{{ product.apps.values()|flatten|map(attribute='binary') }}"
loop_control:
loop_var: app
tags: [always]
- name: Declare tags
ansible.builtin.set_fact:
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 {{ image_ns }}/{{ app.image }}:{{ image_tags[app.binary] }}
register: image_status
changed_when:
- image_status.rc != 0
failed_when: false
loop: "{{ product.apps.values()|flatten }}"
loop_control:
loop_var: app
label: "{{ app.binary }}"
tags: [always]
- name: Status commands
ansible.builtin.debug:
msg: "{{ image_status.results|map(attribute='cmd')|map('join', ' ') }}"
when: image_status is changed
tags: [always]
- name: Create binaries
ansible.builtin.command:
cmd: >-
mvn
--no-snapshot-updates
--fail-fast
--batch-mode
--threads 2
--projects {{
image_status.results
| select('changed')
| map(attribute='app.binary')
| map('regex_replace', '^', ':')
| join(',')
}}
--also-make
clean
{{ maven_phase | default('package') }}
--define maven.compiler.release={{ dev[devenv].jdk.release }}
{% if dev[devenv].kotlin is defined %}
--define kotlin.version={{ dev[devenv].kotlin.version }}
{% endif %}
chdir: "{{ project.dir }}"
strip_empty_ends: false
changed_when: true
when: image_status is changed
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/app/build-and-check.yaml
vars:
maven_phase: package
103 changes: 44 additions & 59 deletions baker/ansible/images.yaml
Original file line number Diff line number Diff line change
@@ -1,72 +1,57 @@
---
- import_playbook: binaries.yaml # noqa: name[play]
vars:
maven_phase: "{{ 'install' if binary_repo == 'local' else 'deploy' }}"
tags: [binaries, deps]

- name: Images
- name: Building
hosts: db
run_once: true
tasks:
- name: Capture statuses
ansible.builtin.command:
cmd: >-
docker {{ docker_entity }} inspect
{{ image_ns }}/{{ product.databases[storage].image }}:{{ product.databases[storage].cid }}
register: image_status
changed_when: image_status.rc != 0
failed_when: false
loop: "{{ product.schemas.keys() }}"
loop_control:
loop_var: storage
- name: Status commands
ansible.builtin.debug:
msg: "{{ image_status.results|map(attribute='cmd')|map('join', ' ') }}"
when: image_status is changed
- name: Create images
ansible.builtin.include_role:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/db/capture.yaml
tags: [always]
- ansible.builtin.import_role: # noqa: name[missing]
name: image
tasks_from: clean
vars:
image_tag: "{{ product.databases[storage].cid }}"
image_name: "{{ image_ns }}/{{ product.databases[storage].image }}"
image_home: "{{ project.dir }}/db/{{ storage }}"
image_key: "{{ product.databases[storage].image }}"
image_push: "{{ image_repo != 'local' }}"
loop: "{{ image_status.results|select('changed')|map(attribute='storage') }}"
loop_control:
loop_var: storage
image_keys: >-
{{ image_status.results
| select('changed')
| map(attribute='db.image')
| map('regex_replace', '$', '/' ~ devenv)
}}
when: image_status is changed
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/db/build.yaml
when: image_status is changed

- name: Images
- name: Building & Checking
hosts: app
run_once: true
tasks:
- name: Analyze coverage
ansible.builtin.command:
cmd: >-
mvn
--no-snapshot-updates
--batch-mode
--projects tool
clean
antrun:run@coverage
chdir: "{{ project.dir }}"
strip_empty_ends: false
changed_when: true
when: image_status is changed
- name: Create images
ansible.builtin.include_role:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/app/capture.yaml
tags: [always]
- ansible.builtin.import_role: # noqa: name[missing]
name: image
tasks_from: clean
vars:
image_tag: "{{ image_tags[app.binary] }}"
image_name: "{{ image_ns }}/{{ app.image }}"
image_home: "{{ project.dir }}/app/{{ app.binary }}"
image_context: target/image-context
image_key: "{{ app.image }}/{{ devenv }}"
image_push: "{{ image_repo != '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 }}"
image_keys: >-
{{ image_status.results
| select('changed')
| map(attribute='app.image')
| map('regex_replace', '$', '/' ~ devenv)
}}
when: image_status is changed
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/app/build-and-check.yaml
vars:
maven_phase: "{{ 'deploy' if repo_mode == 'rw' else 'install' }}"
when: image_status is changed

- name: Publishing
hosts: image
run_once: true
tasks:
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/db/publish.yaml
when: hostvars.db.image_status is changed
- ansible.builtin.import_tasks: # noqa: name[missing]
file: tasks/app/publish.yaml
when: hostvars.app.image_status is changed
Loading