github.com/GoogleCloudPlatform/testgrid@v0.0.174/def.bzl (about)

     1  # Copyright 2019 The Kubernetes Authors.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  load("@io_bazel_rules_docker//container:image.bzl", "container_image")
    16  load("@io_bazel_rules_docker//container:bundle.bzl", "container_bundle")
    17  load("@io_bazel_rules_docker//contrib:push-all.bzl", "container_push")
    18  load("@io_bazel_rules_docker//go:image.bzl", _go_image = "go_image")
    19  
    20  ## make_image is a macro for creating :app and :image targets
    21  def go_image(
    22          name,  # use "image"
    23          base = None,
    24          stamp = "@io_bazel_rules_docker//stamp:always",  # stamp by default, but allow overrides
    25          app_name = "app",
    26          **kwargs):
    27      _go_image(
    28          name = app_name,
    29          base = base,
    30          embed = [":go_default_library"],
    31          goarch = "amd64",
    32          goos = "linux",
    33          pure = "on",
    34      )
    35  
    36      container_image(
    37          name = name,
    38          base = ":" + app_name,
    39          stamp = stamp,
    40          **kwargs
    41      )
    42  
    43  # push_image creates a bundle of container images, and a target to push them.
    44  def push_image(
    45          name,
    46          bundle_name = "bundle",
    47          images = None):
    48      container_bundle(
    49          name = bundle_name,
    50          images = images,
    51      )
    52      container_push(
    53          name = name,
    54          bundle = ":" + bundle_name,
    55          format = "Docker",  # TODO(fejta): consider OCI?
    56      )
    57  
    58  # tags appends default tags to name
    59  #
    60  # In particular, names is a {image_prefix: image_target} mapping, which gets
    61  # expanded into three full image paths:
    62  #   image_prefix:latest
    63  #   image_prefix:latest-{BUILD_USER}
    64  #   image_prefix:{DOCKER_TAG}
    65  # (See hack/print-workspace-status.sh for how BUILD_USER and DOCKER_TAG are created.
    66  def tags(targets):
    67      outs = {}
    68      for img, target in targets.items():
    69          outs["%s:{DOCKER_TAG}" % img] = target
    70          outs["%s:latest-{BUILD_USER}" % img] = target
    71          outs["%s:latest" % img] = target
    72      return outs