forked from JanusGraph/janusgraph-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·90 lines (78 loc) · 2.92 KB
/
update.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
#!/usr/bin/env bash
#
# Copyright 2019 JanusGraph Authors
#
# 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 -Eeuo pipefail
cd $(dirname $0)
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=($(ls -d [0-9]*))
fi
# generate header for auto-generated files
template-generated-warning() {
COMMENT=$1
cat <<-EOD
${COMMENT}
${COMMENT} NOTE: THIS FILE IS GENERATED VIA "update.sh"
${COMMENT} DO NOT EDIT IT DIRECTLY; CHANGES WILL BE OVERWRITTEN.
${COMMENT}
EOD
}
# copy template file to version directory and add header
copy-with-template-generated-warning() {
FILE=$1
COMMENT=$2
template-generated-warning "${COMMENT}" > $dir/$FILE
cat build/$FILE >> $dir/$FILE
}
for version in "${versions[@]}"; do
if [[ $version =~ ^[0]+.[0-4](.[0-9]+)*$ ]]; then
continue
fi
if [[ $version =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
# given latest version, get versioned directory
major_minor_version=$(echo $version | cut -d"." -f 1-2)
latest_version=$version
else
# given versioned directory, query GitHub API for latest version
major_minor_version="$version"
url=https://api.github.com/repos/janusgraph/janusgraph/tags
filter='[.[].name|select(test("v'${version}'.[0-9]+$"))|ltrimstr("v")][0]'
latest_version=$(curl -s "$url" | jq ''$filter'' | tr -d '"')
if [ ${latest_version} == "null" ]; then
echo "Version not found"
exit 1
fi
fi
dir=$major_minor_version
echo "$version/$latest_version"
mkdir -p $dir/conf $dir/scripts
# copy Dockerfile and update version
template-generated-warning "#" > "$dir/Dockerfile"
sed -e 's!^\(ARG JANUS_VERSION\)\s*=.*!\1='"${latest_version}"'!' \
-e 's!{MAJOR_MINOR_VERSION_PLACEHOLDER}!'"${major_minor_version}"'!' \
build/Dockerfile-openjdk8.template >> "$dir/Dockerfile"
# copy docker-entrypoint
head -n 1 build/docker-entrypoint.sh > $dir/docker-entrypoint.sh
template-generated-warning "#" >> $dir/docker-entrypoint.sh
awk 'NR>1' build/docker-entrypoint.sh >> $dir/docker-entrypoint.sh
# copy load-initdb
head -n 1 build/load-initdb.sh > $dir/load-initdb.sh
template-generated-warning "#" >> $dir/load-initdb.sh
awk 'NR>1' build/load-initdb.sh >> $dir/load-initdb.sh
# copy resources
copy-with-template-generated-warning conf/janusgraph-berkeleyje-lucene-server.properties "#"
copy-with-template-generated-warning conf/log4j-server.properties "#"
copy-with-template-generated-warning scripts/remote-connect.groovy "//"
done