hack: polish scripts (#133)

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2019-01-29 14:05:37 -08:00 committed by GitHub
parent 1d452f449a
commit 3da0ae3b31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 56 deletions

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -14,26 +16,26 @@
# Builds and pushes docker image for each demo microservice.
#!/usr/bin/env bash
set -euo pipefail
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
log() { echo "$1" >&2; }
fail() { log "$1"; exit 1; }
TAG="${TAG?TAG env variable must be specified}"
REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}"
for dir in ./src/*/
do
while IFS= read -d $'\0' -r dir; do
# build image
svcname="$(basename $dir)"
image="$REPO_PREFIX/$svcname:$TAG"
echo "Building and pushing $image..."
docker build -t $image -f $dir/Dockerfile $dir
svcname="$(basename "${dir}")"
image="${REPO_PREFIX}/$svcname:$TAG"
(
cd "${dir}"
log "Building: ${image}"
docker build -t "${image}" .
# push image
docker push $image
done
log "Pushing: ${image}"
docker push "${image}"
)
done < <(find "${SCRIPTDIR}/../src" -mindepth 1 -maxdepth 1 -type d -print0)
log "Successfully built and pushed images."
log "Successfully built and pushed all images."

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -14,42 +16,41 @@
# injects new image/tag into the images in ./release/kubernetes-manifests/demo.yaml
#!/usr/bin/env bash
set -euo pipefail
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
log() { echo "$1" >&2; }
fail() { log "$1"; exit 1; }
TAG="${TAG?TAG env variable must be specified}"
REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}"
out_file="${SCRIPTDIR}/../release/kubernetes-manifests/demo.yaml"
# overwrite release/ with the latest manifests, adding "---" separator.
src="./kubernetes-manifests/*"
manifestfile="./release/kubernetes-manifests/demo.yaml"
tmp="./release/kubernetes-manifests/tmp.yaml"
[ -e $manifestfile ] && rm $manifestfile
for f in $src; do (cat "${f}"; echo "---") >> $tmp; done
read_manifests() {
local src_manifest_dir
src_manifest_dir="${SCRIPTDIR}/../kubernetes-manifests"
# remove extra google headers
gsed -i '/^#/d' $tmp
while IFS= read -d $'\0' -r file; do
cat "${file}"
echo "---"
done < <(find "${src_manifest_dir}" -name '*.yaml' -type f -print0)
}
# remove empty lines
gsed -r -i '/^\s*$/d' $tmp
# read and merge all manifests
out_manifest="$(read_manifests)"
# add 1 google header to the top
cat "./release/.googleheader" $tmp > $manifestfile
rm $tmp
# replace image repo, tag for each deployment
# replace "image" repo, tag for each service
for dir in ./src/*/
do
svcname="$(basename $dir)"
svcname="$(basename "${dir}")"
image="$REPO_PREFIX/$svcname:$TAG"
pattern="^(\s*)image:\s.*$svcname(.*)(\s*)"
replace="\1image: $image\3"
gsed -r -i "s|$pattern|$replace|g" $manifestfile
out_manifest="$(gsed -r "s|$pattern|$replace|g" <(echo "${out_manifest}") )"
done
log "Successfully added image tags > wrote to demo.yaml".
rm -rf -- "${out_file}"
mkdir -p "$(dirname "${out_file}")"
echo "${out_manifest}" > "${out_file}"
log "Successfully saved merged manifests to ${out_file}."

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -15,7 +17,6 @@
# Creates a new release by 1) building/pushing images, 2) injecting tag into YAML,
# 3) creating a new git tag, and 4) pushing tags/updated YAML to $BRANCH.
#!/usr/bin/env bash
set -euo pipefail
log() { echo "$1" >&2; }

View file

@ -1,13 +0,0 @@
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.