Skip to content

Docker implementation#1219

Open
Jrice1317 wants to merge 34 commits into
conda:mainfrom
Jrice1317:docker-implementation
Open

Docker implementation#1219
Jrice1317 wants to merge 34 commits into
conda:mainfrom
Jrice1317:docker-implementation

Conversation

@Jrice1317
Copy link
Copy Markdown
Contributor

@Jrice1317 Jrice1317 commented Apr 22, 2026

Description

This PR adds Docker output support to constructor, generating a ready-to-use Dockerfile and optionally building the resulting image via installer_type: docker and docker_build: true in the construct.yaml.

Changes

New:

  • constructor/docker_build.py: Handles Docker output by rendering template and optionally building portable image
  • constructor/dockerfile_template.tmpl: Template used to generate Dockerfile
  • examples/docker_build/construct.yaml: Example construct.yaml used for testing

Updated:

  • constructor/_schema.py: Adds docker to installer_type and adds docker_base_image, docker_tag, docker_labels
  • constructor/main.py: Adds docker to installer types
  • tests/test_examples.py: Adds test_docker_build to cover Dockerfile generation, image build and smoke test

Notes:

  • When docker_build is True, the user can start using the resulting portable image by running the command docker load -i <image_name>
  • Verified RuntimeError is raised when base_image is not provided
RuntimeError: Base image for Dockerfile not specified. Please set 'docker_base_image' in construct.yaml, e.g.:
 docker_base_image: debian:13.4-slim@sha256:4ffb3a1511099754cddc70eb1b12e50ffdb67619aa0ab6c13fcd800a78ef7c7a

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@Jrice1317 Jrice1317 requested a review from a team as a code owner April 22, 2026 19:32
@github-project-automation github-project-automation Bot moved this to 🆕 New in 🔎 Review Apr 22, 2026
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Apr 22, 2026
@Jrice1317 Jrice1317 marked this pull request as draft April 22, 2026 19:45
@Jrice1317 Jrice1317 changed the title Docker implementation Docker implementation [skip windows] May 6, 2026
@Jrice1317 Jrice1317 force-pushed the docker-implementation branch from 9fa7db8 to 9f20cbe Compare May 6, 2026 16:10
@Jrice1317 Jrice1317 changed the title Docker implementation [skip windows] Docker implementation May 8, 2026
@Jrice1317 Jrice1317 marked this pull request as ready for review May 8, 2026 23:01
Comment thread constructor/_schema.py
"""
Base image to use for docker builds when `installer_type` includes `docker` or `docker_build` is True.
Should be a specific image reference. For reproducibility, please specify a SHA256 digest.
For example: `debian:13.4-slim@sha256:abc123...`. If the digest is not provided, a warning will be shown.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is great, but reproducibility is not the primary concern here either, it's supply chain security. I would overall do don't think it's constructor's responsibility to decide or advise on the user's security model though, even if it's just a warning. Warnings show up in GitHub Action summaries and can introduce unwanted noise.

Comment thread constructor/_schema.py
"""
If `True`, builds a docker image using the Dockerfile generated by constructor and saves it as a portable tarball.
``<name>-<version>-<platform>.tar`` will be created in the output docker directory.
Requires `docker_base_image` to be specified.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base image should be a mandatory parameter in any case.

Comment thread constructor/_schema.py
The labels `org.opencontainers.image.title` and `org.opencontainers.image.version` are
set automatically from `name` and `version`.
"""
docker_build: bool = False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that Docker provides several output formats, I would rather choose something that is extendable. It's okay if we don't support all formats right now, we can disclose that.

Comment thread constructor/_schema.py
message: "This base environment is frozen and cannot be modified."
```
"""
docker_base_image: Annotated[str, Field(min_length=1)] | None = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of prefixing all fields with docker_*, would it make more sense to make docker its own key with all other properties being a subkey? I know that's not our current convention, so I'm not 100% sure about that.

Comment thread constructor/_schema.py
docker_tag: NonEmptyStr | None = None
"""
Tag to use for the docker image.
If not provided, it will default to `<name>:<version>`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to provide a default here? docker build runs with a tag, too.

Will this require docker_build (or whatever successor you choose) to be set?


LABEL org.opencontainers.image.title="{{ name }}"
LABEL org.opencontainers.image.version="{{ version }}"
{%- if labels %}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the if is needed. If labels is empty, the loop just won't run.

Comment thread constructor/main.py
Comment on lines +56 to +65
if docker_build and osname == "win":
sys.exit(
"Error: 'docker_build' is not supported on Windows. "
"Run the build on Linux or macOS instead."
)
if docker_build and itype in ("pkg", "exe"):
sys.exit(
"Error: 'docker_build' is not compatible with installer_type 'pkg' or 'exe'. "
"Use installer_type: 'sh', 'docker', or omit installer_type."
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of erroring out, we should just ignore those.

Comment thread constructor/main.py
Comment on lines +438 to +440
info["_outpath"] = abspath(join(output_dir, get_output_filename(info))).replace(
".docker", ".sh"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't you already doing this in the build function?

Comment thread tests/test_examples.py

@pytest.mark.skipif(sys.platform.startswith("win"), reason="Unix only")
@pytest.mark.skipif(not shutil.which("docker"), reason="Docker not available")
def test_docker_build(tmp_path):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't test the labels.

Comment thread constructor/main.py
),
"win": ("exe",),
}
all_allowed = set(sum(os_allowed.values(), ("all", "docker")))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only allow Docker for Linux platforms and can only build them on Linux and macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed [bot] added once the contributor has signed the CLA

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

3 participants