From 8c636313ba6b70c9abc06c3bec259c33ec0d0515 Mon Sep 17 00:00:00 2001 From: Pavel Vetokhin Date: Sat, 24 Feb 2024 21:50:40 +0300 Subject: [PATCH] Remove storage when migrations changed (#367) --- .github/Dockerfile | 2 +- .github/workflows/task_proposal.yaml | 2 +- .github/workflows/work_change.yaml | 4 ++-- .github/workflows/work_proposal.yaml | 21 ++++++++++++++++----- app/sepuling-java/Dockerfile | 4 ++-- app/sepuling-kotlin/Dockerfile | 4 ++-- baker/ansible/images.yaml | 4 ++-- baker/ansible/roles/image/tasks/clean.yaml | 2 +- baker/ansible/stacks.yaml | 2 +- baker/ansible/tasks/gear/capture.yaml | 2 +- baker/ansible/tasks/product/capture.yaml | 2 +- baker/ansible/tasks/product/check.yaml | 9 ++++++--- stack/product/Dockerfile | 2 +- stack/product/compose.j2 | 4 ++++ 14 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.github/Dockerfile b/.github/Dockerfile index b232d290..2c232c01 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -1,2 +1,2 @@ FROM scratch -COPY Dockerfile / +COPY Dockerfile . diff --git a/.github/workflows/task_proposal.yaml b/.github/workflows/task_proposal.yaml index 2dad00fc..6a3c5aed 100644 --- a/.github/workflows/task_proposal.yaml +++ b/.github/workflows/task_proposal.yaml @@ -52,7 +52,7 @@ jobs: - uses: mikepenz/action-junit-report@v4.1.0 if: ${{ !cancelled() && (steps.binaries.outcome == 'success' || steps.binaries.outcome == 'failure') }} with: - check_name: Unit test report + check_name: Unit tests report_paths: "**/target/surefire-reports/TEST-*.xml" require_tests: "${{ steps.binaries.outcome == 'failure' }}" fail_on_failure: false diff --git a/.github/workflows/work_change.yaml b/.github/workflows/work_change.yaml index f9d9519d..4f68f2c4 100644 --- a/.github/workflows/work_change.yaml +++ b/.github/workflows/work_change.yaml @@ -58,7 +58,7 @@ jobs: - uses: mikepenz/action-junit-report@v4.1.0 if: ${{ !cancelled() && (steps.images.outcome == 'success' || steps.images.outcome == 'failure') }} with: - check_name: Unit test report + check_name: Unit tests report_paths: "**/target/surefire-reports/TEST-*.xml" require_tests: "${{ steps.images.outcome == 'failure' }}" fail_on_failure: false @@ -66,7 +66,7 @@ jobs: - uses: mikepenz/action-junit-report@v4.1.0 if: ${{ !cancelled() && (steps.images.outcome == 'success' || steps.images.outcome == 'failure') }} with: - check_name: Integration test report + check_name: Integration tests report_paths: "**/target/failsafe-reports/TEST-*.xml" require_tests: "${{ steps.images.outcome == 'failure' }}" fail_on_failure: false diff --git a/.github/workflows/work_proposal.yaml b/.github/workflows/work_proposal.yaml index 5415c3c4..6cc276ee 100644 --- a/.github/workflows/work_proposal.yaml +++ b/.github/workflows/work_proposal.yaml @@ -36,6 +36,15 @@ jobs: with: devenv: ${{ matrix.env.dev }} token: ${{ secrets.GITHUB_TOKEN }} + - name: Run ansible-playbook sources.yaml + run: >- + docker run --rm + --volume $(pwd):$(pwd) + --volume ~/.m2:/root/.m2 + --workdir $(pwd)/baker/ansible + ${{ env.IMAGE_NAME }}:${{ matrix.env.dev }} + ansible-playbook sources.yaml -v + -e devenv=${{ matrix.env.dev }} - name: Run ansible-playbook images.yaml id: images run: >- @@ -54,7 +63,7 @@ jobs: - uses: mikepenz/action-junit-report@v4.1.0 if: ${{ !cancelled() && (steps.images.outcome == 'success' || steps.images.outcome == 'failure') }} with: - check_name: Unit test report (${{ matrix.env.dev }}) + check_name: Unit tests (${{ matrix.env.dev }}) report_paths: "**/target/surefire-reports/TEST-*.xml" require_tests: "${{ steps.images.outcome == 'failure' }}" fail_on_failure: false @@ -62,7 +71,7 @@ jobs: - uses: mikepenz/action-junit-report@v4.1.0 if: ${{ !cancelled() && (steps.images.outcome == 'success' || steps.images.outcome == 'failure') }} with: - check_name: Integration test report (${{ matrix.env.dev }}) + check_name: Integration tests (${{ matrix.env.dev }}) report_paths: "**/target/failsafe-reports/TEST-*.xml" require_tests: "${{ steps.images.outcome == 'failure' }}" fail_on_failure: false @@ -104,6 +113,7 @@ jobs: -e devenv=${{ matrix.env.dev }} -e purpose=${{ matrix.purpose }} -e opsenv=${{ matrix.env.ops }} + -e repo_mode=ro - uses: actions/upload-artifact@v4.3.1 with: name: product-${{ matrix.purpose }}-${{ matrix.env.ops }} @@ -156,10 +166,11 @@ jobs: -e opsenv=${{ matrix.env.ops }} -e reminder=${{ matrix.shard }} -e modulus=2 + -e repo_mode=ro - uses: actions/upload-artifact@v4.3.1 if: ${{ !cancelled() }} with: - name: e2e-test-report-${{ matrix.shard }}-${{ matrix.purpose }}-${{ matrix.env.ops }} + name: e2e-tests-${{ matrix.shard }}-${{ matrix.purpose }}-${{ matrix.env.ops }} path: test/e2e/target/surefire-reports/*.xml if-no-files-found: ignore @@ -223,8 +234,8 @@ jobs: path: artifacts - uses: mikepenz/action-junit-report@v4.1.0 with: - check_name: E2E test report - report_paths: "artifacts/e2e-test-report-*/**/TEST-*.xml" + check_name: End-to-end tests + report_paths: "artifacts/e2e-tests-*/**/TEST-*.xml" fail_on_failure: false job_summary: false diff --git a/app/sepuling-java/Dockerfile b/app/sepuling-java/Dockerfile index 3b4e8095..ad43c95e 100644 --- a/app/sepuling-java/Dockerfile +++ b/app/sepuling-java/Dockerfile @@ -3,8 +3,8 @@ FROM eclipse-temurin:${JAVA_RELEASE}-jre-alpine RUN addgroup -S app && adduser -S app -G app USER app:app WORKDIR /home/app -COPY lib lib -COPY bin bin +COPY --chown=app:app lib lib +COPY --chown=app:app bin bin ENTRYPOINT [ \ "java", "-classpath", "bin/*:lib/*", \ diff --git a/app/sepuling-kotlin/Dockerfile b/app/sepuling-kotlin/Dockerfile index 6826e55d..95b9d8c1 100644 --- a/app/sepuling-kotlin/Dockerfile +++ b/app/sepuling-kotlin/Dockerfile @@ -3,8 +3,8 @@ FROM eclipse-temurin:${JAVA_RELEASE}-jre-alpine RUN addgroup -S app && adduser -S app -G app USER app:app WORKDIR /home/app -COPY lib lib -COPY bin bin +COPY --chown=app:app lib lib +COPY --chown=app:app bin bin ENTRYPOINT [ \ "java", "-classpath", "bin/*:lib/*", \ diff --git a/baker/ansible/images.yaml b/baker/ansible/images.yaml index 016b7204..f898d05a 100644 --- a/baker/ansible/images.yaml +++ b/baker/ansible/images.yaml @@ -20,7 +20,7 @@ {{ image_status.results | select('changed') | map(attribute='vendor') - | map('regex_replace', '^(.*)$', 'db/\\\1/' ~ devenv) + | map('regex_replace', '^(.*)$', 'db/\1/' ~ devenv) }} when: image_status is changed - ansible.builtin.import_tasks: # noqa: name[missing] @@ -39,7 +39,7 @@ {{ image_status.results | select('changed') | map(attribute='app') - | map('regex_replace', '^(.*)$', 'app/\\\1/' ~ devenv) + | map('regex_replace', '^(.*)$', 'app/\1/' ~ devenv) }} when: image_status is changed - ansible.builtin.import_tasks: # noqa: name[missing] diff --git a/baker/ansible/roles/image/tasks/clean.yaml b/baker/ansible/roles/image/tasks/clean.yaml index f5d90a49..7f722f1c 100644 --- a/baker/ansible/roles/image/tasks/clean.yaml +++ b/baker/ansible/roles/image/tasks/clean.yaml @@ -7,7 +7,7 @@ - name: Kill containers ansible.builtin.shell: - cmd: docker container rm -f $(docker ps -aq --filter label=image.key={{ item }}) + cmd: docker container rm -fv $(docker ps -aq --filter label=image.key={{ item }}) strip_empty_ends: false register: kill_outcome failed_when: false diff --git a/baker/ansible/stacks.yaml b/baker/ansible/stacks.yaml index 1bf14057..b1a80f72 100644 --- a/baker/ansible/stacks.yaml +++ b/baker/ansible/stacks.yaml @@ -20,7 +20,7 @@ tags: [build] when: >- hostvars.gear.stack_status is changed and - repo_mode != 'rw' + hostvars.gear.is_virtual.rc != 0 - name: Building & Checking hosts: product diff --git a/baker/ansible/tasks/gear/capture.yaml b/baker/ansible/tasks/gear/capture.yaml index dc649220..b8d55286 100644 --- a/baker/ansible/tasks/gear/capture.yaml +++ b/baker/ansible/tasks/gear/capture.yaml @@ -15,7 +15,7 @@ stack_tag: "{{ devenv }}-{{ stack_cid.stdout[:7] }}" changed_when: false -- name: Capture status +- name: Capture statuses ansible.builtin.command: cmd: docker {{ docker_entity }} inspect {{ image_ns }}/{{ item }} register: stack_status diff --git a/baker/ansible/tasks/product/capture.yaml b/baker/ansible/tasks/product/capture.yaml index 7ce712b5..213bc87f 100644 --- a/baker/ansible/tasks/product/capture.yaml +++ b/baker/ansible/tasks/product/capture.yaml @@ -15,7 +15,7 @@ stack_tag: "{{ opsenv }}-{{ stack_cid.stdout[:7] }}" changed_when: false -- name: Capture status +- name: Capture statuses ansible.builtin.command: cmd: docker {{ docker_entity }} inspect {{ image_ns }}/{{ item }} register: stack_status diff --git a/baker/ansible/tasks/product/check.yaml b/baker/ansible/tasks/product/check.yaml index 0d0fc662..9f9a1949 100644 --- a/baker/ansible/tasks/product/check.yaml +++ b/baker/ansible/tasks/product/check.yaml @@ -1,9 +1,12 @@ --- -- name: Remove stand (or part of it) +- name: Remove storages ansible.builtin.command: - cmd: docker rm -f env-db + cmd: docker container rm -fv storage-{{ vendor }} changed_when: false - when: hostvars.db.image_status|default({}) is changed + loop: "{{ product.databases.keys() }}" + loop_control: + loop_var: vendor + when: hostvars.db.image_status is changed - name: Create network ansible.builtin.shell: diff --git a/stack/product/Dockerfile b/stack/product/Dockerfile index b4f319f8..04fdc270 100644 --- a/stack/product/Dockerfile +++ b/stack/product/Dockerfile @@ -1,2 +1,2 @@ FROM scratch -COPY . / +COPY . . diff --git a/stack/product/compose.j2 b/stack/product/compose.j2 index 481a2249..381f9187 100644 --- a/stack/product/compose.j2 +++ b/stack/product/compose.j2 @@ -15,6 +15,7 @@ configs: {% set database = product.databases[storage.vendor] %} services: storage: + container_name: storage-{{ storage.vendor }} image: {{ storage.image }}:{{ storage.version }}-alpine networks: - product @@ -30,6 +31,7 @@ services: retries: 5 database: + container_name: database-{{ database.name }} image: {{ image_ns }}/db/{{ storage.vendor }}:{{ hostvars.db.image_tags[storage.vendor] }} networks: - product @@ -55,6 +57,7 @@ services: {% for schema in product.schemas[storage.vendor] %} {{ schema.name }}: + container_name: schema-{{ schema.name }} image: {{ image_ns }}/db/{{ storage.vendor }}:{{ hostvars.db.image_tags[storage.vendor] }} networks: - product @@ -79,6 +82,7 @@ services: {% set apps = product.apps[ops[opsenv].app.lang]|selectattr('service', 'in', usages[purpose].apps) %} {% for app in apps %} {{ app.service }}: + container_name: app-{{ app.service }} image: {{ image_ns }}/app/{{ app.name }}:{{ hostvars.app.image_tags[app.name] }} networks: - product