forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_release
executable file
·99 lines (85 loc) · 2.91 KB
/
prepare_release
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
#!/usr/bin/env sh
#
# Copyright 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
#
# 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
repo_root_dir="$(realpath $1)"
repo_base="$2"
repo_name="$3"
apk update
apk add --no-cache \
ca-certificates \
make \
bash \
git \
curl \
openssl \
tar \
gzip \
sed \
jq
# create virtual package with the dev tools
echo "Installing dev tools in a virtual package"
apk add --no-cache --virtual .build-deps \
gcc \
go \
musl-dev
GOLANG_VERSION="$(sed -rn 's/FROM (eu\.gcr\.io\/gardener-project\/3rd\/golang|golang):([^ ]+).*/\2/p' < "$repo_root_dir/Dockerfile")"
# As we cannot expect alpine to provide and maintain all golang versions via apk, we need to find another way to install the required golang version.
# Alpine is using musl-libc instead of glibc, therefore we cannot use the available pre-built binaries from golang, but have to build them ourselves from source.
# refs:
# - https://stackoverflow.com/a/45987284
# - https://github.com/docker-library/golang/blob/f300e60ca19c3b98cfcf01ca112af2ac10104320/1.16/alpine3.14/Dockerfile
echo "Downloading go src $GOLANG_VERSION"
rm -rf /usr/local/go
wget -q -O - "https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz" | tar zx -C /usr/local
# Configure golang environment
echo "Building and installing go $GOLANG_VERSION"
export \
PATH="/usr/local/go/bin":$PATH \
GOARCH="$(go env GOARCH)" \
GOOS="$(go env GOOS)" \
GOROOT_BOOTSTRAP="$(go env GOROOT)"
export GOHOSTOS="$GOOS" \
GOHOSTARCH="$GOARCH"
cd /usr/local/go/src
echo "Executing make on go $GOLANG_VERSION"
./make.bash
echo "Deleting the virtual package for go"
apk del --no-network .build-deps
export GOROOT="/usr/local/go"
export GOPATH="$(mktemp -d)"
export GOBIN="$GOPATH/bin"
export PATH="$GOBIN:$PATH"
REPO_BASE="$GOPATH/src/$repo_base"
mkdir -p "$REPO_BASE"
REPO_PATH="$REPO_BASE/$repo_name"
cp -R "$repo_root_dir" "$REPO_PATH"
current_dir="$(pwd)"
cd "$REPO_PATH"
if make -n install-requirements &>/dev/null; then
make install-requirements
else
echo "skipping optional 'make install-requirements' as it is not present"
fi
cd "$current_dir"
echo "$EFFECTIVE_VERSION" > "$REPO_PATH/VERSION"
cur_dir="$(pwd)"
cd "$REPO_PATH"
if ! make generate; then
cd "$cur_dir"
exit 1
fi
cd "$cur_dir"
cp -RT "$REPO_PATH/" "$repo_root_dir/"