-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhelpers.sh
141 lines (125 loc) · 3.87 KB
/
helpers.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Common helper functions for all scripts
set -o pipefail
function indent { sed 's/^/| /'; echo "|--" ;}
function status { echo == $(date "+%F %T") $* ; }
function run { set -o pipefail; status "Running: $*"; $* 2>&1 | indent ; }
dns_base=$(echo $H_RUN_URL | cut -d/ -f3 | sed -e 's/api.//')
hub_fio="hub.${dns_base}"
function docker_login {
status "hub url is: $hub_fio"
status "Doing docker-login to ${hub_fio} with secret"
docker login ${hub_fio} --username=doesntmatter --password=$(cat /secrets/osftok) | indent
if [ -f /secrets/container-registries ] ; then
PYTHONPATH=$HERE/.. $HERE/login_registries /secrets/container-registries
fi
}
function require_params {
for x in $* ; do
eval val='$'$x
if [ -z $val ] ; then
echo Missing required parameter: \$$x
exit 1
fi
done
}
function load_extra_certs {
if [ -d /usr/local/share/ca-certificates ] ; then
status "Loading extra ca certificates"
update-ca-certificates
fi
}
function git_config {
git config user.email 2>/dev/null || git config --global user.email "gavin@foundries.io"
git config user.name 2>/dev/null || git config --global user.name "cibot"
# https://github.blog/2022-04-12-git-security-vulnerability-announced/
git config --system --add safe.directory /srv/oe/layers/meta-subscriber-overrides
git config --system --add safe.directory /srv/oe/.repo/manifests
git config --system --add safe.directory /repo
}
function start_ssh_agent {
keys=$(ls /secrets/ssh-*.key 2>/dev/null || true)
if [ -n "$keys" ] ; then
status Found ssh keys, starting an ssh-agent
mkdir -p $HOME/.ssh
eval `ssh-agent`
for x in $keys ; do
echo " Adding $x"
key=$HOME/.ssh/$(basename $x)
cp $x $key
chmod 700 $key
ssh-add $key
done
if [ -f /secrets/ssh-known_hosts ] ; then
status " Adding known hosts file"
ln -s /secrets/ssh-known_hosts $HOME/.ssh/known_hosts
fi
fi
}
function repo_sync {
status "Repo syncing sources..."
if [ -f /secrets/git.http.extraheader ] ; then
domain=$(echo $GIT_URL | cut -d/ -f3)
status "Adding git config extraheader for $domain/factories"
git config --global http.https://${domain}/factories.extraheader "$(cat /secrets/git.http.extraheader)"
fi
_repo_extra_args=""
for i in $(seq 4); do
if run repo init $_repo_extra_args --repo-rev=v2.35 --no-clone-bundle -u $* ${REPO_INIT_OVERRIDES}; then
break
fi
_repo_extra_args="--verbose"
status "repo init failed with error $?"
if [ $i -eq 4 ]; then
exit 1
fi
status "sleeping and trying again"
sleep $(($i*2))
done
_repo_extra_args=""
for i in $(seq 4); do
if run timeout 4m repo sync $_repo_extra_args; then
break
fi
_repo_extra_args="--verbose"
if [ $? -eq 124 ] ; then
msg="Command timed out"
if [ $i -ne 4 ] ; then
msg="${msg}, trying again"
else
status ${msg}
exit 1
fi
status ${msg}
sleep $(($i*2))
else
exit $?
fi
done
if [ -d "$archive" ] ; then
status "Generating pinned manifest"
repo manifest -r -o $archive/manifest.pinned.xml
cp .repo/manifest.xml $archive/manifest.xml
fi
}
function set_base_lmp_version {
# 1: Work on a copy
WORKCOPY="$PWD/.repo/manifests.git.tmp"
cp -R .repo/manifests.git $WORKCOPY
pushd $WORKCOPY >/dev/null
# 2: Replace all tags
git tag --delete $(git tag) >/dev/null
git remote set-url origin https://github.com/foundriesio/lmp-manifest
git fetch origin --tags --quiet
# 3: Find our base LMP version based on the HEAD
export LMP_VERSION=$(git describe --tags --abbrev=0 HEAD)
export LMP_VERSION_MINOR="$(git rev-list ${LMP_VERSION}..HEAD --count)"
export LMP_VERSION_CACHE="$(echo $LMP_VERSION | sed 's/\.[0-9]*$//')"
if [[ "${H_PROJECT}" == "lmp" ]] || [ -v LMP_VERSION_CACHE_DEV ] ; then
# Public LmP build - we are building for the *next* release
LMP_VERSION_CACHE=$(( $LMP_VERSION_CACHE + 1 ))
fi
status "Base LmP cache version detected as: $LMP_VERSION_CACHE"
# 4: cleanup
popd >/dev/null
rm -rf $WORKCOPY
}