Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ansible-builder v3 schema #3480

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
pytest.param(
"examples/ee_broken/execution-environment.yml",
"execution-environment",
["Additional properties are not allowed ('foo' was unexpected)"],
["{'foo': 'bar'} is not valid under any of the given schemas"],
id="execution-environment-broken",
),
("examples/meta/runtime.yml", "meta-runtime", []),
Expand Down
341 changes: 290 additions & 51 deletions src/ansiblelint/schemas/execution-environment.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,309 @@
{
"$id": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/execution-environment.json",
"$schema": "http://json-schema.org/draft-07/schema",
"additionalProperties": false,
"description": "See https://docs.ansible.com/automation-controller/latest/html/userguide/ee_reference.html",
"examples": ["execution-environment.yml"],
"properties": {
"additional_build_steps": {
"properties": {
"append": {
"examples": ["RUN cat /etc/os-release"],
"type": ["string", "array"]
},
"prepend": {
"examples": ["RUN cat /etc/os-release"],
"type": ["string", "array"]
"$defs": {
"TYPE_DictOrStringOrListOfStrings": {
"anyOf": [
{ "type": "object" },
{ "type": "string" },
{
"items": {
"type": "string"
},
"type": "array"
}
},
"title": "Commands to append or prepend to container build process.",
"type": "object"
]
},
"ansible_config": {
"examples": ["ansible.cfg"],
"title": "Ansible configuration file",
"type": "string"
"TYPE_StringOrListOfStrings": {
"anyOf": [
{ "type": "string" },
{
"items": {
"type": "string"
},
"type": "array"
}
]
},
"build_arg_defaults": {
"additionalProperties": true,
"v1": {
"additionalProperties": false,
"properties": {
"EE_BASE_IMAGE": {
"additional_build_steps": {
"properties": {
"append": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"prepend": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
}
},
"title": "Commands to append or prepend to container build process.",
"type": "object"
},
"ansible_config": {
"examples": ["ansible.cfg"],
"title": "Ansible configuration file",
"type": "string"
},
"build_arg_defaults": {
"additionalProperties": true,
"properties": {
"EE_BASE_IMAGE": {
"type": "string"
}
},
"type": "object"
},
"dependencies": {
"description": "Allows adding system, python or galaxy dependencies.",
"properties": {
"galaxy": {
"examples": ["requirements.yml"],
"markdownDescription": "Example `requirements.yml`",
"title": "Optional galaxy file",
"type": "string"
},
"python": {
"examples": ["requirements.txt"],
"markdownDescription": "Example `requirements.txt`",
"title": "Optional python package dependencies",
"type": "string"
},
"system": {
"examples": ["bindep.txt"],
"markdownDescription": "Example `bindep.txt`",
"title": "Optional system dependencies using bindep format",
"type": "string"
}
},
"title": "Dependencies",
"type": "object"
},
"version": {
"enum": [1],
"title": "Version",
"type": "integer"
}
},
"required": ["version", "dependencies"],
"title": "Ansible Execution Environment Schema v1",
"type": "object"
},
"dependencies": {
"description": "Allows adding system, python or galaxy dependencies.",
"v3": {
"additionalProperties": false,
"properties": {
"galaxy": {
"examples": ["requirements.yml"],
"markdownDescription": "Example `requirements.yml`",
"title": "Optional galaxy file",
"type": "string"
"additional_build_files": {
"description": "Describes files to add to the build context",
"items": {
"additionalProperties": false,
"properties": {
"dest": {
"description": "Relative subdirectory under build context to place file",
"type": "string"
},
"src": {
"description": "File to add to build context",
"type": "string"
}
},
"required": ["src", "dest"],
"type": "object"
},
"type": "array"
},
"python": {
"examples": ["requirements.txt"],
"markdownDescription": "Example `requirements.txt`",
"title": "Optional python package dependencies",
"type": "string"
"additional_build_steps": {
"properties": {
"append_base": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"append_builder": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"append_final": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"append_galaxy": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"prepend_base": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"prepend_builder": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"prepend_final": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
},
"prepend_galaxy": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["RUN cat /etc/os-release"]
}
},
"title": "Commands to append or prepend to container build process.",
"type": "object"
},
"system": {
"examples": ["bindep.txt"],
"markdownDescription": "Example `bindep.txt`",
"title": "Optional system dependencies using bindep format",
"type": "string"
"build_arg_defaults": {
"additionalProperties": false,
"properties": {
"ANSIBLE_GALAXY_CLI_COLLECTION_OPTS": {
"type": "string"
},
"ANSIBLE_GALAXY_CLI_ROLE_OPTS": {
"type": "string"
},
"PKGMGR_PRESERVE_CACHE": {
"type": "string"
}
},
"type": "object"
},
"dependencies": {
"description": "Allows adding system, python or galaxy dependencies.",
"properties": {
"ansible_core": {
"additionalProperties": false,
"description": "Ansible package installation",
"oneOf": [{ "required": ["package_pip"] }],
"properties": {
"package_pip": {
"description": "Ansible package to install via pip",
"type": "string"
}
},
"type": "object"
},
"ansible_runner": {
"additionalProperties": false,
"description": "Ansible Runner package installation",
"oneOf": [{ "required": ["package_pip"] }],
"properties": {
"package_pip": {
"description": "Ansible Runner package to install via pip",
"type": "string"
}
},
"type": "object"
},
"galaxy": {
"$ref": "#/$defs/TYPE_DictOrStringOrListOfStrings",
"examples": ["requirements.yml"],
"markdownDescription": "Example `requirements.yml`",
"title": "Optional galaxy file"
},
"python": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["requirements.txt"],
"markdownDescription": "Example `requirements.txt`",
"title": "Optional python package dependencies"
},
"python_interpreter": {
"additionalProperties": false,
"description": "Python package name and path",
"properties": {
"package_system": {
"description": "The python package to install via system package manager",
"type": "string"
},
"python_path": {
"description": "Path to the python interpreter",
"type": "string"
}
},
"type": "object"
},
"system": {
"$ref": "#/$defs/TYPE_StringOrListOfStrings",
"examples": ["bindep.txt"],
"markdownDescription": "Example `bindep.txt`",
"title": "Optional system dependencies using bindep format"
}
},
"title": "Dependencies",
"type": "object"
},
"images": {
"additionalProperties": false,
"properties": {
"base_image": {
"name": {
"examples": [
"registry.redhat.io/ansible-automation-platform-21/ee-minimal-rhel8:latest"
],
"type": "string"
},
"type": "object"
}
},
"type": "object"
},
"options": {
"additionalProperties": false,
"description": "Options that effect runtime behavior",
"properties": {
"container_init": {
"additionalProperties": false,
"description": "Customize container startup behavior",
"properties": {
"cmd": {
"description": "literal value for CMD Containerfile directive",
"type": "string"
},
"entrypoint": {
"description": "literal value for ENTRYPOINT Containerfile directive",
"type": "string"
},
"package_pip": {
"description": "package to install via pip for entrypoint support",
"type": "string"
}
},
"type": "object"
},
"package_manager_path": {
"description": "Path to the system package manager to use",
"type": "string"
},
"relax_passwd_permissions": {
"description": "allows GID0 write access to /etc/passwd; currently necessary for many uses",
"type": "boolean"
},
"skip_ansible_check": {
"description": "Disables the check for Ansible/Runner in final image",
"type": "boolean"
},
"user": {
"description": "Sets the username or UID",
"type": "string"
},
"workdir": {
"description": "Default working directory, also often the homedir for ephemeral UIDs",
"type": ["string", "null"]
}
},
"type": "object"
},
"version": {
"enum": [3],
"title": "Version",
"type": "integer"
}
},
"title": "Dependencies",
"required": ["version", "dependencies"],
"title": "Ansible Execution Environment Schema v3",
"type": "object"
},
"version": {
"enum": [1],
"title": "Version",
"type": "integer"
}
},
"required": ["version", "dependencies"],
"title": "Ansible Execution Environment Schema",
"type": "object"
"$id": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/execution-environment.json",
"$schema": "http://json-schema.org/draft-07/schema",
"description": "See \nV1: https://docs.ansible.com/automation-controller/latest/html/userguide/ee_reference.html\nV3: https://ansible-builder.readthedocs.io/en/latest/definition/",
"examples": ["execution-environment.yml"],
"oneOf": [{ "$ref": "#/$defs/v3" }, { "$ref": "#/$defs/v1" }],
"title": "Ansible Execution Environment Schema v1/v3"
}
19 changes: 19 additions & 0 deletions test/schemas/test/execution-environment-v3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: 3

images:
base_image:
name: "quay.io/ansible/ansible-runner:stable-2.10-devel"

dependencies:
galaxy: requirements.yml
python: requirements.txt
system: bindep.txt

additional_build_steps:
prepend_base: |
RUN whoami
RUN cat /etc/os-release
append_base:
- RUN echo This is a post-install command!
- RUN ls -la /etc