-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] #3889: add Compose validation scripts
Signed-off-by: 6r1d <[email protected]>
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PyYAML==6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |