Skip to content

Commit

Permalink
Validate k8s to docker migration file
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Aug 2, 2024
1 parent 2cba1d8 commit e635fae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps_validation/validate_app_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .app_version import validate_app_version_file
from .ix_values import validate_ix_values_schema
from .json_schema_utils import VERSION_VALIDATION_SCHEMA
from .validate_k8s_to_docker_migration import validate_k8s_to_docker_migrations
from .validate_questions import validate_questions_yaml
from .validate_templates import validate_templates

Expand Down Expand Up @@ -89,6 +90,9 @@ def validate_catalog_item_version(
except ValidationErrors as v:
verrors.extend(v)

validate_k8s_to_docker_migrations(
verrors, os.path.join(version_path, 'migrations'), f'{schema}.migrations.migrate_from_kubernetes'
)
# validate_app_migrations(verrors, version_path, f'{schema}.app_migrations')
# FIXME: Add validation for app migrations

Expand Down
15 changes: 15 additions & 0 deletions apps_validation/validate_k8s_to_docker_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import contextlib
import os.path

from apps_exceptions import ValidationErrors


def validate_k8s_to_docker_migrations(verrors: ValidationErrors, app_migration_path: str, schema: str):
file_to_check_path = os.path.join(app_migration_path, 'migrate_from_kubernetes')
with contextlib.suppress(FileNotFoundError):
if not os.access(file_to_check_path, os.X_OK):
verrors.add(schema, 'Migration file is not executable')

with open(file_to_check_path, 'r') as r:
if not r.readline().startswith('#!'):
verrors.add(schema, 'Migration file should start with shebang line')

0 comments on commit e635fae

Please sign in to comment.