forked from jfrog/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e-docker4mac.sh
executable file
·103 lines (80 loc) · 3.52 KB
/
e2e-docker4mac.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
#!/usr/bin/env bash
# Copyright 2018 The Helm Authors. All rights reserved.
#
# 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 -o errexit
set -o nounset
set -o pipefail
readonly IMAGE_TAG=${CHART_TESTING_TAG}
readonly IMAGE_REPOSITORY="quay.io/helmpack/chart-testing"
main() {
local testcontainer_id
testcontainer_id=$(create_testcontainer)
# shellcheck disable=SC2064
trap "docker container rm --force $testcontainer_id > /dev/null" EXIT
configure_kubectl "$testcontainer_id"
# --- Work around for Tillerless Helm, till Helm v3 gets released --- #
run_tillerless
# ---------- #
run_test
}
lookup_apiserver_container_id() {
docker container list --filter name=k8s_kube-apiserver --format '{{ .ID }}'
}
get_apiserver_arg() {
local container_id="$1"
local arg="$2"
docker container inspect "$container_id" | jq -r ".[].Args[] | capture(\"$arg=(?<arg>.*)\") | .arg"
}
create_testcontainer() {
docker container run --interactive --tty --detach \
--volume "$(pwd):/workdir" --workdir /workdir \
"$IMAGE_REPOSITORY:$IMAGE_TAG" cat
}
configure_kubectl() {
local testcontainer_id="$1"
local apiserver_id
apiserver_id=$(lookup_apiserver_container_id)
if [[ -z "$apiserver_id" ]]; then
echo "ERROR: API-Server container not found. Make sure 'Show system containers' is enabled in Docker4Mac 'Preferences'!" >&2
exit 1
fi
local ip
ip=$(get_apiserver_arg "$apiserver_id" --advertise-address)
local port
port=$(get_apiserver_arg "$apiserver_id" --secure-port)
docker cp "$HOME/.kube" "$testcontainer_id:/root/.kube"
docker exec "$testcontainer_id" kubectl config set-cluster docker-desktop "--server=https://$ip:$port"
docker exec "$testcontainer_id" kubectl config set-cluster docker-desktop --insecure-skip-tls-verify=true
docker exec "$testcontainer_id" kubectl config use-context docker-desktop
}
run_tillerless() {
# -- Work around for Tillerless Helm, till Helm v3 gets released -- #
docker exec "$testcontainer_id" apk add bash
docker exec "$testcontainer_id" helm init --client-only
docker exec "$testcontainer_id" helm plugin install https://github.com/rimusz/helm-tiller
docker exec "$testcontainer_id" bash -c 'echo "Starting Tiller..."; helm tiller start-ci >/dev/null 2>&1 &'
docker exec "$testcontainer_id" bash -c 'echo "Waiting Tiller to launch on 44134..."; while ! nc -z localhost 44134; do sleep 1; done; echo "Tiller launched..."'
echo
}
run_test() {
git remote add k8s "${CHARTS_REPO}" &> /dev/null || true
git fetch k8s
# --- Work around for Tillerless Helm, till Helm v3 gets released --- #
# shellcheck disable=SC2086
docker exec -e HELM_HOST=127.0.0.1:44134 -e HELM_TILLER_SILENT=true "$testcontainer_id" ct install ${CHART_TESTING_ARGS} --config /workdir/test/ct.yaml
# ------------------------------------------------------------------- #
##### docker exec "$testcontainer_id" ct install ${CHART_TESTING_ARGS} --config /workdir/test/ct.yaml
echo "Done Testing!"
}
main