sigs.k8s.io/gateway-api@v1.0.0/hack/build-and-push.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2022 The Kubernetes Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # This file is run by cloudbuild, from cloudbuild.yaml, using `make release-staging`.
    18  
    19  set -o errexit
    20  set -o nounset
    21  set -o pipefail
    22  
    23  if [[ -z "${VERIFY-}" ]];
    24  then
    25    export DOCKER_PUSH_FLAG="--push"
    26  else
    27    export DOCKER_PUSH_FLAG=""
    28  fi
    29  
    30  if [[ -z "${GIT_TAG-}" ]];
    31  then
    32      echo "GIT_TAG env var must be set and nonempty."
    33      exit 1
    34  fi
    35  
    36  if [[ -z "${BASE_REF-}" ]];
    37  then
    38      echo "BASE_REF env var must be set and nonempty."
    39      exit 1
    40  fi
    41  
    42  if [[ -z "${COMMIT-}" ]];
    43  then
    44      echo "COMMIT env var must be set and nonempty."
    45      exit 1
    46  fi
    47  
    48  if [[ -z "${REGISTRY-}" ]];
    49  then
    50      echo "REGISTRY env var must be set and nonempty."
    51      exit 1
    52  fi
    53  
    54  
    55  
    56  # If our base ref == "main" then we will tag :latest.
    57  VERSION_TAG=latest
    58  
    59  # We tag the go binary with the git-based tag by default
    60  BINARY_TAG=$GIT_TAG
    61  
    62  # $BASE_REF has only two things that it can be set to by cloudbuild and Prow,
    63  # `main`, or a semver tag.
    64  # This is controlled by k8s.io/test-infra/config/jobs/image-pushing/k8s-staging-gateway-api.yaml.
    65  if [[ "${BASE_REF}" != "main" ]]
    66  then
    67      # Since we know this is built from a tag or release branch, we can set the VERSION_TAG
    68      VERSION_TAG="${BASE_REF}"
    69  
    70      # Include the semver tag in the binary instead of the git-based tag
    71      BINARY_TAG="${BASE_REF}"
    72  fi
    73  
    74  # Support multi-arch image build and push.
    75  BUILDX_PLATFORMS="linux/amd64,linux/arm64"
    76  
    77  echo "Building and pushing admission-server image...${BUILDX_PLATFORMS}"
    78  
    79  # First, build the image, with the version info passed in.
    80  # Note that an image will *always* be built tagged with the GIT_TAG, so we know when it was built.
    81  # And, we add an extra version tag - either :latest or semver.
    82  # The buildx integrate build and push in one line.
    83  docker buildx build \
    84      -t ${REGISTRY}/admission-server:${GIT_TAG} \
    85      -t ${REGISTRY}/admission-server:${VERSION_TAG} \
    86      --build-arg "COMMIT=${COMMIT}" \
    87      --build-arg "TAG=${BINARY_TAG}" \
    88      --platform ${BUILDX_PLATFORMS} \
    89      ${DOCKER_PUSH_FLAG} \
    90      -f docker/Dockerfile.webhook \
    91      .
    92  
    93  echo "Building and pushing echo-advanced image (from Istio) ...${BUILDX_PLATFORMS}"
    94  
    95  docker buildx build \
    96      -t ${REGISTRY}/echo-advanced:${GIT_TAG} \
    97      -t ${REGISTRY}/echo-advanced:${VERSION_TAG} \
    98      --platform ${BUILDX_PLATFORMS} \
    99      ${DOCKER_PUSH_FLAG} \
   100      -f docker/Dockerfile.echo-advanced \
   101      .
   102  
   103  echo "Building and pushing echo-basic image (previously in Ingress Controller Conformance Repo) ...${BUILDX_PLATFORMS}"
   104  
   105  docker buildx build \
   106      -t ${REGISTRY}/echo-basic:${GIT_TAG} \
   107      -t ${REGISTRY}/echo-basic:${VERSION_TAG} \
   108      --platform ${BUILDX_PLATFORMS} \
   109      ${DOCKER_PUSH_FLAG} \
   110      -f docker/Dockerfile.echo-basic \
   111      .