Skip to content

Commit

Permalink
[ci] #3889: add Compose validation scripts
Browse files Browse the repository at this point in the history
Signed-off-by: 6r1d <[email protected]>
  • Loading branch information
6r1d committed Nov 13, 2023
1 parent e9c6fe4 commit a300620
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/scripts/ci_test/ci_image_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

"""
CI script for locating the improperly configured images.
Images that should trigger an error should be listed in
LIST_IMAGES variable.
"""

import sys
from logging import warning, error
from yaml import safe_load
from yaml.error import YAMLError
from git_root import git_root

FAIL_IMAGES = ['iroha2:dev']

def check_docker_config(config_file):
status = 0
services = {}
try:
with open(config_file, 'r', encoding='utf8') as config_contents:
config_inst = safe_load(config_contents.read())
if isinstance(config_inst, dict):
services = config_inst.get('services', {})
else:
error(f'improper configuration at "{config_file}"')
status = 1
except YAMLError:
error(f'improper formatting at "{config_file}"')
status = 1
for _, service in services.items():
if service.get('image', '') in FAIL_IMAGES:
status = 1
break
return status

def main():
for yml_file in git_root().glob('*.yml'):
if check_docker_config(yml_file):
warning(f'wrong image in "{yml_file}"')
sys.exit(1)
print('Scan completed successfully')

if __name__ == '__main__':
main()
19 changes: 19 additions & 0 deletions .github/scripts/ci_test/git_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
This module contains a modified copy of git_root by Jan Tilly.
It allows to find a repo root on GitHub for the CI purposes.
https://github.com/jtilly/git_root/blob/master/git_root/git_root.py
"""

from subprocess import Popen, PIPE, DEVNULL
from os.path import abspath
from pathlib import Path

def git_root():
root = '.'
with Popen(
['git', 'rev-parse', '--show-toplevel'],
stdout=PIPE, stderr=DEVNULL
) as git_proc:
root = git_proc.communicate()[0].rstrip().decode('utf-8')
return Path(abspath(root))
1 change: 1 addition & 0 deletions .github/scripts/ci_test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyYAML==6.0.1
17 changes: 17 additions & 0 deletions .github/workflows/no-incorrect-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: I2::CI::check_for_incorrect_images

on: workflow_dispatch

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: "3.11"
- uses: actions/checkout@v3
- name: Install depenencies
run: pip install -r .github/scripts/ci_test/requirements.txt --no-input
- name: Check containers
run: python .github/scripts/ci_test/ci_image_scan.py

0 comments on commit a300620

Please sign in to comment.