-
Notifications
You must be signed in to change notification settings - Fork 4
/
apigee-pull-push.sh
executable file
·122 lines (102 loc) · 3.79 KB
/
apigee-pull-push.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
# Copyright 2022 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.
# Exit immediately if sequence of one or more commands returns a non-zero status.
set -e
#PWD=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
# shellcheck disable=SC1090
#source "${PWD}/common.sh"
source common.sh
TAG=${APIGEE_VERSION}
REPO=$1
APIGEE_COMPONENTS=("apigee-authn-authz" "apigee-mart-server" "apigee-synchronizer" "apigee-runtime" "apigee-hybrid-cassandra-client" "apigee-hybrid-cassandra" "apigee-cassandra-backup-utility" "apigee-udca" "apigee-connect-agent" "apigee-watcher" "apigee-operators" "apigee-installer" "apigee-redis" "apigee-diagnostics-collector" "apigee-diagnostics-runner")
THIRD_PARTY_COMPONENTS=("apigee-stackdriver-logging-agent:1.8.9" "apigee-prom-prometheus:v2.25.0" "apigee-stackdriver-prometheus-sidecar:0.9.0" "apigee-kube-rbac-proxy:v0.8.0" "apigee-envoy:v1.19.1")
#**
# @brief Displays usage details.
#
usage() {
log_info "$*\\n usage: $(basename "$0")" \
"[repo where you want to push the images]\\n" \
"Note: if the repo is not provided. It will be pushed to us.gcr.io/<PROJECT_ID>.\\n" \
" Please make sure you have gcloud installed as it uses for finding out PROJECT_ID\\n\\n" \
"example: $(basename "$0") [foo.docker.com]"
}
#**
# @brief Obtains GCP project ID from gcloud configuration and updates global variable PROJECT_ID.
#
get_project(){
local project_id ret
local msg="Provide GCP Project ID via command line arguments or update gcloud config: gcloud config set project <project_id>"
project_id=$(gcloud config list core/project --format='value(core.project)'); ret=$?
[[ ${ret} -ne 0 || -z "${project_id}" ]] && \
usage "Failed to get project ID from gcloud config.\\n${msg}"
log_info "gcloud configured project ID is ${project_id}.\\n" \
"Press: y to proceed for pushing images in project: ${project_id}\\n" \
"Press: n to abort."
read -r prompt
if [[ "${prompt}" != "y" ]]; then
usage "Aborting.\\n${msg}"
exit 0
fi
PROJECT_ID="${project_id}"
}
docker_exe() {
local action=$1
local repo=$2
for i in "${APIGEE_COMPONENTS[@]}"
do
docker "${action}" "${repo}/$i:${TAG}"
done
for i in "${THIRD_PARTY_COMPONENTS[@]}"
do
docker "${action}" "${repo}/$i"
done
}
docker_tag() {
local source=$1
local dest=$2
for i in "${APIGEE_COMPONENTS[@]}"
do
docker tag "${source}/$i:${TAG}" "${dest}/$i:${TAG}"
done
for i in "${THIRD_PARTY_COMPONENTS[@]}"
do
docker tag "${source}/$i" "${dest}/$i"
done
}
# check whether user had supplied -h or --help . If yes display usage
if [[ ( $* == "--help") || $* == "-h" ]]
then
usage
exit 0
fi
# Check gcloud config for project ID.
if [[ -z "${REPO}" ]]; then
# Check gcloud is installed and on the $PATH.
if ! which gcloud > /dev/null 2>&1; then
log_error "gcloud is not installed or not on PATH."
fi
get_project
REPO="us.gcr.io/${PROJECT_ID}"
fi
# Check docker is installed and on the $PATH.
if ! which docker > /dev/null 2>&1; then
log_error "docker is not installed or not on PATH."
fi
# Pull all the images from the Google Docker Hub
docker_exe "pull" "google"
# tag the pulled images
docker_tag "google" "${REPO}"
# Push the images to the user defined repo.
docker_exe "push" "${REPO}"