forked from googleapis/gapic-generator-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gapic.sh
executable file
·107 lines (93 loc) · 3.04 KB
/
gapic.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
#!/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 -e
CMD="$0"
# Set variables used by this script.
# All of these are set in options below, and all but PLUGIN_OPTIONS and
# PROTO_PATH are required.
IMAGE=
IN=
OUT=
PLUGIN_OPTIONS=
PROTO_PATH=`pwd`
GAPIC_SERVICE_CONFIG=
# Print help and exit.
function show_help {
cat << EOF
Usage: $CMD --image IMAGE --in IN_DIR --out OUT_DIR [--path PATH_DIR]
Required arguments:
--image The Docker image to use. The script will attempt to pull
it if it is not present.
-i, --in A directory containing the protos describing the API
to be generated.
-o, --out Destination directory for the completed client library.
--config Location of the GAPIC service configuration .yml file.
Optional arguments:
-p, --path The base import path for the protos. Assumed to be the
current working directory if unspecified.
-h, --help This help information.
EOF
exit 0
}
# Parse out options.
while true; do
case "$1" in
-h | --help ) show_help ;;
--image ) IMAGE="$2"; shift 2 ;;
-i | --in ) IN="$2"; shift 2 ;;
-o | --out ) OUT="$2"; shift 2 ;;
-p | --path ) PROTO_PATH=$2; shift 2 ;;
--config ) GAPIC_SERVICE_CONFIG=$2; shift 2 ;;
--* ) PLUGIN_OPTIONS="$PLUGIN_OPTIONS $1 $2"; shift 2 ;;
-- ) shift; break; ;;
* ) break ;;
esac
done
# Ensure that all required options are set.
if [ -z "$IMAGE" ] || [ -z "$IN" ] || [ -z "$OUT" ]; then
cat << EOF
Required argument missing.
The --image, --in, and --out arguments are all required.
Run $CMD --help for more information.
EOF
exit 64
fi
# Ensure that the input directory exists (and is a directory).
if ! [ -d ${PROTO_PATH}/${IN} ]; then
cat << EOF
Directory does not exist: ${PROTO_PATH}/${IN}
EOF
exit 2
fi
# Ensure Docker is running and seems healthy.
# This is mostly a check to bubble useful errors quickly.
docker ps > /dev/null
# If the output directory does not exist, create it.
mkdir -p $OUT
# If the output directory is not empty, warn (but continue).
if [ "$(ls -A $OUT )" ]; then
cat << EOF
Warning: Output directory is not empty.
EOF
fi
# Generate the client library.
docker run \
--mount type=bind,source=${PROTO_PATH}/${IN},destination=/workspace/in/${IN},readonly \
--mount type=bind,source=${PROTO_PATH}/${GAPIC_SERVICE_CONFIG},destination=/workspace/config.yml,readonly \
--mount type=bind,source=${PROTO_PATH}/${OUT},destination=/workspace/out \
--rm \
--user $UID \
$IMAGE \
$PLUGIN_OPTIONS