hack: polish scripts (#133)
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
1d452f449a
commit
3da0ae3b31
4 changed files with 47 additions and 56 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright 2019 Google LLC
|
# Copyright 2019 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -12,28 +14,28 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Builds and pushes docker image for each demo microservice.
|
# Builds and pushes docker image for each demo microservice.
|
||||||
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
log() { echo "$1" >&2; }
|
log() { echo "$1" >&2; }
|
||||||
fail() { log "$1"; exit 1; }
|
|
||||||
|
|
||||||
TAG="${TAG?TAG env variable must be specified}"
|
TAG="${TAG?TAG env variable must be specified}"
|
||||||
REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}"
|
REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}"
|
||||||
|
|
||||||
|
while IFS= read -d $'\0' -r dir; do
|
||||||
|
# build image
|
||||||
|
svcname="$(basename "${dir}")"
|
||||||
|
image="${REPO_PREFIX}/$svcname:$TAG"
|
||||||
|
(
|
||||||
|
cd "${dir}"
|
||||||
|
log "Building: ${image}"
|
||||||
|
docker build -t "${image}" .
|
||||||
|
|
||||||
for dir in ./src/*/
|
log "Pushing: ${image}"
|
||||||
do
|
docker push "${image}"
|
||||||
# build image
|
)
|
||||||
svcname="$(basename $dir)"
|
done < <(find "${SCRIPTDIR}/../src" -mindepth 1 -maxdepth 1 -type d -print0)
|
||||||
image="$REPO_PREFIX/$svcname:$TAG"
|
|
||||||
echo "Building and pushing $image..."
|
|
||||||
docker build -t $image -f $dir/Dockerfile $dir
|
|
||||||
|
|
||||||
# push image
|
log "Successfully built and pushed all images."
|
||||||
docker push $image
|
|
||||||
done
|
|
||||||
|
|
||||||
log "Successfully built and pushed images."
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright 2019 Google LLC
|
# Copyright 2019 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# 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
|
# injects new image/tag into the images in ./release/kubernetes-manifests/demo.yaml
|
||||||
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
log() { echo "$1" >&2; }
|
log() { echo "$1" >&2; }
|
||||||
fail() { log "$1"; exit 1; }
|
|
||||||
|
|
||||||
TAG="${TAG?TAG env variable must be specified}"
|
TAG="${TAG?TAG env variable must be specified}"
|
||||||
REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX 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.
|
read_manifests() {
|
||||||
src="./kubernetes-manifests/*"
|
local src_manifest_dir
|
||||||
manifestfile="./release/kubernetes-manifests/demo.yaml"
|
src_manifest_dir="${SCRIPTDIR}/../kubernetes-manifests"
|
||||||
tmp="./release/kubernetes-manifests/tmp.yaml"
|
|
||||||
[ -e $manifestfile ] && rm $manifestfile
|
|
||||||
for f in $src; do (cat "${f}"; echo "---") >> $tmp; done
|
|
||||||
|
|
||||||
# remove extra google headers
|
while IFS= read -d $'\0' -r file; do
|
||||||
gsed -i '/^#/d' $tmp
|
cat "${file}"
|
||||||
|
echo "---"
|
||||||
|
done < <(find "${src_manifest_dir}" -name '*.yaml' -type f -print0)
|
||||||
|
}
|
||||||
|
|
||||||
# remove empty lines
|
# read and merge all manifests
|
||||||
gsed -r -i '/^\s*$/d' $tmp
|
out_manifest="$(read_manifests)"
|
||||||
|
|
||||||
# add 1 google header to the top
|
# replace "image" repo, tag for each service
|
||||||
cat "./release/.googleheader" $tmp > $manifestfile
|
for dir in ./src/*/
|
||||||
rm $tmp
|
|
||||||
|
|
||||||
|
|
||||||
# replace image repo, tag for each deployment
|
|
||||||
for dir in ./src/*/
|
|
||||||
do
|
do
|
||||||
svcname="$(basename $dir)"
|
svcname="$(basename "${dir}")"
|
||||||
image="$REPO_PREFIX/$svcname:$TAG"
|
image="$REPO_PREFIX/$svcname:$TAG"
|
||||||
|
|
||||||
pattern="^(\s*)image:\s.*$svcname(.*)(\s*)"
|
pattern="^(\s*)image:\s.*$svcname(.*)(\s*)"
|
||||||
replace="\1image: $image\3"
|
replace="\1image: $image\3"
|
||||||
gsed -r -i "s|$pattern|$replace|g" $manifestfile
|
out_manifest="$(gsed -r "s|$pattern|$replace|g" <(echo "${out_manifest}") )"
|
||||||
done
|
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}."
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright 2019 Google LLC
|
# Copyright 2019 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# 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,
|
# 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.
|
# 3) creating a new git tag, and 4) pushing tags/updated YAML to $BRANCH.
|
||||||
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
log() { echo "$1" >&2; }
|
log() { echo "$1" >&2; }
|
||||||
|
@ -24,13 +25,13 @@ fail() { log "$1"; exit 1; }
|
||||||
TAG="${TAG?TAG env variable must be specified}"
|
TAG="${TAG?TAG env variable must be specified}"
|
||||||
REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}"
|
REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}"
|
||||||
|
|
||||||
# build and push images
|
# build and push images
|
||||||
./hack/make-docker-images.sh
|
./hack/make-docker-images.sh
|
||||||
|
|
||||||
# update yaml
|
# update yaml
|
||||||
./hack/make-release-artifacts.sh
|
./hack/make-release-artifacts.sh
|
||||||
|
|
||||||
# create git release / push to master
|
# create git release / push to master
|
||||||
log "Pushing k8s manifests to master..."
|
log "Pushing k8s manifests to master..."
|
||||||
git tag "$TAG"
|
git tag "$TAG"
|
||||||
git add release/
|
git add release/
|
||||||
|
|
|
@ -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.
|
|
Loading…
Reference in a new issue