@@ -324,6 +324,7 @@ def _impl(
324324 executable = True,
325325 outputs = _container.image.outputs,
326326 implementation = _impl,
327+ cfg = _container.image.cfg,
327328 )
328329
329330 Args:
@@ -625,7 +626,7 @@ _attrs = dicts.add(_layer.attrs, {
625626 Acceptable formats: Integer or floating point seconds since Unix Epoch, RFC 3339 date/time.
626627
627628 This field supports stamp variables.
628-
629+
629630 If not set, defaults to {BUILD_TIMESTAMP} when stamp = True, otherwise 0""" ,
630631 ),
631632 "docker_run_flags" : attr .string (
@@ -637,14 +638,14 @@ _attrs = dicts.add(_layer.attrs, {
637638 doc = """List of entrypoints to add in the image.
638639
639640 See https://docs.docker.com/engine/reference/builder/#entrypoint
640-
641+
641642 Set `entrypoint` to `None`, `[]` or `""` will set the `Entrypoint` of the image
642643 to be `null`.
643644
644645 The behavior between using `""` and `[]` may differ.
645646 Please see [#1448](https://github.com/bazelbuild/rules_docker/issues/1448)
646647 for more details.
647-
648+
648649 This field supports stamp variables.""" ,
649650 ),
650651 "experimental_tarball_format" : attr .string (
@@ -667,12 +668,12 @@ _attrs = dicts.add(_layer.attrs, {
667668 ),
668669 "labels" : attr .string_dict (
669670 doc = """Dictionary from custom metadata names to their values.
670-
671+
671672 See https://docs.docker.com/engine/reference/builder/#label
672-
673+
673674 You can also put a file name prefixed by '@' as a value.
674675 Then the value is replaced with the contents of the file.
675-
676+
676677 Example:
677678
678679 labels = {
@@ -699,7 +700,7 @@ _attrs = dicts.add(_layer.attrs, {
699700 ),
700701 "layers" : attr .label_list (
701702 doc = """List of `container_layer` targets.
702-
703+
703704 The data from each `container_layer` will be part of container image,
704705 and the environment variable will be available in the image as well.""" ,
705706 providers = [LayerInfo ],
@@ -731,7 +732,7 @@ _attrs = dicts.add(_layer.attrs, {
731732 # Starlark doesn't support int_list...
732733 "ports" : attr .string_list (
733734 doc = """List of ports to expose.
734-
735+
735736 See https://docs.docker.com/engine/reference/builder/#expose""" ,
736737 ),
737738 "repository" : attr .string (
@@ -741,7 +742,7 @@ _attrs = dicts.add(_layer.attrs, {
741742 Images generated by `container_image` are tagged by default to
742743 `bazel/package_name:target` for a `container_image` target at
743744 `//package/name:target`.
744-
745+
745746 Setting this attribute to `gcr.io/dummy` would set the default tag to
746747 `gcr.io/dummy/package_name:target`.""" ,
747748 ),
@@ -767,19 +768,22 @@ _attrs = dicts.add(_layer.attrs, {
767768 ),
768769 "volumes" : attr .string_list (
769770 doc = """List of volumes to mount.
770-
771+
771772 See https://docs.docker.com/engine/reference/builder/#volumes""" ,
772773 ),
773774 "workdir" : attr .string (
774775 doc = """Initial working directory when running the Docker image.
775776
776777 See https://docs.docker.com/engine/reference/builder/#workdir
777-
778+
778779 Because building the image never happens inside a Docker container,
779780 this working directory does not affect the other actions (e.g., adding files).
780781
781782 This field supports stamp variables.""" ,
782783 ),
784+ "_allowlist_function_transition" : attr .label (
785+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
786+ ),
783787 "_digester" : attr .label (
784788 default = "//container/go/cmd/digester" ,
785789 cfg = "host" ,
@@ -799,19 +803,40 @@ _outputs["config_digest"] = "%{name}.json.sha256"
799803
800804_outputs ["build_script" ] = "%{name}.executable"
801805
806+ def _image_transition_impl (settings , attr ):
807+ # Architecture aliases.
808+ architecture = {
809+ "386" : "x86_32" ,
810+ "amd64" : "x86_64" ,
811+ "ppc64le" : "ppc" ,
812+ }.get (attr .architecture , attr .architecture )
813+ return dicts .add (settings , {
814+ "//command_line_option:platforms" : "//platforms:{}_{}" .format (attr .operating_system , architecture ),
815+ })
816+
817+ _image_transition = transition (
818+ implementation = _image_transition_impl ,
819+ inputs = [],
820+ outputs = [
821+ "//command_line_option:platforms" ,
822+ ],
823+ )
824+
802825image = struct (
803826 attrs = _attrs ,
804827 outputs = _outputs ,
805828 implementation = _impl ,
829+ cfg = _image_transition ,
806830)
807831
808832container_image_ = rule (
809- attrs = _attrs ,
833+ attrs = image . attrs ,
810834 doc = "Called by the `container_image` macro with **kwargs, see below" ,
811835 executable = True ,
812- outputs = _outputs ,
836+ outputs = image . outputs ,
813837 toolchains = ["@io_bazel_rules_docker//toolchains/docker:toolchain_type" ],
814- implementation = _impl ,
838+ implementation = image .implementation ,
839+ cfg = image .cfg ,
815840)
816841
817842# This validates the two forms of value accepted by
0 commit comments