https://pulumi.com logo
Title
p

powerful-pharmacist-31524

06/18/2020, 1:02 PM
Having an issue with pulumi_docker and environment variables. This works fine:
mock_image = docker.Image('mock-server-image',
                          build=docker.DockerBuild(context='../',
                                                   dockerfile=f'../Dockerfile'),
                          image_name=f'{repo.repository_url}',
                          registry=registry)
But as soon as I add an environment variable …
mock_image = docker.Image('mock-server-image',
                          build=docker.DockerBuild(context='../',
                                                   dockerfile=f'../Dockerfile',
                                                   env={'MOCK_PORT': '80'}),
                          image_name=f'{repo.repository_url}',
                          registry=registry)
I get an error:
FileNotFoundError: [Errno 2] No such file or directory: 'docker': 'docker'
l

lemon-agent-27707

06/18/2020, 3:01 PM
Can you share the full output?
p

powerful-pharmacist-31524

06/18/2020, 4:42 PM
Diagnostics:
  pulumi:pulumi:Stack (pdc_number_management_mock_server-mock):
    error: Program failed with an unhandled exception:
    error: Traceback (most recent call last):
      File "/usr/local/bin/pulumi-language-python-exec", line 85, in <module>
        loop.run_until_complete(coro)
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
        return future.result()
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/stack.py", line 81, in run_in_stack
        await run_pulumi_func(lambda: Stack(func))
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/stack.py", line 50, in run_pulumi_func
        await RPC_MANAGER.rpcs.pop()
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc_manager.py", line 67, in rpc_wrapper
        result = await rpc
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 89, in is_value_known
        return await is_known and not contains_unknowns(await future)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 89, in is_value_known
        return await is_known and not contains_unknowns(await future)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 89, in is_value_known
        return await is_known and not contains_unknowns(await future)
      [Previous line repeated 22 more times]
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/resource.py", line 325, in do_register
        resolver = await prepare_resource(res, ty, custom, props, opts)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/resource.py", line 88, in prepare_resource
        serialized_props = await rpc.serialize_properties(props, property_dependencies_resources, res.translate_input_property)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 68, in serialize_properties
        result = await serialize_property(v, deps, input_transformer)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 171, in serialize_property
        is_known = await output._is_known
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc_manager.py", line 67, in rpc_wrapper
        result = await rpc
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 89, in is_value_known
        return await is_known and not contains_unknowns(await future)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 89, in is_value_known
        return await is_known and not contains_unknowns(await future)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 89, in is_value_known
        return await is_known and not contains_unknowns(await future)
      [Previous line repeated 16 more times]
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/resource.py", line 325, in do_register
        resolver = await prepare_resource(res, ty, custom, props, opts)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/resource.py", line 88, in prepare_resource
        serialized_props = await rpc.serialize_properties(props, property_dependencies_resources, res.translate_input_property)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 68, in serialize_properties
        result = await serialize_property(v, deps, input_transformer)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 173, in serialize_property
        value = await serialize_property(output.future(), deps, input_transformer)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 159, in serialize_property
        future_return = await asyncio.ensure_future(awaitable)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 114, in get_value
        val = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 155, in run
        value = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 340, in gather_futures
        return await asyncio.gather(*value_futures)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 114, in get_value
        val = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 155, in run
        value = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 340, in gather_futures
        return await asyncio.gather(*value_futures)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 114, in get_value
        val = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 340, in gather_futures
        return await asyncio.gather(*value_futures)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 114, in get_value
        val = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 155, in run
        value = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 155, in run
        value = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 155, in run
        value = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc_manager.py", line 67, in rpc_wrapper
        result = await rpc
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/resource.py", line 440, in do_register_resource_outputs
        serialized_props = await rpc.serialize_properties(outputs, {})
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 68, in serialize_properties
        result = await serialize_property(v, deps, input_transformer)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 173, in serialize_property
        value = await serialize_property(output.future(), deps, input_transformer)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/runtime/rpc.py", line 159, in serialize_property
        future_return = await asyncio.ensure_future(awaitable)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 114, in get_value
        val = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 155, in run
        value = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 155, in run
        value = await self._future
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi/output.py", line 176, in run
        transformed: Input[U] = func(value)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi_docker/image.py", line 234, in <lambda>
        lambda args: get_image_data(_ImageArgs(*args))
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi_docker/image.py", line 225, in get_image_data
        image_args.skip_push,
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi_docker/docker.py", line 238, in build_and_push_image
        build_result = build_image(base_image_name, path_or_build, log_resource, cache_from)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi_docker/docker.py", line 422, in build_image
        docker_build(image_name, build, log_resource, cache_from)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi_docker/docker.py", line 477, in docker_build
        return run_command_that_must_succeed("docker", build_args, log_resource, env=build.env)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi_docker/docker.py", line 585, in run_command_that_must_succeed
        cmd, args, log_resource, report_full_command_line, False, stdin, env)
      File "/Users/mhill/projects/phonecom/pdc_number_management/services/users/deployment/venv/lib/python3.7/site-packages/pulumi_docker/docker.py", line 643, in run_command_that_can_fail
        stderr=subprocess.PIPE, stdin=subprocess.PIPE, encoding="utf-8")
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 800, in __init__
        restore_signals, start_new_session)
      File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1551, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: 'docker': 'docker'
    error: an unhandled error occurred: Program exited with non-zero exit code: 1
Thanks for responding @lemon-agent-27707
l

lemon-agent-27707

06/18/2020, 5:08 PM
Did you see the other reply here? https://pulumi-community.slack.com/archives/CRH5ENVDX/p1592489858347900 You might need to make a copy of os.environ, set your variable, and then pass that in to the build command.
s

strong-plastic-28250

06/18/2020, 6:06 PM
I can confirm setting env in the
Image()
class does cause this error. I had this happen to myself I removed the
env
and everything worked
p

powerful-pharmacist-31524

06/18/2020, 6:16 PM
ahh, this makes sense will retry with full env, thank you!
Might be helpful to add a note about this to docs.
And finally, I can confirm that
os.environ['MOCK_PORT'] = '80' 
docker.DockerBuild(env=os.environ, ...)
works. Thanks again!
l

lemon-agent-27707

06/18/2020, 6:42 PM
Glad to help. Reading through the SDKs, the behavior is inconsistent across languages. So I filed a bug to track: https://github.com/pulumi/pulumi-docker/issues/196
👍🏾 1