-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·52 lines (38 loc) · 1.05 KB
/
build.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
#!/bin/bash
set -eo pipefail
configure_git_privkey() {
privatekey=$1
git config --global core.sshCommand \
"ssh -i $privatekey -o StrictHostKeyChecking=no"
}
configure_docker_credentials() {
cp "$PUSH_DOCKERCFG_PATH"/.dockercfg "$HOME"/.dockercfg
}
fast_checkout() {
repository=$1
ref=$2
git init
git remote add origin "$repository"
[ -n "$ref" ] && fetch=$ref || fetch=HEAD
git fetch --depth 30 --tags origin $fetch
git checkout FETCH_HEAD
}
get_git_ref() {
commit=$(echo "$BUILD" | jq -r '.spec.revision.git.commit |
select (. != null)')
if [ -n "$commit" ]; then
echo "$commit"
else
echo "$SOURCE_REF"
fi
}
cd "$(mktemp -d)" || exit 1
git_ref=$(get_git_ref)
configure_git_privkey "$SOURCE_SECRET_PATH"/ssh-privatekey
fast_checkout "$SOURCE_REPOSITORY" "$git_ref"
configure_docker_credentials
COMMIT=$(git rev-parse HEAD)
OUTPUT_REPOSITORY=$(echo "$OUTPUT_IMAGE" | cut -d: -f1)
export COMMIT
export OUTPUT_REPOSITORY
bash -c "$BUILD_COMMAND"