Пример #1
0
  def encode(
      self,
      component_spec: Optional[types.ComponentSpec] = None) -> message.Message:
    """Encodes ExecutorSpec into an IR proto for compiling.

    This method will be used by DSL compiler to generate the corresponding IR.

    Args:
      component_spec: Optional. The ComponentSpec to help with the encoding.

    Returns:
      An executor spec proto.
    """
    result = executable_spec_pb2.ContainerExecutableSpec()
    result.image = self.image
    for command in self.command:
      cmd = result.commands.add()
      str_or_placeholder = self._recursively_encode(command)
      if isinstance(str_or_placeholder, str):
        expression = placeholder_pb2.PlaceholderExpression()
        expression.value.string_value = str_or_placeholder
        cmd.CopyFrom(expression)
      else:
        cmd.CopyFrom(self._recursively_encode(command).encode())

    for arg in self.args:
      cmd = result.args.add()
      str_or_placeholder = self._recursively_encode(arg)
      if isinstance(str_or_placeholder, str):
        expression = placeholder_pb2.PlaceholderExpression()
        expression.value.string_value = str_or_placeholder
        cmd.CopyFrom(expression)
      else:
        cmd.CopyFrom(self._recursively_encode(arg).encode())
    return result
                        placeholder {
                          type: INPUT_ARTIFACT
                          key: "input"
                        }
                      }
                      index: 0
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  """, executable_spec_pb2.ContainerExecutableSpec())

_PLATFORM_CONFIG = text_format.Parse(
    """
    environment: "VAR=1"
    environment: "ANOTHER_VAR=2"
    name: "TestContainer"
    privileged: True
    user {
      username: "******"
    }
    volumes {
      key: "/home/user1"
      value: {
        bind: "/mnt/vol2",
        mode: "rw"