cloud-build/cloud_build/image_tests/docker.py

31 lines
701 B
Python
Raw Normal View History

2019-07-08 02:14:01 +03:00
from typing import List
def test_docker(image: str) -> List[str]:
dockerfile = rf"""FROM scratch
ADD {image} /
RUN true > /etc/security/limits.d/50-defaults.conf
CMD ["/bin/bash"]"""
with open('Dockerfile', 'w') as f:
f.write(dockerfile)
2019-07-08 17:57:36 +03:00
name = f'cloud_build_test_{abs(hash(image))}'
2022-11-10 19:31:07 +03:00
test_commads = [
'apt-get update',
'apt-get install -y vim-console',
'[ -L /var/run ]',
'[ -L /var/lock ]'
]
test_commad = " && ".join(test_commads)
2019-07-08 02:14:01 +03:00
commands = [
f'docker build --rm --tag={name} .',
2021-03-17 17:49:39 +03:00
f"docker run --rm {name} /bin/sh -c "
2022-11-10 19:31:07 +03:00
f"'{test_commad}'",
2019-07-08 02:14:01 +03:00
f'docker image rm {name}',
]
return commands