From 6500b770cf6fa873efd15b5c7a5ba73b8b81ffd9 Mon Sep 17 00:00:00 2001 From: m-okeefe Date: Mon, 28 Jan 2019 15:12:33 -0800 Subject: [PATCH] Resolved comments --- hack/README.md | 20 ++++++++++ hack/build-push.sh | 29 -------------- hack/inject-yaml.sh | 29 -------------- hack/make-docker-images.sh | 39 +++++++++++++++++++ hack/make-release-artifacts.sh | 41 +++++++++++++++++++ hack/make-release.sh | 65 +++++++++++++++---------------- hack/restore-release-artifacts.sh | 35 +++++++++++++++++ hack/restore.sh | 14 ------- 8 files changed, 166 insertions(+), 106 deletions(-) create mode 100755 hack/README.md delete mode 100644 hack/build-push.sh delete mode 100644 hack/inject-yaml.sh create mode 100755 hack/make-docker-images.sh create mode 100755 hack/make-release-artifacts.sh create mode 100755 hack/restore-release-artifacts.sh delete mode 100644 hack/restore.sh diff --git a/hack/README.md b/hack/README.md new file mode 100755 index 0000000..8deb56f --- /dev/null +++ b/hack/README.md @@ -0,0 +1,20 @@ +## `hack/` + +This directory provides scripts for building and pushing Docker images, and tagging new demo +releases. + +### env variables + +- `TAG` - git release tag / Docker tag. +- `REPO_PREFIX` - Docker repo prefix to push images. Format: `$user/$project`. Resulting images will be of the + format `$user/$project/$svcname:$tag` (where `svcname` = `adservice`, `cartservice`, + etc.) + +### scripts + +1. `./make-docker-images.sh`: builds and pushes images to the specified Docker repository. +2. `./make-release-artifacts.sh`: injects updated images/tag into + `./release/kubernetes-manifests/demo.yaml`. +3. `./restore-release-artifacts.sh`: restores image names/tags in `demo.yaml` to defaults + (`adservice`, `cartservice`, etc.) +4. `./make-release.sh`: runs scripts 1 and 2, then runs `git tag` / pushes updated manifests to master. diff --git a/hack/build-push.sh b/hack/build-push.sh deleted file mode 100644 index 237c7a4..0000000 --- a/hack/build-push.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# set vars -if [ -n "$1" ]; then - DOCKER_REPO=$1 -else - echo "Must provide a docker repo" - exit -fi - -if [ -n "$2" ]; then - TAG=$2 -else - echo "Must provide a version tag." - exit -fi - - -for dir in ./src/*/ -do - # build image - svcname=$(basename $dir) - image="$DOCKER_REPO/$svcname:$TAG" - echo "Building and pushing $image..." - docker build -t $image -f $dir/Dockerfile $dir - - # push image - docker push $image -done \ No newline at end of file diff --git a/hack/inject-yaml.sh b/hack/inject-yaml.sh deleted file mode 100644 index ac17e7c..0000000 --- a/hack/inject-yaml.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# set vars -if [ -n "$1" ]; then - DOCKER_REPO=$1 -else - echo "Must provide a docker repo" - exit -fi - -if [ -n "$2" ]; then - TAG=$2 -else - echo "Must provide a version tag." - exit -fi - -# inject new tag into the relevant k8s manifest -manifestfile="./release/kubernetes-manifests/demo.yaml" - -for dir in ./src/*/ -do - svcname=$(basename $dir) - image="$DOCKER_REPO/$svcname:$TAG" - - pattern=".*image:.*$svcname.*" - replace=" image: $image" - sed -i '' "s|$pattern|$replace|g" $manifestfile -done \ No newline at end of file diff --git a/hack/make-docker-images.sh b/hack/make-docker-images.sh new file mode 100755 index 0000000..51a8e10 --- /dev/null +++ b/hack/make-docker-images.sh @@ -0,0 +1,39 @@ +# 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. + +# Builds and pushes docker image for each demo microservice. + +#!/usr/bin/env bash +set -euo pipefail + +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 + # build image + svcname="$(basename $dir)" + image="$REPO_PREFIX/$svcname:$TAG" + echo "Building and pushing $image..." + docker build -t $image -f $dir/Dockerfile $dir + + # push image + docker push $image +done + +log "Successfully built and pushed images." diff --git a/hack/make-release-artifacts.sh b/hack/make-release-artifacts.sh new file mode 100755 index 0000000..a24aee7 --- /dev/null +++ b/hack/make-release-artifacts.sh @@ -0,0 +1,41 @@ +# 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. + +# injects new image/tag into the images in ./release/kubernetes-manifests/demo.yaml + +#!/usr/bin/env bash +set -euo pipefail + +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}" + + +# inject new tag into the relevant k8s manifest +manifestfile="./release/kubernetes-manifests/demo.yaml" + +for dir in ./src/*/ +do + svcname="$(basename $dir)" + image="$REPO_PREFIX/$svcname:$TAG" + + pattern=".*image:.*$svcname.*" + replace=" image: $image" + sed -i '' "s|$pattern|$replace|g" $manifestfile +done + + +log "Successfully injected image tag into demo.yaml". diff --git a/hack/make-release.sh b/hack/make-release.sh index ad10386..1eb8bce 100755 --- a/hack/make-release.sh +++ b/hack/make-release.sh @@ -1,44 +1,41 @@ -#!/bin/bash +# 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. -# set vars -if [ -n "$1" ]; then - DOCKER_REPO=$1 -else - echo "Must provide a docker repo" - exit -fi +# 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. -if [ -n "$2" ]; then - TAG=$2 -else - echo "Must provide a version tag." - exit -fi +#!/usr/bin/env bash +set -euo pipefail -if [ -n "$3" ]; then - BRANCH=$3 -else - echo "Must provide a git branch." - exit -fi +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}" # build and push images -./build-push.sh $DOCKER_REPO $TAG - +./hack/make-docker-images.sh # update yaml -./inject-yaml.sh $DOCKER_REPO $TAG +./hack/make-release-artifacts.sh - -# git tag -echo "Pushing git tag..." -git tag $TAG +# create git release / push to master +log "Pushing k8s manifests to master..." +git tag "$TAG" +git add release/ +git commit --allow-empty -m "Release $TAG" git push --tags +git push origin master -# push updated manifests -echo "Commiting to $BRANCH..." -git add . -git commit -m "Tagged release $TAG" -git push origin $BRANCH - -echo "✅ Successfully tagged release $TAG" +log "Successfully tagged release $TAG." diff --git a/hack/restore-release-artifacts.sh b/hack/restore-release-artifacts.sh new file mode 100755 index 0000000..e8f2338 --- /dev/null +++ b/hack/restore-release-artifacts.sh @@ -0,0 +1,35 @@ +# 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. + + +# Restores images ./release/kubernetes-manifests/demo.yaml to match ./kubernetes-manifests + +#!/usr/bin/env bash +set -euo pipefail + +log() { echo "$1" >&2; } +fail() { log "$1"; exit 1; } + +manifestfile="./release/kubernetes-manifests/demo.yaml" + +# restore release/ manifest images to skaffold default, eg. "adservice" +for dir in ./src/*/ +do + svcname=$(basename $dir) + pattern=".*image:.*$svcname.*" + replace=" image: $svcname" + sed -i '' "s|$pattern|$replace|g" $manifestfile +done + +log "Restored demo.yaml." diff --git a/hack/restore.sh b/hack/restore.sh deleted file mode 100644 index 0bae8fa..0000000 --- a/hack/restore.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -manifestfile="./release/kubernetes-manifests/demo.yaml" - -# restore release/ manifest images to skaffold default, eg. "adservice" -for dir in ./src/*/ -do - svcname=$(basename $dir) - image="$DOCKER_REPO/$svcname:$TAG" - - pattern=".*image:.*$svcname.*" - replace=" image: $svcname" - sed -i '' "s|$pattern|$replace|g" $manifestfile -done \ No newline at end of file