Sync new tests from upstreamfirst
* the tests is quite old since it moved from upstreamfirst * lots of new cases are added, like option 'run', 'inspect' etc * save log to TEST_ARTIFACTS when the variable is set * always run tests with latest runc built from source * merge task and task status to same line
This commit is contained in:
parent
4770dbb8bf
commit
eea687c42a
@ -1,3 +0,0 @@
|
|||||||
Buildah - a tool which facilitates building OCI container images
|
|
||||||
|
|
||||||
When executing the buildah bud testing, it will cost much time as it is building image in the background.
|
|
@ -24,8 +24,14 @@ except ImportError: # < ansible 2.1
|
|||||||
BASECLASS = DEFAULT_MODULE.CallbackModule
|
BASECLASS = DEFAULT_MODULE.CallbackModule
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
|
try:
|
||||||
|
reload # Python 2.7
|
||||||
|
except NameError:
|
||||||
|
try:
|
||||||
|
from importlib import reload # Python 3.4+
|
||||||
|
except ImportError:
|
||||||
|
from imp import reload
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf-8')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
@ -33,8 +39,8 @@ except ImportError:
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
# Fields to reformat output for
|
# Fields to reformat output for
|
||||||
FIELDS = ['cmd', 'command', 'start', 'end', 'delta', 'msg', 'stdout',
|
FIELDS = ['cmd', 'command', 'msg', 'stdout',
|
||||||
'stderr', 'results', 'failed', 'reason']
|
'stderr', 'failed', 'reason']
|
||||||
|
|
||||||
|
|
||||||
class CallbackModule(CallbackBase):
|
class CallbackModule(CallbackBase):
|
||||||
@ -50,6 +56,9 @@ class CallbackModule(CallbackBase):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# pylint: disable=non-parent-init-called
|
# pylint: disable=non-parent-init-called
|
||||||
BASECLASS.__init__(self, *args, **kwargs)
|
BASECLASS.__init__(self, *args, **kwargs)
|
||||||
|
if os.getenv("TEST_ARTIFACTS") is not None:
|
||||||
|
self.artifacts = os.getenv("TEST_ARTIFACTS")
|
||||||
|
else:
|
||||||
self.artifacts = './artifacts'
|
self.artifacts = './artifacts'
|
||||||
self.result_file = os.path.join(self.artifacts, 'test.log')
|
self.result_file = os.path.join(self.artifacts, 'test.log')
|
||||||
if not os.path.exists(self.artifacts):
|
if not os.path.exists(self.artifacts):
|
||||||
@ -58,27 +67,30 @@ class CallbackModule(CallbackBase):
|
|||||||
|
|
||||||
def human_log(self, data, taskname, status):
|
def human_log(self, data, taskname, status):
|
||||||
if type(data) == dict:
|
if type(data) == dict:
|
||||||
with open('./artifacts/test.log', 'a') as f:
|
with open(self.result_file, 'a') as f:
|
||||||
f.write("\n\n")
|
f.write("################################################################\n")
|
||||||
f.write("# TASK NAME: %s \n" % taskname)
|
f.write('The status is "%s" for task: %s.\n' % (status, taskname))
|
||||||
f.write("# STATUS: %s \n\n" % status)
|
f.write("Ansible outputs: \n\n")
|
||||||
f.write("Outputs: \n\n")
|
|
||||||
for field in FIELDS:
|
for field in FIELDS:
|
||||||
no_log = data.get('_ansible_no_log', False)
|
no_log = data.get('_ansible_no_log', False)
|
||||||
if field in data.keys() and data[field] and no_log != True:
|
if field in data.keys() and data[field] and no_log != True:
|
||||||
output = self._format_output(data[field])
|
output = self._format_output(data[field], field)
|
||||||
# The following two lines are a hack to make it work with UTF-8 characters
|
# The following two lines are a hack to make it work with UTF-8 characters
|
||||||
if type(output) != list:
|
if type(output) != list:
|
||||||
output = output.encode('utf-8', 'replace')
|
output = output.encode('utf-8', 'replace')
|
||||||
#self._display.display("\n{0}:\n{1}".format(field, output.replace("\\n","\n")), log_only=False)
|
if type(output) == bytes:
|
||||||
with open('./artifacts/test.log', 'a') as f:
|
output = output.decode('utf-8')
|
||||||
|
|
||||||
f.write("{0}: {1}".format(field, output.replace("\\n","\n"))+"\n")
|
f.write("{0}: {1}".format(field, output.replace("\\n","\n"))+"\n")
|
||||||
|
|
||||||
|
|
||||||
def _format_output(self, output):
|
def _format_output(self, output, field):
|
||||||
# Strip unicode
|
# Strip unicode
|
||||||
|
try:
|
||||||
if type(output) == unicode:
|
if type(output) == unicode:
|
||||||
output = output.encode(sys.getdefaultencoding(), 'replace')
|
output = output.encode(sys.getdefaultencoding(), 'replace')
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
# If output is a dict
|
# If output is a dict
|
||||||
if type(output) == dict:
|
if type(output) == dict:
|
||||||
@ -94,12 +106,14 @@ class CallbackModule(CallbackBase):
|
|||||||
if type(item) == dict:
|
if type(item) == dict:
|
||||||
for field in FIELDS:
|
for field in FIELDS:
|
||||||
if field in item.keys():
|
if field in item.keys():
|
||||||
copy[field] = self._format_output(item[field])
|
copy[field] = self._format_output(item[field], field)
|
||||||
real_output.append(copy)
|
real_output.append(copy)
|
||||||
return json.dumps(output, indent=2, sort_keys=True)
|
return json.dumps(output, indent=2, sort_keys=True)
|
||||||
|
|
||||||
# If output is a list of strings
|
# If output is a list of strings
|
||||||
if type(output) == list and type(output[0]) != dict:
|
if type(output) == list and type(output[0]) != dict:
|
||||||
|
if field == "cmd":
|
||||||
|
return ' '.join(output)
|
||||||
return '\n'.join(output)
|
return '\n'.join(output)
|
||||||
|
|
||||||
# Otherwise it's a string, (or an int, float, etc.) just return it
|
# Otherwise it's a string, (or an int, float, etc.) just return it
|
||||||
@ -110,16 +124,18 @@ class CallbackModule(CallbackBase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def v2_runner_on_failed(self, result, ignore_errors=False):
|
def v2_runner_on_failed(self, result, ignore_errors=False):
|
||||||
self.human_log(result._result, result._task.name, "fail")
|
self.human_log(result._result, result._task.name, "FAIL")
|
||||||
|
|
||||||
def v2_runner_on_ok(self, result):
|
def v2_runner_on_ok(self, result):
|
||||||
self.human_log(result._result, result._task.name, "pass")
|
if result._task.name == "":
|
||||||
|
return
|
||||||
|
self.human_log(result._result, result._task.name, "PASS")
|
||||||
|
|
||||||
def v2_runner_on_skipped(self, result):
|
def v2_runner_on_skipped(self, result):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def v2_runner_on_unreachable(self, result):
|
def v2_runner_on_unreachable(self, result):
|
||||||
self.human_log(result._result, result._task.name, "unreachable")
|
self.human_log(result._result, result._task.name, "UNREACHABLE")
|
||||||
|
|
||||||
def v2_runner_on_no_hosts(self, task):
|
def v2_runner_on_no_hosts(self, task):
|
||||||
pass
|
pass
|
||||||
@ -128,10 +144,10 @@ class CallbackModule(CallbackBase):
|
|||||||
self.human_log(result._result, result._task.name, "")
|
self.human_log(result._result, result._task.name, "")
|
||||||
|
|
||||||
def v2_runner_on_async_ok(self, host, result):
|
def v2_runner_on_async_ok(self, host, result):
|
||||||
self.human_log(result._result, result._task.name, "pass")
|
self.human_log(result._result, result._task.name, "PASS")
|
||||||
|
|
||||||
def v2_runner_on_async_failed(self, result):
|
def v2_runner_on_async_failed(self, result):
|
||||||
self.human_log(result._result, result._task.name, "fail")
|
self.human_log(result._result, result._task.name, "FAIL")
|
||||||
|
|
||||||
def v2_playbook_on_start(self, playbook):
|
def v2_playbook_on_start(self, playbook):
|
||||||
pass
|
pass
|
||||||
|
1
tests/github.sh
Executable file
1
tests/github.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
ansible-playbook -i inventory github.yml "$@"
|
19
tests/github.yml
Normal file
19
tests/github.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
# test buildah
|
||||||
|
- hosts: localhost
|
||||||
|
become: true
|
||||||
|
tags:
|
||||||
|
- classic
|
||||||
|
roles:
|
||||||
|
- role: prepare-env
|
||||||
|
tags:
|
||||||
|
- env
|
||||||
|
- role: github-buildah
|
||||||
|
tags:
|
||||||
|
- github-buildah
|
||||||
|
- role: github-runc
|
||||||
|
tags:
|
||||||
|
- github-runc
|
||||||
|
- role: cli
|
||||||
|
tags:
|
||||||
|
- cli
|
@ -23,19 +23,36 @@
|
|||||||
- name: check buildah add URL to destination
|
- name: check buildah add URL to destination
|
||||||
command: ls {{mount.stdout}}/home/README.md
|
command: ls {{mount.stdout}}/home/README.md
|
||||||
|
|
||||||
|
- name: create /tmp/buildah/addcopy
|
||||||
|
file: path=/tmp/buildah/addcopy state=directory
|
||||||
|
|
||||||
- name: Download buildah README.md
|
- name: Download buildah README.md
|
||||||
get_url:
|
get_url:
|
||||||
url: https://github.com/projectatomic/buildah/raw/master/README.md
|
url: https://github.com/projectatomic/buildah/raw/master/README.md
|
||||||
dest: /tmp/buildah/
|
dest: /tmp/buildah/addcopy/
|
||||||
|
|
||||||
- name: buildah add dir
|
- name: buildah add dir
|
||||||
command: buildah add nginxc /tmp
|
command: buildah add nginxc /tmp/buildah
|
||||||
|
|
||||||
- name: check buildah add dir
|
- name: check buildah add dir
|
||||||
command: ls {{mount.stdout}}/buildah/README.md
|
command: ls {{mount.stdout}}/addcopy/README.md
|
||||||
|
|
||||||
- name: buildah add dir to destination
|
- name: buildah add dir to destination
|
||||||
command: buildah add nginxc /tmp /home
|
command: buildah add nginxc /tmp/buildah /home
|
||||||
|
|
||||||
- name: check buildah add dir to destination
|
- name: check buildah add dir to destination
|
||||||
command: ls {{mount.stdout}}/home/buildah/README.md
|
command: ls {{mount.stdout}}/home/addcopy/README.md
|
||||||
|
|
||||||
|
- name: buildah add a tarball file
|
||||||
|
command: buildah add nginxc /var/www/html/bud/Dockerfile.tar.gz /home
|
||||||
|
|
||||||
|
- name: check buildah has added content of tarball to container
|
||||||
|
command: ls {{mount.stdout}}/home/hello
|
||||||
|
|
||||||
|
- name: buildah add with option chown
|
||||||
|
command: buildah add --chown bin:bin nginxc /tmp/buildah/bud /home
|
||||||
|
|
||||||
|
- name: check user after add with option chown
|
||||||
|
raw: buildah run nginxc -- ls -l /home/hello
|
||||||
|
register: ast
|
||||||
|
failed_when: '"bin" not in ast.stdout'
|
||||||
|
@ -1,24 +1,103 @@
|
|||||||
---
|
---
|
||||||
- name: buildah bud localfile
|
- name: buildah bud with image's format oci
|
||||||
command: buildah bud -t testing/nginx --pull /tmp/buildah/bud
|
command: buildah bud --format=oci --tag testing/fmtoci /tmp/buildah/bud
|
||||||
|
|
||||||
- name: check bud images with buildah images command
|
- name: buildah bud with image's format docker
|
||||||
shell: buildah images | grep testing/nginx
|
command: buildah bud -t testing/fmtdocker --format=docker /tmp/buildah/bud
|
||||||
|
|
||||||
|
- name: buildah bud localfile
|
||||||
|
command: buildah bud -t testing/hello --pull /tmp/buildah/bud
|
||||||
|
|
||||||
- name: buildah bud -f localfile
|
- name: buildah bud -f localfile
|
||||||
command: buildah bud -t testing/nginx2 -f /tmp/buildah/bud/Dockerfile .
|
command: buildah bud -t testing/hello2 -f /tmp/buildah/bud/Dockerfile /tmp/buildah/bud
|
||||||
|
|
||||||
- name: buildah bud URL
|
- name: buildah bud URL
|
||||||
command: buildah bud -t testing/nginx3 http://localhost/bud/Dockerfile.tar.gz
|
command: buildah bud -t testing/hello3 http://localhost/bud/Dockerfile.tar.gz
|
||||||
|
|
||||||
- name: buildah build-using-dockerfile localfile
|
- name: buildah build-using-dockerfile localfile
|
||||||
command: buildah build-using-dockerfile -t testing/nginx4 /tmp/buildah/bud
|
command: buildah build-using-dockerfile -t testing/hello4 /tmp/buildah/bud
|
||||||
|
|
||||||
- name: buildah build-using-dockerfile -f localfile
|
- lineinfile:
|
||||||
command: buildah build-using-dockerfile -t testing/nginx5 --file /tmp/buildah/bud/Dockerfile .
|
path: /tmp/buildah/bud/Dockerfile
|
||||||
|
regexp: '^COPY'
|
||||||
|
line: 'COPY $foo /'
|
||||||
|
|
||||||
- name: buildah build-using-dockerfile URL
|
- name: buildah bud with build-arg
|
||||||
command: buildah build-using-dockerfile --tag testing/nginx6 http://localhost/bud/Dockerfile.tar.gz
|
command: buildah bud -t testing/hello5 --build-arg foo=hello /tmp/buildah/bud
|
||||||
|
|
||||||
- name: buildah rmi
|
- name: create container from bud images
|
||||||
command: buildah rmi testing/nginx{2..6}
|
command: buildah from docker.io/testing/{{ item }}
|
||||||
|
with_items:
|
||||||
|
- hello
|
||||||
|
- hello2
|
||||||
|
- hello3
|
||||||
|
- hello4
|
||||||
|
- hello5
|
||||||
|
|
||||||
|
- name: list containers
|
||||||
|
command: buildah containers
|
||||||
|
register: ctrs
|
||||||
|
|
||||||
|
- name: run containers from bud images
|
||||||
|
command: buildah run {{ item }}-working-container
|
||||||
|
register: hello
|
||||||
|
with_items:
|
||||||
|
- hello
|
||||||
|
- hello2
|
||||||
|
- hello3
|
||||||
|
- hello4
|
||||||
|
- hello5
|
||||||
|
|
||||||
|
- name: verify string hello in container hellos
|
||||||
|
fail:
|
||||||
|
msg: '"Hello from Docker" not found after container run'
|
||||||
|
when: '"Hello from Docker" not in item.stdout'
|
||||||
|
with_items: "{{ hello.results }}"
|
||||||
|
|
||||||
|
- name: buildah rm containers of hello
|
||||||
|
command: buildah rm {{ item }}-working-container
|
||||||
|
with_items:
|
||||||
|
- hello
|
||||||
|
- hello2
|
||||||
|
- hello3
|
||||||
|
- hello4
|
||||||
|
- hello5
|
||||||
|
|
||||||
|
|
||||||
|
- name: buildah bud --quiet
|
||||||
|
command: buildah bud --quiet -t testing/hello6 /tmp/buildah/bud
|
||||||
|
register: budquiet
|
||||||
|
failed_when: '"STEP" in budquiet.stdout'
|
||||||
|
|
||||||
|
- name: buildah bud -q
|
||||||
|
command: buildah bud -q -t testing/hello7 /tmp/buildah/bud
|
||||||
|
register: budq
|
||||||
|
failed_when: '"STEP" in budq.stdout'
|
||||||
|
|
||||||
|
- lineinfile:
|
||||||
|
path: /tmp/buildah/bud/Dockerfile
|
||||||
|
regexp: "^FROM"
|
||||||
|
line: "FROM localhost:5000/buildah/busybox"
|
||||||
|
|
||||||
|
- name: verify bud image from local docker registry without tls-verify is failed
|
||||||
|
command: buildah bud -t testing/hellofail /tmp/buildah/bud
|
||||||
|
register: st
|
||||||
|
failed_when: st.rc != 1
|
||||||
|
|
||||||
|
- name: buildah bud image from local docker registry is successful
|
||||||
|
command: buildah bud --tls-verify=false -t testing/hello8 /tmp/buildah/bud
|
||||||
|
|
||||||
|
- name: buildah rmi hello images
|
||||||
|
command: buildah rmi {{ item }}
|
||||||
|
with_items:
|
||||||
|
- testing/hello
|
||||||
|
- testing/hello2
|
||||||
|
- testing/hello3
|
||||||
|
- testing/hello4
|
||||||
|
- testing/hello5
|
||||||
|
- testing/hello6
|
||||||
|
- testing/hello7
|
||||||
|
- testing/hello8
|
||||||
|
- testing/fmtoci
|
||||||
|
- testing/fmtdocker
|
||||||
|
- localhost:5000/buildah/busybox
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
---
|
---
|
||||||
- name: remove buildah containers after testing
|
- block:
|
||||||
command: buildah rm busybox nginxc nginxc-2
|
- name: remove all buildah containers after testing
|
||||||
ignore_errors: true
|
command: buildah rm -a
|
||||||
|
|
||||||
|
- name: remove all images after testing
|
||||||
|
command: buildah rmi -a
|
||||||
|
|
||||||
|
always:
|
||||||
|
- include_role:
|
||||||
|
name: tear-down
|
||||||
|
59
tests/roles/cli/tasks/commit.yaml
Normal file
59
tests/roles/cli/tasks/commit.yaml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
- name: buildah commit an image by name
|
||||||
|
command: buildah commit nginxc-2 commitbyname/nginxbyname
|
||||||
|
|
||||||
|
- name: check commit images by name is existed
|
||||||
|
command: buildah images commitbyname/nginxbyname
|
||||||
|
|
||||||
|
- name: get container ID
|
||||||
|
shell: buildah containers | grep nginxc-2 | awk '{print $1}'
|
||||||
|
register: cid
|
||||||
|
|
||||||
|
- name: buildah commit an image by ID
|
||||||
|
command: buildah commit {{ cid.stdout }} commitbyid/nginxbyid
|
||||||
|
|
||||||
|
- name: check commit images by ID is existed
|
||||||
|
command: buildah images commitbyid/nginxbyid
|
||||||
|
|
||||||
|
- name: buildah from commit image
|
||||||
|
command: buildah from docker.io/commitbyid/nginxbyid
|
||||||
|
|
||||||
|
- name: check container nginxbyid exists by inspect
|
||||||
|
command: buildah inspect nginxbyid-working-container
|
||||||
|
|
||||||
|
- name: buildah commit to docker-distribution
|
||||||
|
command: buildah commit --tls-verify=false nginxbyid-working-container docker://localhost:5000/commit/nginx
|
||||||
|
|
||||||
|
- name: buildah commit quiet
|
||||||
|
command: buildah commit --quiet --tls-verify=false nginxbyid-working-container docker://localhost:5000/commit/nginx
|
||||||
|
register: quietcommit
|
||||||
|
failed_when: '"Getting" in quietcommit.stdout'
|
||||||
|
|
||||||
|
- name: create container from commit images on docker-distribution
|
||||||
|
command: buildah from --tls-verify=false docker://localhost:5000/commit/nginx
|
||||||
|
|
||||||
|
- name: buildah commit with rm container
|
||||||
|
command: buildah commit --rm -q --tls-verify=false nginxbyid-working-container docker://localhost:5000/commit/nginx
|
||||||
|
|
||||||
|
- name: verify the container is removed after commit
|
||||||
|
command: buildah inspect nginxbyid-working-container
|
||||||
|
register: commitrm
|
||||||
|
failed_when: commitrm.rc != 1
|
||||||
|
|
||||||
|
- name: buildah commit format oci
|
||||||
|
command: buildah commit --disable-compression --format=oci nginx-working-container nginxoci
|
||||||
|
|
||||||
|
- name: buildah commit format docker
|
||||||
|
command: buildah commit -D -f docker nginx-working-container nginxdocker
|
||||||
|
|
||||||
|
- name: remove containers from commit images
|
||||||
|
command: buildah rm nginx-working-container
|
||||||
|
|
||||||
|
- name: remove images from commit
|
||||||
|
command: buildah rmi {{ item }}
|
||||||
|
with_items:
|
||||||
|
- localhost:5000/commit/nginx
|
||||||
|
- commitbyid/nginxbyid
|
||||||
|
- commitbyname/nginxbyname
|
||||||
|
- nginxoci
|
||||||
|
- nginxdocker
|
@ -1,16 +1,48 @@
|
|||||||
---
|
---
|
||||||
|
- name: buildah config annotation
|
||||||
|
command: buildah config --annotation annotation=test-annotation nginxc
|
||||||
|
|
||||||
|
- name: buildah config arch
|
||||||
|
command: buildah config --arch x86_64 nginxc
|
||||||
|
|
||||||
|
- name: buildah config author
|
||||||
|
command: buildah config --author "Guohua Ouyang" nginxc
|
||||||
|
|
||||||
|
- name: buildah config cmd
|
||||||
|
command: buildah config --cmd "nginx -g 'daemon off;'" nginxc
|
||||||
|
|
||||||
|
- name: buildah config createdby
|
||||||
|
command: buildah config --created-by "manualcreated" nginxc
|
||||||
|
|
||||||
|
- name: buildah config label
|
||||||
|
command: buildah config --label label=test-label nginxc
|
||||||
|
|
||||||
|
- name: buildah config port
|
||||||
|
command: buildah config --port 8001 nginxc
|
||||||
|
|
||||||
|
- name: buildah config user
|
||||||
|
command: buildah config --user www-data nginxc
|
||||||
|
|
||||||
- name: buildah config workingdir
|
- name: buildah config workingdir
|
||||||
command: buildah config --workingdir /opt nginxc
|
command: buildah config --workingdir /opt nginxc
|
||||||
|
|
||||||
- name: get buildah config workingdir
|
|
||||||
command: buildah run nginxc "pwd"
|
|
||||||
register: checkworkingdir
|
|
||||||
failed_when: "'/opt' not in checkworkingdir.stdout"
|
|
||||||
|
|
||||||
- name: buildah config env
|
- name: buildah config env
|
||||||
command: buildah config --env foo=bar nginxc
|
command: buildah config --env foo=bar nginxc
|
||||||
|
|
||||||
- name: get buildah config env
|
- name: buildah config os
|
||||||
command: buildah run nginxc env
|
command: buildah config --os unix nginxc
|
||||||
register: env
|
|
||||||
failed_when: "'foo=bar' not in env.stdout"
|
- name: verify the container after config
|
||||||
|
shell: buildah inspect nginxc | grep '{{ item }}'
|
||||||
|
with_items:
|
||||||
|
- test-annotation
|
||||||
|
- x86_64
|
||||||
|
- test-label
|
||||||
|
- Ouyang
|
||||||
|
- daemon off
|
||||||
|
- manualcreated
|
||||||
|
- 8001
|
||||||
|
- www-data
|
||||||
|
- opt
|
||||||
|
- foo=bar
|
||||||
|
- unix
|
||||||
|
@ -23,19 +23,22 @@
|
|||||||
- name: check buildah copy URL to destination
|
- name: check buildah copy URL to destination
|
||||||
command: ls {{mount.stdout}}/home/README.md
|
command: ls {{mount.stdout}}/home/README.md
|
||||||
|
|
||||||
- name: Download buildah README.md
|
|
||||||
get_url:
|
|
||||||
url: https://github.com/projectatomic/buildah/raw/master/README.md
|
|
||||||
dest: /tmp/buildah/
|
|
||||||
|
|
||||||
- name: buildah copy dir
|
- name: buildah copy dir
|
||||||
command: buildah copy nginxc-2 /tmp/buildah
|
command: buildah copy nginxc-2 /tmp/buildah
|
||||||
|
|
||||||
- name: check buildah copy dir
|
- name: check buildah copy dir
|
||||||
command: ls {{mount.stdout}}/README.md
|
command: ls {{mount.stdout}}/addcopy/README.md
|
||||||
|
|
||||||
- name: buildah copy dir to destination
|
- name: buildah copy dir to destination
|
||||||
command: buildah copy nginxc-2 /tmp /home
|
command: buildah copy nginxc-2 /tmp/buildah /home
|
||||||
|
|
||||||
- name: check buildah copy dir to destination
|
- name: check buildah copy dir to destination
|
||||||
command: ls {{mount.stdout}}/home/buildah/README.md
|
command: ls {{mount.stdout}}/home/addcopy/README.md
|
||||||
|
|
||||||
|
- name: buildah copy with option chown
|
||||||
|
command: buildah copy --chown nginx:nginx nginxc-2 /tmp/buildah/bud /home
|
||||||
|
|
||||||
|
- name: check user after copy with option chown
|
||||||
|
command: buildah run nginxc-2 -- ls -l /home/hello
|
||||||
|
register: cst
|
||||||
|
failed_when: '"nginx" not in cst.stdout'
|
||||||
|
@ -1,12 +1,23 @@
|
|||||||
---
|
---
|
||||||
- name: buildah from pull
|
- name: remove all containers before pull
|
||||||
command: buildah from --pull nginx
|
command: buildah rm --all
|
||||||
|
|
||||||
- name: buildah from pull always
|
- name: buildah from without pull
|
||||||
command: buildah from --pull-always nginx
|
command: buildah from --name nginxc docker.io/nginx
|
||||||
|
|
||||||
- name: buildah from with name
|
- name: buildah from with pull
|
||||||
command: buildah from --name nginx nginx
|
command: buildah from --pull --name nginxc-2 docker.io/nginx
|
||||||
|
|
||||||
- name: clean from testings
|
- name: buildah from with pull always
|
||||||
command: buildah delete nginx nginx-working-container nginx-working-container-2
|
command: buildah from --pull-always docker.io/busybox
|
||||||
|
|
||||||
|
- name: remove busybox-working-container
|
||||||
|
command: buildah rm busybox-working-container
|
||||||
|
|
||||||
|
- name: remove exist image so it will pull again
|
||||||
|
command: buildah rmi busybox
|
||||||
|
|
||||||
|
- name: buildah from with quiet
|
||||||
|
command: buildah from --quiet docker.io/busybox
|
||||||
|
register: quietpull
|
||||||
|
failed_when: '"Getting" in quietpull.stdout'
|
||||||
|
65
tests/roles/cli/tasks/images.yaml
Normal file
65
tests/roles/cli/tasks/images.yaml
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
- name: verify buildah images digests
|
||||||
|
command: buildah images --digests
|
||||||
|
register: digest
|
||||||
|
failed_when: '"sha256" not in digest.stdout'
|
||||||
|
|
||||||
|
- name: verify buildah images output json
|
||||||
|
command: buildah images --json
|
||||||
|
register: json
|
||||||
|
failed_when: '"id" not in json.stdout'
|
||||||
|
|
||||||
|
- name: verify buildah images noheading
|
||||||
|
command: buildah images --noheading
|
||||||
|
register: head
|
||||||
|
failed_when: '"IMAGE" in head.stdout'
|
||||||
|
|
||||||
|
- name: verify buildah images quiet
|
||||||
|
command: buildah images --quiet
|
||||||
|
register: quiet
|
||||||
|
failed_when: '"NAME" in quiet.stdout'
|
||||||
|
|
||||||
|
- name: verify buildah images format output
|
||||||
|
command: buildah images --format "{% raw %}{{.ID}} {{.Name}} {{.CreatedAt}} {{.Size}}{% endraw %}"
|
||||||
|
register: format
|
||||||
|
|
||||||
|
- lineinfile:
|
||||||
|
path: /tmp/buildah/bud/Dockerfile
|
||||||
|
insertafter: '^FROM'
|
||||||
|
line: 'LABEL project=buildah'
|
||||||
|
|
||||||
|
- name: buildah bud with LABEL in Dockerfile
|
||||||
|
command: buildah bud --tls-verify=false -t testing/label /tmp/buildah/bud
|
||||||
|
|
||||||
|
- name: verify buildah images filter by label
|
||||||
|
command: buildah images -f "label=project=buildah"
|
||||||
|
register: label
|
||||||
|
failed_when: '"testing/label" not in label.stdout'
|
||||||
|
|
||||||
|
- name: buildah bud an image to test filter since/before
|
||||||
|
command: buildah bud -t testing/since /tmp/buildah/bud
|
||||||
|
|
||||||
|
- name: verify buildah images filter by since
|
||||||
|
command: buildah images -f "since=label"
|
||||||
|
register: since
|
||||||
|
failed_when: '"testing/label" in since.stdout and "testing/since" in since.stdout'
|
||||||
|
|
||||||
|
- name: verify buildah images filter by before
|
||||||
|
command: buildah images -f "before=since"
|
||||||
|
register: before
|
||||||
|
failed_when: '"testing/label" not in before.stdout and "testing/since" in before.stdout'
|
||||||
|
|
||||||
|
- name: buildah build an image to test filter dangling
|
||||||
|
command: buildah bud -t testing/label /tmp/buildah/bud
|
||||||
|
|
||||||
|
- name: verify buildah images filter by dangling
|
||||||
|
command: buildah images -f "dangling=true" -q
|
||||||
|
register: dangling
|
||||||
|
|
||||||
|
- name: remove testing images after buildah images
|
||||||
|
command: buildah rmi {{ item }}
|
||||||
|
with_items:
|
||||||
|
- testing/label
|
||||||
|
- testing/since
|
||||||
|
- "{{ dangling.stdout }}"
|
||||||
|
- localhost:5000/buildah/busybox
|
25
tests/roles/cli/tasks/inspect.yaml
Normal file
25
tests/roles/cli/tasks/inspect.yaml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
- name: buildah inspect an image by name
|
||||||
|
command: buildah inspect docker.io/library/nginx:latest
|
||||||
|
|
||||||
|
- name: get image ID
|
||||||
|
command: buildah images -q docker.io/library/nginx:latest
|
||||||
|
register: imgid
|
||||||
|
|
||||||
|
- name: buildah inspect an image by ID
|
||||||
|
command: buildah inspect --type image {{ imgid.stdout }}
|
||||||
|
|
||||||
|
- name: buildah inspect image with format
|
||||||
|
command: buildah inspect -t image -f {% raw %}'{{ .FromImageID }}'{% endraw %} {{ imgid.stdout }}
|
||||||
|
register: inspectid
|
||||||
|
failed_when: 'inspectid.stdout != imgid.stdout'
|
||||||
|
|
||||||
|
- name: buildah inspect container by name
|
||||||
|
command: buildah inspect -t container nginxc-2
|
||||||
|
|
||||||
|
- name: buildah inspect container with format
|
||||||
|
shell: buildah inspect -f {% raw %}'{{ .ContainerID }}'{% endraw %} nginxc-2
|
||||||
|
register: inspectcid
|
||||||
|
|
||||||
|
- name: buildah inspect container by ID
|
||||||
|
command: buildah inspect {{ inspectcid.stdout }}
|
@ -1,20 +1,20 @@
|
|||||||
---
|
---
|
||||||
- block:
|
- block:
|
||||||
- name: prepare containers nginxc
|
- name: buildah version
|
||||||
import_tasks: prepare-containers.yaml
|
import_tasks: version.yaml
|
||||||
tags:
|
tags:
|
||||||
- nginxc
|
- version
|
||||||
|
|
||||||
- name: buildah containers
|
|
||||||
import_tasks: containers.yaml
|
|
||||||
tags:
|
|
||||||
- ctr
|
|
||||||
|
|
||||||
- name: buildah from
|
- name: buildah from
|
||||||
import_tasks: from.yaml
|
import_tasks: from.yaml
|
||||||
tags:
|
tags:
|
||||||
- from
|
- from
|
||||||
|
|
||||||
|
- name: buildah containers
|
||||||
|
import_tasks: containers.yaml
|
||||||
|
tags:
|
||||||
|
- ctr
|
||||||
|
|
||||||
- name: buildah mount
|
- name: buildah mount
|
||||||
import_tasks: mount.yaml
|
import_tasks: mount.yaml
|
||||||
tags:
|
tags:
|
||||||
@ -30,6 +30,16 @@
|
|||||||
tags:
|
tags:
|
||||||
- config
|
- config
|
||||||
|
|
||||||
|
- name: buildah commit
|
||||||
|
import_tasks: commit.yaml
|
||||||
|
tags:
|
||||||
|
- commit
|
||||||
|
|
||||||
|
- name: buildah inspect
|
||||||
|
import_tasks: inspect.yaml
|
||||||
|
tags:
|
||||||
|
- inspect
|
||||||
|
|
||||||
- name: buildah push
|
- name: buildah push
|
||||||
import_tasks: push.yaml
|
import_tasks: push.yaml
|
||||||
tags:
|
tags:
|
||||||
@ -40,5 +50,15 @@
|
|||||||
tags:
|
tags:
|
||||||
- bud
|
- bud
|
||||||
|
|
||||||
|
- name: buildah images
|
||||||
|
import_tasks: images.yaml
|
||||||
|
tags:
|
||||||
|
- images
|
||||||
|
|
||||||
|
- name: buildah run
|
||||||
|
import_tasks: run.yaml
|
||||||
|
tags:
|
||||||
|
- run
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- import_tasks: cleanup.yaml
|
- import_tasks: cleanup.yaml
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: pull busybox before push
|
- name: pull busybox before push
|
||||||
command: buildah from --pull --name busybox busybox
|
command: buildah from --pull --name busybox docker.io/busybox
|
||||||
|
|
||||||
- name: buildah push image to containers-storage
|
- name: buildah push image to containers-storage
|
||||||
command: buildah push docker.io/busybox:latest containers-storage:docker.io/busybox:latest
|
command: buildah push docker.io/busybox:latest containers-storage:docker.io/busybox:latest
|
||||||
@ -46,15 +46,20 @@
|
|||||||
|
|
||||||
- name: init default ostree repo
|
- name: init default ostree repo
|
||||||
command: ostree --repo=/ostree/repo init
|
command: ostree --repo=/ostree/repo init
|
||||||
|
when: not ansible_distribution == "CentOS"
|
||||||
|
|
||||||
- name: create /tmp/buildah/ostree/repo
|
- name: create /tmp/buildah/ostree/repo
|
||||||
file: path=/tmp/buildah/ostree/repo state=directory
|
file: path=/tmp/buildah/ostree/repo state=directory
|
||||||
|
when: not ansible_distribution == "CentOS"
|
||||||
|
|
||||||
- name: init tmp ostree repo
|
- name: init tmp ostree repo
|
||||||
command: ostree --repo=/tmp/buildah/ostree/repo init
|
command: ostree --repo=/tmp/buildah/ostree/repo init
|
||||||
|
when: not ansible_distribution == "CentOS"
|
||||||
|
|
||||||
- name: buildah push image to ostree
|
- name: buildah push image to ostree
|
||||||
command: buildah push docker.io/busybox:latest ostree:busybox:latest
|
command: buildah push docker.io/busybox:latest ostree:busybox:latest
|
||||||
|
when: not ansible_distribution == "CentOS"
|
||||||
|
|
||||||
- name: buildah push image to non-default ostree repo
|
- name: buildah push image to non-default ostree repo
|
||||||
command: buildah push docker.io/busybox:latest ostree:busybox:latest@/tmp/buildah/ostree/repo
|
command: buildah push docker.io/busybox:latest ostree:busybox:latest@/tmp/buildah/ostree/repo
|
||||||
|
when: not ansible_distribution == "CentOS"
|
||||||
|
10
tests/roles/cli/tasks/run.yaml
Normal file
10
tests/roles/cli/tasks/run.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
- name: buildah run with option hostname
|
||||||
|
command: buildah run --hostname example.buildah.com nginxc -- hostname
|
||||||
|
register: hostname
|
||||||
|
failed_when: '"example.buildah.com" not in hostname.stdout'
|
||||||
|
|
||||||
|
- name: buildah run with option volume
|
||||||
|
command: buildah run --volume /tmp/buildah/bud:/home nginxc ls /home
|
||||||
|
register: volume
|
||||||
|
failed_when: '"hello" not in volume.stdout'
|
@ -1,7 +1,4 @@
|
|||||||
---
|
---
|
||||||
- name: buildah from --pull busybox
|
|
||||||
command: buildah from busybox
|
|
||||||
|
|
||||||
- name: buildah tag by name
|
- name: buildah tag by name
|
||||||
command: buildah tag busybox busybox1
|
command: buildah tag busybox busybox1
|
||||||
|
|
||||||
@ -19,7 +16,7 @@
|
|||||||
shell: buildah images | grep busybox2
|
shell: buildah images | grep busybox2
|
||||||
|
|
||||||
- name: buildah from tagged image
|
- name: buildah from tagged image
|
||||||
command: buildah from busybox1
|
command: buildah from docker.io/busybox1
|
||||||
|
|
||||||
- name: mount the container which using tagged image
|
- name: mount the container which using tagged image
|
||||||
command: buildah mount busybox1-working-container
|
command: buildah mount busybox1-working-container
|
||||||
@ -34,7 +31,7 @@
|
|||||||
command: buildah rm busybox1-working-container
|
command: buildah rm busybox1-working-container
|
||||||
|
|
||||||
- name: buildah rmi tagged image
|
- name: buildah rmi tagged image
|
||||||
command: buildah rmi busybox{1..2}
|
shell: buildah rmi busybox{1..2}
|
||||||
|
|
||||||
- name: check image busybox is not deleted
|
- name: check image busybox is not deleted
|
||||||
shell: buildah images | grep busybox
|
shell: buildah images | grep busybox
|
||||||
|
14
tests/roles/cli/tasks/version.yaml
Normal file
14
tests/roles/cli/tasks/version.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
- name: check version of buildah rpm package
|
||||||
|
command: rpm -q buildah
|
||||||
|
register: rpmver
|
||||||
|
args:
|
||||||
|
warn: no
|
||||||
|
|
||||||
|
- debug: msg={{ rpmver.stdout }}
|
||||||
|
|
||||||
|
- name: check version of command buildah version
|
||||||
|
command: buildah version
|
||||||
|
register: ver
|
||||||
|
|
||||||
|
- debug: msg={{ ver.stdout }}
|
21
tests/roles/github-buildah/tasks/main.yml
Normal file
21
tests/roles/github-buildah/tasks/main.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: pull latest buildah source from github
|
||||||
|
git:
|
||||||
|
repo: https://github.com/projectatomic/buildah
|
||||||
|
dest: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah"
|
||||||
|
|
||||||
|
- name: make binary for buildah
|
||||||
|
command: make
|
||||||
|
args:
|
||||||
|
chdir: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah"
|
||||||
|
|
||||||
|
- name: install buildah to /usr/local/bin
|
||||||
|
command: make install
|
||||||
|
args:
|
||||||
|
chdir: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah"
|
||||||
|
|
||||||
|
- name: copy buildah to /usr/bin
|
||||||
|
copy:
|
||||||
|
remote_src: True
|
||||||
|
src: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah/buildah"
|
||||||
|
dest: /usr/bin/buildah
|
16
tests/roles/github-runc/tasks/main.yml
Normal file
16
tests/roles/github-runc/tasks/main.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
- name: pull latest runc source from github
|
||||||
|
git:
|
||||||
|
repo: https://github.com/opencontainers/runc
|
||||||
|
dest: "{{ ansible_env.HOME }}/go/src/github.com/opencontainers/runc"
|
||||||
|
|
||||||
|
- name: building runc for buildah runtime
|
||||||
|
command: make
|
||||||
|
args:
|
||||||
|
chdir: "{{ ansible_env.HOME }}/go/src/github.com/opencontainers/runc"
|
||||||
|
|
||||||
|
- name: copy runc to /usr/bin
|
||||||
|
copy:
|
||||||
|
remote_src: True
|
||||||
|
src: "{{ ansible_env.HOME }}/go/src/github.com/opencontainers/runc/runc"
|
||||||
|
dest: /usr/bin/runc
|
21
tests/roles/github/tasks/buildah.yml
Normal file
21
tests/roles/github/tasks/buildah.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: pull latest buildah source from github
|
||||||
|
git:
|
||||||
|
repo: https://github.com/projectatomic/buildah
|
||||||
|
dest: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah"
|
||||||
|
|
||||||
|
- name: make binary for buildah
|
||||||
|
command: make
|
||||||
|
args:
|
||||||
|
chdir: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah"
|
||||||
|
|
||||||
|
- name: install buildah to /usr/local/bin
|
||||||
|
command: make install
|
||||||
|
args:
|
||||||
|
chdir: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah"
|
||||||
|
|
||||||
|
- name: copy buildah to /usr/bin
|
||||||
|
copy:
|
||||||
|
remote_src: True
|
||||||
|
src: "{{ ansible_env.HOME }}/go/src/github.com/projectatomic/buildah/buildah"
|
||||||
|
dest: /usr/bin/buildah
|
8
tests/roles/github/tasks/main.yml
Normal file
8
tests/roles/github/tasks/main.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: runc.yml
|
||||||
|
tags:
|
||||||
|
- runc
|
||||||
|
|
||||||
|
- import_tasks: buildah.yml
|
||||||
|
tags:
|
||||||
|
- buildah
|
16
tests/roles/github/tasks/runc.yml
Normal file
16
tests/roles/github/tasks/runc.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
- name: pull latest runc source from github
|
||||||
|
git:
|
||||||
|
repo: https://github.com/opencontainers/runc
|
||||||
|
dest: "{{ ansible_env.HOME }}/go/src/github.com/opencontainers/runc"
|
||||||
|
|
||||||
|
- name: building runc for buildah runtime
|
||||||
|
command: make
|
||||||
|
args:
|
||||||
|
chdir: "{{ ansible_env.HOME }}/go/src/github.com/opencontainers/runc"
|
||||||
|
|
||||||
|
- name: copy runc to /usr/bin
|
||||||
|
copy:
|
||||||
|
remote_src: True
|
||||||
|
src: "{{ ansible_env.HOME }}/go/src/github.com/opencontainers/runc/runc"
|
||||||
|
dest: /usr/bin/runc
|
@ -11,6 +11,9 @@
|
|||||||
- ostree
|
- ostree
|
||||||
- httpd
|
- httpd
|
||||||
- libselinux-python
|
- libselinux-python
|
||||||
|
- golang
|
||||||
|
- make
|
||||||
|
- libseccomp-devel
|
||||||
|
|
||||||
- name: start docker daemon
|
- name: start docker daemon
|
||||||
systemd: state=started name=docker
|
systemd: state=started name=docker
|
||||||
@ -21,21 +24,32 @@
|
|||||||
- name: ensure docker-distribution service is running
|
- name: ensure docker-distribution service is running
|
||||||
systemd: state=started name=docker-distribution
|
systemd: state=started name=docker-distribution
|
||||||
|
|
||||||
- name: creates directory buildah testing
|
- name: create tmp directory for buildah testing
|
||||||
file: path=/tmp/buildah/bud state=directory
|
file: path=/tmp/buildah/bud state=directory
|
||||||
|
|
||||||
- name: download Dockerfile
|
- name: download Dockerfile for hello-world from github
|
||||||
get_url:
|
get_url:
|
||||||
url: https://github.com/fedora-cloud/Fedora-Dockerfiles/raw/master/nginx/Dockerfile
|
url: https://raw.githubusercontent.com/docker-library/hello-world/master/amd64/hello-world/Dockerfile
|
||||||
dest: /tmp/buildah/bud/Dockerfile
|
dest: /tmp/buildah/bud/Dockerfile
|
||||||
|
force: yes
|
||||||
|
|
||||||
- name: creates a bud directory in /var/www/html
|
- name: download hello for the Dockerfile
|
||||||
|
get_url:
|
||||||
|
url: https://github.com/docker-library/hello-world/raw/master/amd64/hello-world/hello
|
||||||
|
dest: /tmp/buildah/bud/hello
|
||||||
|
force: yes
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: create a bud directory in /var/www/html
|
||||||
file: path=/var/www/html/bud state=directory
|
file: path=/var/www/html/bud state=directory
|
||||||
|
|
||||||
- name: archive dockerfile into httpd directory
|
- name: archive dockerfile into httpd directory
|
||||||
command: tar zcvf /var/www/html/bud/Dockerfile.tar.gz Dockerfile
|
command: tar zcvf /var/www/html/bud/Dockerfile.tar.gz Dockerfile hello
|
||||||
args:
|
args:
|
||||||
chdir: /tmp/buildah/bud
|
chdir: /tmp/buildah/bud
|
||||||
|
# Disables the following warning:
|
||||||
|
# Consider using unarchive module rather than running tar
|
||||||
|
warn: no
|
||||||
|
|
||||||
- name: start httpd service
|
- name: start httpd service
|
||||||
systemd: state=started name=httpd
|
systemd: state=started name=httpd
|
||||||
|
@ -4,3 +4,6 @@
|
|||||||
|
|
||||||
- name: stop httpd service
|
- name: stop httpd service
|
||||||
systemd: state=stopped name=httpd
|
systemd: state=stopped name=httpd
|
||||||
|
|
||||||
|
- name: remove /tmp/buildah
|
||||||
|
file: path=/tmp/buildah state=absent
|
||||||
|
1
tests/test.sh
Executable file
1
tests/test.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
ansible-playbook -i inventory tests.yml "$@"
|
@ -5,8 +5,12 @@
|
|||||||
tags:
|
tags:
|
||||||
- classic
|
- classic
|
||||||
roles:
|
roles:
|
||||||
- prepare-env
|
- role: prepare-env
|
||||||
|
tags:
|
||||||
|
- env
|
||||||
|
- role: github-runc
|
||||||
|
tags:
|
||||||
|
- github-runc
|
||||||
- role: cli
|
- role: cli
|
||||||
tags:
|
tags:
|
||||||
- cli
|
- cli
|
||||||
- tear-down
|
|
||||||
|
Loading…
Reference in New Issue
Block a user