#185 Add standard role for docker images
Closed 5 years ago by dhodovsk. Opened 5 years ago by dhodovsk.
dhodovsk/standard-test-roles standard-test-image  into  master

@@ -0,0 +1,12 @@ 

+ # Ansible role for docker images

+ 

+ Put this role in your tests.yml playbook. This role will ensure docker engine is installed

+ and running on your localhost, pulls the image specified in image_name and runs the script

+ ./runtest.sh that should execute image tests. You'll need

+ to have the following variables defined:

+ 

+  * image_name: url of image to test

+  * artifacts: An artifacts directory

Hi, I do not see where it is used in this role.
Buy the way we have default definition for it at:

standard-test-roles/roles/str-common-init/defaults/main.yml:
remote_artifacts: /tmp/artifacts/
artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}"

There two different location for artifacts: test-runner or test-environment

+ 

+ Include any playbooks after this role with tests you want to

+ run. For example test_local.yml

Include any playbooks after this role with tests you want to run. For example
test_local.yml

@@ -0,0 +1,4 @@ 

+ ---

+ 

+ dependencies:

+   - role: standard-test-basic

This is very strange approach. What you do:

You run all tasks from : standard-test-basic ... than you run tasks from roles/standard-test-image-docker/tasks/main.yml

What is reason to run standard-test-basic before docker is started ?

Or maybe I do not understand, please correct me.

@@ -0,0 +1,36 @@ 

+ ---

+ - name: Prepare the environment to run tests

+   block:

+   - name: Install the container engine

+     package:

+       name: docker

+       state: present

+     become: true

+   - name: Start the container engine

+     systemd:

+       name: docker

+       state: started

+     become: true

+ 

+ - name: Pull the container image

+   docker_image:

+     name: "{{ image_name }}"

+   register: container_image_under_test

+ 

+ 

+ - block:

+   - name: Create temp dir to store tests

+     tempfile:

+       state: directory

+     register: tmp_tests

+   - name: Execute the role which performs testing

+     import_role:

+       name: standard-test-basic

+     vars:

+       tenv_workdir: "{{ tmp_tests.path }}"

Why do not use default definition tenv_workdir which is defined at :

./roles/str-common-init/defaults/main.yml:5:tenv_workdir: /var/str/

+   always:

+   - name: delete the temp dir

+     file:

+       path: "{{ tmp_tests.path }}"

+       state: absent

+ 

This role is executed on container repositories (with Dockerfile as main component)

Hi, I do not see where it is used in this role.
Buy the way we have default definition for it at:

standard-test-roles/roles/str-common-init/defaults/main.yml:
remote_artifacts: /tmp/artifacts/
artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}"

There two different location for artifacts: test-runner or test-environment

Include any playbooks after this role with tests you want to run. For example
test_local.yml

This is very strange approach. What you do:

You run all tasks from : standard-test-basic ... than you run tasks from roles/standard-test-image-docker/tasks/main.yml

What is reason to run standard-test-basic before docker is started ?

Or maybe I do not understand, please correct me.

Why do not use default definition tenv_workdir which is defined at :

./roles/str-common-init/defaults/main.yml:5:tenv_workdir: /var/str/

Please check comments to code.

This role does two things:

  1. Start docker service.
  2. Fetch Docker image.

The first one could be done in more generic way. Maybe add a new parameter to basic role something like:

required_services:
   - docker
   - httpd

?

This will be more generic approach.

Fetching required image could be a part of tests.yml. Do not see reason to add a whole new role only for this action.

@astepano good comments, good suggestions! I actually originally wrote the code a couple months ago and was fighting Ansible really hard b/c some things just didn't work, @dhodovsk took over to submit it as a PR. Therefore many of the issues you identified are either historical or lack of our Ansible knowledge.

We agree with your proposal. Thank you, Andrei!

Pull-Request has been closed by dhodovsk

5 years ago