...

Text file src/sigs.k8s.io/gateway-api/hack/build-and-push.sh

Documentation: sigs.k8s.io/gateway-api/hack

     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
    19set -o errexit
    20set -o nounset
    21set -o pipefail
    22
    23if [[ -z "${VERIFY-}" ]];
    24then
    25  export DOCKER_PUSH_FLAG="--push"
    26else
    27  export DOCKER_PUSH_FLAG=""
    28fi
    29
    30if [[ -z "${GIT_TAG-}" ]];
    31then
    32    echo "GIT_TAG env var must be set and nonempty."
    33    exit 1
    34fi
    35
    36if [[ -z "${BASE_REF-}" ]];
    37then
    38    echo "BASE_REF env var must be set and nonempty."
    39    exit 1
    40fi
    41
    42if [[ -z "${COMMIT-}" ]];
    43then
    44    echo "COMMIT env var must be set and nonempty."
    45    exit 1
    46fi
    47
    48if [[ -z "${REGISTRY-}" ]];
    49then
    50    echo "REGISTRY env var must be set and nonempty."
    51    exit 1
    52fi
    53
    54
    55
    56# If our base ref == "main" then we will tag :latest.
    57VERSION_TAG=latest
    58
    59# We tag the go binary with the git-based tag by default
    60BINARY_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.
    65if [[ "${BASE_REF}" != "main" ]]
    66then
    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}"
    72fi
    73
    74# Support multi-arch image build and push.
    75BUILDX_PLATFORMS="linux/amd64,linux/arm64"
    76
    77echo "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.
    83docker 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
    93echo "Building and pushing echo-advanced image (from Istio) ...${BUILDX_PLATFORMS}"
    94
    95docker 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
   103echo "Building and pushing echo-basic image (previously in Ingress Controller Conformance Repo) ...${BUILDX_PLATFORMS}"
   104
   105docker 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    .

View as plain text