incalculable-grass-76623
09/20/2022, 7:00 AMdocker_image(
name="docker_image",
repository="my-image-name",
image_tags=[the_version()],
dependencies=[":the_python_pkg", ":docker_resources"],
)
where the_version()
is coming from a rule generated in a plugin
This is the "test plugin" i have written:
# pants-plugin/versioning/register.py
import os
from pants.engine.rules import collect_rules, rule
@rule
async def the_version() -> str:
return os.popen('git --no-pager describe --always --dirty --broken').read()
def rules():
return collect_rules()
However when ./pants package path/to:docker
is run I am expecting the docker_image tag to pickup the "string" from the the_version()
however pant` does not register the rule as a symbol ? (maybe it's not a rule I need)
MappingError: Failed to parse ./services/my-image/BUILD:
Name 'the_version' is not defined.
If you expect to see more symbols activated in the below list, refer to <https://www.pantsbuild.org/v2.13/docs/enabling-backends> for all available backends to activate.
All registered symbols: ['_generator_sources_helper', 'archive', 'build_file_dir', 'docker_image', 'experimental_run_shell_command', 'experimental_shell_command', 'file', 'files', 'helm_artifact', 'helm_chart', 'helm_unittest_test', 'helm_unittest_tests', 'http_source', 'parametrize', 'pex_binaries', 'pex_binary', 'pipenv_requirements', 'poetry_requirements', 'python_artifact', 'python_distribution', 'python_requirement', 'python_requirements', 'python_source', 'python_sources', 'python_test', 'python_test_utils', 'python_tests', 'relocated_files', 'resource', 'resources', 'setup_py', 'shell_source', 'shell_sources', 'shunit2_test', 'shunit2_tests', 'target']
My goal for this first step is to get pants
to "auto collect" the "GIT_COMMIT" version
ref: https://www.pantsbuild.org/v2.11/docs/tagging-docker-images#using-env-vars-to-include-dynamic-data-in-tags
and provide it as a variable or via a function (like I tried above).
Such that
./pants package src/example:demo
Builds a docker image with demo:$(git rev-parse HEAD)
enough-analyst-54434
09/20/2022, 2:59 PMbitter-ability-32190
09/20/2022, 3:09 PMgit
state changes, so the result might be cached when you change commits.
You might try using the type defined here as an input to your rule.bitter-ability-32190
09/20/2022, 3:10 PMincalculable-grass-76623
09/20/2022, 8:50 PMbitter-ability-32190
09/20/2022, 8:56 PM