...

Text file src/github.com/emissary-ingress/emissary/v3/manifests/push_manifests.sh

Documentation: github.com/emissary-ingress/emissary/v3/manifests

     1#!/bin/bash
     2
     3set -e -o pipefail
     4
     5RED=$'\033[1;31m'
     6END=$'\033[0m'
     7BLOCK=$'\033[1;47m'
     8
     9abort() {
    10    log "${RED}FATAL: $1${END}"
    11    exit 1
    12}
    13
    14log() { >&2 printf '%s>>>%s %s\n' "$BLOCK" "$END" "$*"; }
    15
    16errusage() {
    17    printf >&2 'Usage: %s DIR\n' "$0"
    18    if [[ $# -gt 0 ]]; then
    19        local msg
    20        # shellcheck disable=SC2059
    21        printf -v msg "$@"
    22        printf >&2 '%s: error: %s\n' "$0" "$msg"
    23    fi
    24    exit 2
    25}
    26
    27[[ $# == 1                     ]] || errusage 'wrong number of args: %d' $#
    28[[ -d "$1"                     ]] || errusage 'DIR is not a directory: %q' "$dir"
    29[[ -n "$AWS_ACCESS_KEY_ID"     ]] || errusage "AWS_ACCESS_KEY_ID is not set"
    30[[ -n "$AWS_SECRET_ACCESS_KEY" ]] || errusage "AWS_SECRET_ACCESS_KEY is not set"
    31[[ "${VERSION:-}" == v3.*      ]] || errusage "VERSION must be set to a 'v3.*' string"
    32dir=$1
    33while [[ "$dir" == */ ]]; do
    34    dir=${dir%/}
    35done
    36version=${VERSION#v}
    37
    38log "Publishing manifest version ${version}"
    39
    40if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-ea)?$ ]] ; then
    41    # if this is a stable version, working directory must be clean
    42    # otherwise this is an rc or test version and we don't care
    43    if [ -n "$(git status --porcelain)" ] ; then
    44        abort "working tree is dirty, aborting"
    45    fi
    46elif [[ "${BUMP_STABLE}" ]] ; then
    47    # if this isn't an X.Y.Z version, don't let allow bumping stable
    48    abort "Cannot bump stable unless this is an X.Y.Z tag"
    49fi
    50if [ -z "$AWS_S3_BUCKET" ] ; then
    51    AWS_S3_BUCKET=datawire-static-files
    52fi
    53
    54echo "$version" > stable.txt
    55
    56aws s3api put-object \
    57    --bucket "$AWS_S3_BUCKET" \
    58    --key "yaml/emissary/${version}"
    59
    60find "$dir" -type f -name '*.yaml' -print0 | while read -r -d '' file; do
    61    aws s3api put-object \
    62        --bucket "$AWS_S3_BUCKET" \
    63        --key "yaml/emissary/${version}/${file##*/}" \
    64        --body "$file"
    65    echo "... yaml/emissary/${version}/${file##*/} pushed"
    66done
    67
    68if [[ "${BUMP_STABLE}" ]] ; then
    69    log "Bumping stable version for yaml/emissary"
    70    aws s3api put-object \
    71        --bucket "$AWS_S3_BUCKET" \
    72        --key "yaml/emissary/stable.txt" \
    73        --body stable.txt
    74fi
    75rm stable.txt
    76
    77exit 0

View as plain text