I’ve run into a minor hickup, however.. as I’m gen...
# development
c
I’ve run into a minor hickup, however.. as I’m generating the source file (a
Dockerfile
) for the
docker_image
target, the engine complains that I don’t have the required file present for the source field:
Copy code
E             File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executioneZewVW/src/python/pants/engine/internals/graph.py", line 792, in hydrate_sources
E               sources_field.validate_resolved_files(snapshot.files)
E             File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executioneZewVW/src/python/pants/engine/target.py", line 1570, in validate_resolved_files
E               f"The {repr(self.alias)} field in target {self.address} must have "
E           pants.engine.target.InvalidFieldException: The 'source' field in target src/docker:docker must have 1 file, but it had 0 files.
However, it will be in the Digest.. any way to work around this? This is what the test looks like:
Copy code
def test_synthetic_dockerfile(rule_runner: RuleRunner) -> None:
    rule_runner.write_files(
        {
            "src/docker/BUILD": dedent(
                """\
                docker_image(dependencies=[":dockerfile"])
                dockerfile(
                  name="dockerfile",
                  instructions=[
                    "FROM python:3.8",
                    "FROM alpine as interim",
                    "FROM interim",
                    "FROM scratch:1-1 as output",
                  ]
                )
                """
            ),
        }
    )

    assert_build_context(
        rule_runner,
        Address("src/docker"),
        expected_files=["src/docker/Dockerfile"],
        expected_version_context={
            "baseimage": {"tag": "3.8"},
            "stage0": {"tag": "3.8"},
            "interim": {"tag": "latest"},
            "stage2": {"tag": "latest"},
            "output": {"tag": "1-1"},
        },
    )
So there’s a codegen for the
dockerfile
target, which produces the
Dockerfile
which I want the
docker_image
to pick up..