From 2d02e5e3bd1e8f8080fa2984e35ee5b44be2c92d Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 10 Oct 2019 09:33:56 -0700 Subject: [PATCH] Add docker buildset test This tests the registry in a buildset configuration under docker. Change-Id: Ifa992feaa4870715b3aa62f560d2d85af8ba7733 --- playbooks/functional-test/cleanup.yaml | 25 +++++ .../functional-test/docker-buildset.yaml | 93 +++++++++++++++++++ playbooks/functional-test/docker.yaml | 6 +- playbooks/functional-test/localtest.yaml | 4 + playbooks/functional-test/run.yaml | 29 +++++- playbooks/functional-test/setup.yaml | 19 ++++ 6 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 playbooks/functional-test/cleanup.yaml create mode 100644 playbooks/functional-test/docker-buildset.yaml diff --git a/playbooks/functional-test/cleanup.yaml b/playbooks/functional-test/cleanup.yaml new file mode 100644 index 0000000..3fe1236 --- /dev/null +++ b/playbooks/functional-test/cleanup.yaml @@ -0,0 +1,25 @@ +- name: Restore docker daemon configuration + when: daemon_config_stat.stat.exists + command: "cp {{ workspace }}/docker-daemon.json /etc/docker/daemon.json" + become: true + +- name: Remove docker daemon configuration + when: not daemon_config_stat.stat.exists + command: "rm /etc/docker/daemon.json" + become: true + +- name: Restart docker daemon + service: + name: docker + state: restarted + become: true + register: docker_restart + failed_when: docker_restart is failed and not 'Could not find the requested service' in docker_restart.msg + +- name: Restore docker user configuration + when: user_config_stat.stat.exists + command: "cp {{ workspace }}/docker-user.json ~/.docker/config.json" + +- name: Remove docker user configuration + when: not user_config_stat.stat.exists + command: "rm ~/.docker/config.json" diff --git a/playbooks/functional-test/docker-buildset.yaml b/playbooks/functional-test/docker-buildset.yaml new file mode 100644 index 0000000..29c6648 --- /dev/null +++ b/playbooks/functional-test/docker-buildset.yaml @@ -0,0 +1,93 @@ +# Test push and pull from the buildset registry + +- name: Create new docker daemon config + set_fact: + new_daemon_config: + registry-mirrors: + - "https://localhost:9000" + +- name: Write docker daemon configuration + copy: + content: "{{ new_daemon_config | to_nice_json }}" + dest: /etc/docker/daemon.json + become: true + +- name: Restart docker daemon + service: + name: docker + state: restarted + become: true + register: docker_restart + failed_when: docker_restart is failed and not 'Could not find the requested service' in docker_restart.msg + +- name: Start the standard registry + shell: + cmd: docker-compose -f standard-compose.yaml up -d + chdir: "{{ ansible_user_dir }}/src/opendev.org/zuul/zuul-registry/playbooks/functional-test" + +- name: Wait for registry to come up + uri: + url: https://localhost:9000/v2/ + validate_certs: false + status_code: 401 + register: result + until: result.status is defined and result.status == 401 + delay: 1 + retries: 120 + +- name: Create new docker user config + set_fact: + new_user_config: {} + +- name: Write docker user configuration + copy: + content: "{{ new_user_config | to_nice_json }}" + dest: ~/.docker/config.json + +- name: Copy the test image into the buildset registry + command: > + skopeo copy --dest-creds testuser:testpass + docker-archive:{{ workspace }}/test.img + docker://localhost:9000/test/image:latest + +- name: Print list of images + command: docker image ls --all --digests --no-trunc + register: image_list + failed_when: + - "'test/image' in image_list.stdout" + - "'alpine' in image_list.stdout" + +- name: Pull the image from the buildset registry + command: docker pull test/image + +- name: Print list of images + command: docker image ls --all --digests --no-trunc + register: image_list + failed_when: "'test/image' not in image_list.stdout" + +- name: Try to pull an image that does not exist + command: docker pull test/dne + register: result + failed_when: result.rc != 1 + +- name: Pull an image from upstream + command: docker pull alpine + +- name: Print list of images + command: docker image ls --all --digests --no-trunc + register: image_list + failed_when: "'alpine' not in image_list.stdout" + +- name: Remove the test image from the local cache + command: docker rmi test/image + +- name: Remove the test image from the local cache + command: docker rmi alpine + +- name: Stop the standard registry + shell: + cmd: docker-compose -f standard-compose.yaml down + chdir: "{{ ansible_user_dir }}/src/opendev.org/zuul/zuul-registry/playbooks/functional-test" + +- name: Clean up docker volumes + command: docker volume prune -f diff --git a/playbooks/functional-test/docker.yaml b/playbooks/functional-test/docker.yaml index 42ea0bd..b19b63b 100644 --- a/playbooks/functional-test/docker.yaml +++ b/playbooks/functional-test/docker.yaml @@ -25,9 +25,6 @@ - name: Remove the test image from the local cache command: docker rmi localhost:9000/test/image -- name: Clean up the local image cache - command: docker image prune -f - - name: Print list of images command: docker image ls --all --digests --no-trunc register: image_list @@ -46,6 +43,9 @@ register: result failed_when: result.rc != 1 +- name: Remove the test image from the local cache + command: docker rmi localhost:9000/test/image + - name: Stop the standard registry shell: cmd: docker-compose -f standard-compose.yaml down diff --git a/playbooks/functional-test/localtest.yaml b/playbooks/functional-test/localtest.yaml index 6fb2797..adb1801 100644 --- a/playbooks/functional-test/localtest.yaml +++ b/playbooks/functional-test/localtest.yaml @@ -7,5 +7,9 @@ include_tasks: setup.yaml - name: Run docker test tasks include_tasks: docker.yaml + - name: Run docker buildset test tasks + include_tasks: docker-buildset.yaml - name: Run podman test tasks include_tasks: podman.yaml + - name: Run cleanup tasks + include_tasks: cleanup.yaml diff --git a/playbooks/functional-test/run.yaml b/playbooks/functional-test/run.yaml index 1f17224..2718e82 100644 --- a/playbooks/functional-test/run.yaml +++ b/playbooks/functional-test/run.yaml @@ -4,15 +4,18 @@ - build-docker-image - hosts: all + name: Set up for tests vars: - workspace: /tmp/registry-test - local: false tasks: + # Set facts here to apply to all plays below + - name: Set variables for all tests + set_fact: + workspace: /tmp/registry-test + local: false - name: Add project atomic PPA apt_repository: repo: ppa:projectatomic/ppa become: true - - name: Install packages package: name: @@ -25,11 +28,31 @@ become: true - name: Run setup tasks include_tasks: setup.yaml + +- hosts: all + name: Run docker standard registry test + tasks: - name: Run docker test tasks include_tasks: docker.yaml + +- hosts: all + name: Run podman standard registry test + tasks: - name: Run podman test tasks include_tasks: podman.yaml +- hosts: all + name: Run docker buildset registry test + tasks: + - name: Run docker buildset test tasks + include_tasks: docker-buildset.yaml + +- hosts: all + name: Clean up after tests + tasks: + - name: Run cleanup tasks + include_tasks: cleanup.yaml + # If buildset_registry is defined, that means a parent job is running it; # only if it is not defined does it mean that we are running it. If we # are running it, pause the job so that child jobs will automatically diff --git a/playbooks/functional-test/setup.yaml b/playbooks/functional-test/setup.yaml index e852248..88aa97f 100644 --- a/playbooks/functional-test/setup.yaml +++ b/playbooks/functional-test/setup.yaml @@ -24,6 +24,25 @@ command: update-ca-certificates become: true +- name: Check if docker daemon configuration exists + stat: + path: /etc/docker/daemon.json + register: daemon_config_stat + +- name: Save docker daemon configuration + when: daemon_config_stat.stat.exists + command: "cp /etc/docker/daemon.json {{ workspace }}/docker-daemon.json" + become: true + +- name: Check if docker user configuration exists + stat: + path: ~/.docker/config.json + register: user_config_stat + +- name: Save docker user configuration + when: user_config_stat.stat.exists + command: "cp ~/.docker/config.json {{ workspace }}/docker-user.json" + - name: Create a local containers image shell: buildah commit --rm $(buildah from scratch) testimage