diff options
author | Riku Voipio <riku.voipio@linaro.org> | 2018-08-17 15:28:18 +0300 |
---|---|---|
committer | Riku Voipio <riku.voipio@linaro.org> | 2018-09-10 11:14:16 +0000 |
commit | 81a0e7233f0f2331abe03652bea2fae1cce79a27 (patch) | |
tree | 5420bd40a11dbf40ef4992ac1a6201dada237774 | |
parent | 9470240caeb03bff7e49edcad0205077350358e4 (diff) |
sandbox: add scripts to easily test plays with docker
Automate docker testing. Instead of documenting in Readme.md
just write a script to do it.
Change-Id: Ided972a23545d7bbdf1e0f6fe04dd0a63d26545e
Reviewed-on: https://review.linaro.org/28139
Reviewed-by: Kelley Spoon <kelley.spoon@linaro.org>
Reviewed-by: Benjamin Copeland <ben.copeland@linaro.org>
-rw-r--r-- | README.sandbox | 31 | ||||
-rwxr-xr-x | tests/docker-test.sh | 85 | ||||
-rw-r--r-- | tests/docker-test.yml | 19 |
3 files changed, 113 insertions, 22 deletions
diff --git a/README.sandbox b/README.sandbox index 4f6db003..b0ecdddb 100644 --- a/README.sandbox +++ b/README.sandbox @@ -108,34 +108,21 @@ To login use private key counterpart of pubkey you used during "lxc-create": Choice 3: Docker --------------- -With docker ansible docker connection module, it's possible to create sandboxes by -prepending the playbook you want to try with: +With docker ansible docker connection module, it easy to test sandboxes. We +use ansible to bring up and docker container with the name of the hosts to +deploy on, and then create a temporary inventory to run the tests against. +For example to test gerrit, run: -- name: start up sandbox - hosts: localhost - vars: - base_image: ansible/baseimage:16.04 - docker_hostname: review.linaro.org - tasks: - - name: start docker container by running bash - local_action: docker image={{base_image}} name={{docker_hostname}} detach=yes tty=yes command=bash - - name: add the host to inventory - add_host: name={{docker_hostname}} groups="all, gerrit" + ./tests/docker-test.sh gerrit -Change the main part of play to include just the host you want to work on and set the connection to type to docker: +This will create "review.linaro.org" container and run gerrit playbook on it. -- name: Test gerrit - hosts: review.linaro.org - connection: docker - -And then just run the playbook: - - ansible-playbook gerrit.yml - -You can log in to the docker container with: +To login in to the docker container, run: docker exec -it review.linaro.org /bin/bash +The main limitation this approach is systemd based services won't be +automatically started. After sandbox bring-up ---------------------- diff --git a/tests/docker-test.sh b/tests/docker-test.sh new file mode 100755 index 00000000..6178acb2 --- /dev/null +++ b/tests/docker-test.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +start_docker() { + hostname=$1 + group=$2 + cat > /tmp/hosts <<EOF +[$group] +$hostname ansible_connection=docker +EOF + ansible-playbook --extra-vars "docker_hostname=$hostname" \ + ./tests/docker-test.yml + +} + +snakeoil=" + ssl_cert=/etc/ssl/certs/ssl-cert-snakeoil.pem + ssl_key=/etc/ssl/private/ssl-cert-snakeoil.key + ssl_ca=/etc/ssl/certs/ssl-cert-snakeoil.pem" + + +jenkins_master() +{ + start_docker ci.linaro.org jenkins_master + ansible-playbook --skip-tags="nfs,ssh-ldap,letsencrypt,vpn" \ + --extra-vars "$snakeoil" \ + -i /tmp/hosts \ + ./jenkins-master.yml +} + +gerrit() +{ + start_docker review.linaro.org gerrit + ansible-playbook --skip-tags="imapd" \ + --extra-vars "$snakeoil" \ + -i /tmp/hosts \ + ./gerrit.yml +} + +ssh_ldap() +{ + start_docker mmwg-hackbox.linaro.org ssh-ldap + ansible-playbook \ + -i /tmp/hosts \ + ./ssh-ldap.yml +} + +git() +{ + start_docker git-ap.linaro.org git + ansible-playbook \ + --extra-vars "$snakeoil" \ + -i /tmp/hosts \ + ./git.yml +} + +obs_server() +{ + start_docker obs-server-cn1.linaro.cloud none + ansible-playbook --skip-tags="letsencrypt" \ + --extra-vars "$snakeoil" \ + -i /tmp/hosts \ + -l obs-server-cn1.linaro.cloud \ + ./obs-cn1.yml +} + +case $1 in + jenkins-master) + jenkins_master + ;; + gerrit) + gerrit + ;; + git) + git + ;; + ssh-ldap) + ssh_ldap + ;; + obs-server) + obs_server + ;; + *) + echo usage $0 service-to-test + ;; +esac diff --git a/tests/docker-test.yml b/tests/docker-test.yml new file mode 100644 index 00000000..d479458f --- /dev/null +++ b/tests/docker-test.yml @@ -0,0 +1,19 @@ +# pre-play for docker based testing + +- name: start up docker for {{ docker_hostname }} + hosts: localhost + vars: + base_image: linaro/ci-amd64-ubuntu:xenial + tasks: + - name: get base image + local_action: docker_image name={{ base_image }} + - name: start docker container + local_action: + module: docker_container + name: "{{ docker_hostname }}" + image: "{{ base_image }}" + detach: yes + tty: yes + privileged: yes + command: ["sleep", "infinity"] + |