/
deploy-onebox.sh
111 lines (90 loc) · 2.54 KB
/
deploy-onebox.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
#!/usr/bin/env bash
# Licensed under the MIT license. See LICENSE file on the project webpage for details.
set -e
# Determine the appropriate github branch to clone
get_branch()
{
local branchInfo=
if [[ -n $CIRCLE_BRANCH ]] ; then
branchInfo=$CIRCLE_BRANCH
elif [[ -n $TRAVIS_BRANCH ]] ; then
branchInfo=$TRAVIS_BRANCH
elif [[ -n $TRAVIS_PULL_REQUEST_BRANCH ]] ; then
branchInfo=$TRAVIS_PULL_REQUEST_BRANCH
else
branchInfo=$(get_current_branch)
# Ensure branch information is useful.
if ! is_valid_branch $branchInfo ; then
log "Unable to determine branch for testing"
exit 1
fi
fi
echo "$branchInfo"
}
get_repo()
{
local protocol="https://"
local repoInfo=
if [[ -n $CIRCLE_PROJECT_USERNAME ]] && [[ -n $CIRCLE_PROJECT_REPONAME ]] ; then
repoInfo=$(get_github_url $CIRCLE_PROJECT_USERNAME $CIRCLE_PROJECT_REPONAME)
else
if [[ -n $CIRCLE_REPOSITORY_URL ]] ; then
repoInfo="${protocol}${CIRCLE_REPOSITORY_URL}"
else
repoInfo=$(git config --get remote.origin.url)
fi
# Convert ssh repo into https
if echo $repoInfo | grep "@.*:.*/" > /dev/null 2>&1 ; then
repoInfo=$(echo $repoInfo | tr : / | sed "s#git@#${protocol}#g")
fi
fi
echo "$repoInfo"
}
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_SCRIPT_DIR/../templates/stamp/utilities.sh
BRANCH=$(get_branch)
set -o pipefail
REPO=$(get_repo)
FOLDER=$(basename $REPO .git)
CONTAINER_NAME=$(echo "$ONEBOX_PARAMS" | tr -d "-" | tr -d " ")
log "BRANCH=$BRANCH, REPO=$REPO, FOLDER=$FOLDER"
log "ONEBOX_PARAMS=$ONEBOX_PARAMS"
log "CONTAINER_NAME=$CONTAINER_NAME"
log
# keep alive
bash ./tests/keep-alive.sh &
# Connect to container
docker exec -i $CONTAINER_NAME /bin/bash -s <<EOF
# test systemd
if systemctl > /dev/null ; then
echo "success: has systemd"
else
echo "FAILURE: no systemd"
exit 1
fi
# install git
apt update -qq
if apt install git -y -qq ; then
echo "success: apt install git"
else
echo "FAILURE: can't apt install git"
exit 1
fi
# clone repo
mkdir /oxa
pushd /oxa
if git clone --quiet --depth=50 --branch=$BRANCH ${REPO} ; then
echo "success: clone repo inside of container"
else
echo "FAILURE: can't clone repo inside of container"
exit 1
fi
pushd $FOLDER
# run custom tests
if bash onebox.sh $ONEBOX_PARAMS ; then
echo "success: onebox deployed"
else
echo "FAILURE: onebox wasn't deployed"
exit 1
fi
EOF