-
-
Notifications
You must be signed in to change notification settings - Fork 942
Support a new field to set image tag for docker and docker_image languages #2968
Description
search you tried in the issue tracker
rev docker
describe your actual problem
When creating / using hooks based on the docker_image language, it would be really useful to support passing a new tagfield to the function that runs the hook.
This would allow the hook owner to set a floating default (such as latest) in the git repo, but allow users to override this value in order to pin to a specific version of the hook's container image.
This would help to mitigate compatibility issues across major version changes and reduce the overhead of maintaining hooks based on container images in general.
To maintain backward compatibility, the entry string concatenation would only happen in the case that the tag field was not None
This seems relatively simple to implement in this function:
pre-commit/pre_commit/languages/docker_image.py
Lines 16 to 32 in a1f1d19
| def run_hook( | |
| prefix: Prefix, | |
| entry: str, | |
| args: Sequence[str], | |
| file_args: Sequence[str], | |
| *, | |
| is_local: bool, | |
| require_serial: bool, | |
| color: bool, | |
| ) -> tuple[int, bytes]: # pragma: win32 no cover | |
| cmd = docker_cmd() + lang_base.hook_cmd(entry, args) | |
| return lang_base.run_xargs( | |
| cmd, | |
| file_args, | |
| require_serial=require_serial, | |
| color=color, | |
| ) |
pseudo code:
def run_hook(
prefix: Prefix,
entry: str,
args: Sequence[str],
file_args: Sequence[str],
*,
is_local: bool,
require_serial: bool,
color: bool,
) -> tuple[int, bytes]: # pragma: win32 no cover
if tag:
# probably requires regex to match the container name if `entry` contains flags or other options: ie [myhost.foo/]myrepo/mycontainer --foo bar
container_name, remainder = <regex to get container_name>
entry = f"{container_name}:{tag}{remainder}"
cmd = docker_cmd() + lang_base.hook_cmd(entry, args)
return lang_base.run_xargs(
cmd,
file_args,
require_serial=require_serial,
color=color,
)Examples of proposed hook (source):
new field:
- id: helm-docs-container
args: []
description: Uses the container image of 'helm-docs' to create documentation from the Helm chart's 'values.yaml' file, and inserts the result into a corresponding 'README.md' file.
entry: jnorwood/helm-docs
tag: v1.11.0
files: (README\.md\.gotmpl|(Chart|requirements|values)\.yaml)$
language: docker_image
name: Helm Docs Container
require_serial: true- id: helm-docs-container
args: []
description: Uses the container image of 'helm-docs' to create documentation from the Helm chart's 'values.yaml' file, and inserts the result into a corresponding 'README.md' file.
entry: jnorwood/helm-docs
tag: latest
files: (README\.md\.gotmpl|(Chart|requirements|values)\.yaml)$
language: docker_image
name: Helm Docs Container
require_serial: truepre-commit --version
pre-commit 3.3.3