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(ci): add container state test + CI updates #105

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:
steps:
- name: Checkout Codebase
uses: actions/checkout@v3

- name: Pull eclipse-mosquitto image
run: docker pull eclipse-mosquitto:2.0.15

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand All @@ -41,7 +38,7 @@ jobs:
run: python -m pip install -r requirements.txt

- name: Install ansible.utils collection
run: ansible-galaxy collection install ansible.utils
run: ansible-galaxy collection install -r requirements.yml

- name: Generate the Default Komponist Stack
run: ansible-playbook -vv generate_stack.yml
Expand All @@ -56,4 +53,7 @@ jobs:
run: ansible-playbook tests/test_schemas.yml

- name: Test Content Checks for Generated Files for Mosquitto / Node-RED
run: ansible-playbook tests/test_file_contents.yml
run: ansible-playbook tests/test_file_contents.yml

- name: Test Containers for Komponist
run: ansible-playbook tests/test_compose_containers.yml
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ansible
docker
urllib3 < 2.0 # Pin this requirement to combat a current incompatibility with docker and urllib3
urllib3
jsonschema
passlib
7 changes: 7 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
---
collections:
- name: community.docker
version: 3.4.8
- name: ansible.utils
version: 2.10.3
47 changes: 47 additions & 0 deletions tests/test_compose_containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: AGPL-3.0-only
---
- name: Bring the Compose Application up and check if containers exist and are running
hosts: localhost
gather_facts: false
vars_files:
- "{{ playbook_dir }}/../vars/config.yml"

tasks:
- name: Container Checks
block:
- name: (Komponist-Docker) Bring the Compose Application up
ansible.builtin.command:
cmd: docker compose --project-directory="{{ playbook_dir }}/../deploy" up --quiet-pull -d
register: compose_up
changed_when: compose_up.rc != 0

- name: (Komponist-Docker) Obtain information about containers
community.docker.docker_container_info:
name: "{{ komponist.project_name }}_{{ item }}"
register: containers_info
loop: "{{ komponist.configuration.keys() }}"

- name: (Komponist-Docker) Check if containers exist
ansible.builtin.assert:
that: item.exists
fail_msg: "FAIL: {{ item.item }} container DOES NOT EXIST."
success_msg: "PASS: {{ item.item }} container EXISTS."
loop: "{{ containers_info.results }}"
loop_control:
label: "{{ item.item }}"

- name: (Komponist-Docker) Check if containers are running
ansible.builtin.assert:
that: item.container.State.Status == 'running'
fail_msg: "FAIL: {{ item.item }} container NOT RUNNING."
success_msg: "PASS: {{ item.item }} container RUNNING."
loop: "{{ containers_info.results }}"
loop_control:
label: "{{ item.item }}"

always:
- name: (Komponist-Docker) docker compose down --volumes
ansible.builtin.command:
cmd: docker compose --project-directory="{{ playbook_dir }}/../deploy" down --volumes
register: compose_down
changed_when: compose_down.rc != 0