Browse Source

Merge "Create Makefile target to install Helm binary"

Zuul 5 months ago
parent
commit
9a92abe1d7
3 changed files with 106 additions and 36 deletions
  1. 11
    9
      Makefile
  2. 43
    0
      tools/helm_install.sh
  3. 52
    27
      tools/helm_tk.sh

+ 11
- 9
Makefile View File

@@ -13,11 +13,12 @@
13 13
 # limitations under the License.
14 14
 
15 15
 # APP INFO
16
+BUILD_DIR         := $(shell mktemp -d)
16 17
 DOCKER_REGISTRY   ?= quay.io
17 18
 IMAGE_PREFIX      ?= airshipit
18 19
 IMAGE_NAME        ?= armada
19 20
 IMAGE_TAG         ?= latest
20
-HELM              ?= helm
21
+HELM              ?= $(BUILD_DIR)/helm
21 22
 PROXY             ?= http://proxy.foo.com:8000
22 23
 NO_PROXY          ?= localhost,127.0.0.1,.svc.cluster.local
23 24
 USE_PROXY         ?= false
@@ -36,6 +37,8 @@ GIT_SHA    = $(shell git rev-parse --short HEAD)
36 37
 GIT_TAG    = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
37 38
 GIT_DIRTY  = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
38 39
 
40
+HELM_PIDFILE ?= $(abspath ./.helm-pid)
41
+
39 42
 ifdef VERSION
40 43
 	DOCKER_VERSION = $(VERSION)
41 44
 endif
@@ -82,12 +85,6 @@ check-tox:
82 85
 .PHONY: images
83 86
 images: check-docker build_armada
84 87
 
85
-.PHONY: dry-run
86
-dry-run: clean
87
-	tools/helm_tk.sh $(HELM)
88
-	$(HELM) dep up charts/$(CHART)
89
-	$(HELM) template charts/$(CHART)
90
-
91 88
 .PHONY: docs
92 89
 docs: clean build_docs
93 90
 
@@ -187,7 +184,7 @@ helm-init-%: helm-serve
187 184
 	cd charts;if [ -s $*/requirements.yaml ]; then echo "Initializing $*";$(HELM) dep up $*; fi
188 185
 
189 186
 .PHONY: helm-serve
190
-helm-serve:
187
+helm-serve: helm-install
191 188
 	./tools/helm_tk.sh $(HELM) $(HELM_PIDFILE)
192 189
 
193 190
 .PHONY: helm-lint
@@ -199,7 +196,7 @@ helm-lint-%: helm-init-%
199 196
 	cd charts;$(HELM) lint $*
200 197
 
201 198
 .PHONY: dry-run
202
-dry-run: $(addprefix dry-run-,$(CHARTS))
199
+dry-run: clean $(addprefix dry-run-,$(CHARTS))
203 200
 
204 201
 .PHONY: dry-run-%
205 202
 dry-run-%: helm-lint-%
@@ -209,3 +206,8 @@ dry-run-%: helm-lint-%
209 206
 .PHONY: $(CHARTS)
210 207
 $(CHARTS): $(addprefix dry-run-,$(CHARTS)) chartbanner
211 208
 	$(HELM) package -d charts charts/$@
209
+
210
+# Install helm binary
211
+.PHONY: helm-install
212
+helm-install:
213
+	./tools/helm_install.sh $(HELM)

+ 43
- 0
tools/helm_install.sh View File

@@ -0,0 +1,43 @@
1
+#!/bin/bash
2
+# Copyright 2018 AT&T Intellectual Property.  All other rights reserved.
3
+#
4
+# Licensed under the Apache License, Version 2.0 (the "License");
5
+# you may not use this file except in compliance with the License.
6
+# You may obtain a copy of the License at
7
+#
8
+#     http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS,
12
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+# See the License for the specific language governing permissions and
14
+# limitations under the License.
15
+#
16
+
17
+set -x
18
+
19
+HELM=$1
20
+HELM_ARTIFACT_URL=${HELM_ARTIFACT_URL:-"https://storage.googleapis.com/kubernetes-helm/helm-v2.10.0-linux-amd64.tar.gz"}
21
+
22
+
23
+function install_helm_binary {
24
+  if [[ -z "${HELM}" ]]
25
+  then
26
+    echo "No Helm binary target location."
27
+    exit -1
28
+  fi
29
+
30
+  if [[ -w "$(dirname ${HELM})" ]]
31
+  then
32
+    TMP_DIR=${BUILD_DIR:-$(mktemp -d)}
33
+    curl -o "${TMP_DIR}/helm.tar.gz" "${HELM_ARTIFACT_URL}"
34
+    cd ${TMP_DIR}
35
+    tar -xvzf helm.tar.gz
36
+    cp "${TMP_DIR}/linux-amd64/helm" "${HELM}"
37
+  else
38
+    echo "Cannot write to ${HELM}"
39
+    exit -1
40
+  fi
41
+}
42
+
43
+install_helm_binary

+ 52
- 27
tools/helm_tk.sh View File

@@ -15,37 +15,62 @@
15 15
 #
16 16
 # Script to setup helm-toolkit and helm dep up the armada chart
17 17
 #
18
-HELM=$1
19 18
 
20
-set -x
19
+set -eux
21 20
 
22
-function helm_serve {
23
-    if [[ -d "$HOME/.helm" ]]; then
24
-        echo ".helm directory found"
25
-    else
26
-        ${HELM} init --client-only
27
-    fi
28
-    if [[ -z $(curl -s 127.0.0.1:8879 | grep 'Helm Repository') ]]; then
29
-        ${HELM} serve & > /dev/null
30
-        while [[ -z $(curl -s 127.0.0.1:8879 | grep 'Helm Repository') ]]; do
31
-            sleep 1
32
-            echo "Waiting for Helm Repository"
33
-        done
34
-    else
35
-        echo "Helm serve already running"
36
-    fi
21
+HELM=${1}
22
+HELM_PIDFILE=${2}
23
+SERVE_DIR=$(mktemp -d)
37 24
 
38
-    if ${HELM} repo list | grep -q "^stable" ; then
39
-        ${HELM} repo remove stable
25
+${HELM} init --client-only
26
+
27
+if [[ -s ${HELM_PIDFILE} ]]; then
28
+    HELM_PID=$(cat "${HELM_PIDFILE}")
29
+    if ps "${HELM_PID}"; then
30
+        kill "${HELM_PID}"
31
+        sleep 0.5
32
+        if ps "${HELM_PID}"; then
33
+            echo Failed to terminate Helm, PID = "${HELM_PID}"
34
+            exit 1
35
+        fi
40 36
     fi
37
+fi
38
+
39
+${HELM} serve & > /dev/null
40
+HELM_PID=${!}
41
+echo Started Helm, PID = "${HELM_PID}"
42
+echo "${HELM_PID}" > "${HELM_PIDFILE}"
43
+
44
+set +x
45
+if [[ -z $(curl -s 127.0.0.1:8879 | grep 'Helm Repository') ]]; then
46
+    while [[ -z $(curl -s 127.0.0.1:8879 | grep 'Helm Repository') ]]; do
47
+       sleep 1
48
+       echo "Waiting for Helm Repository"
49
+    done
50
+else
51
+    echo "Helm serve already running"
52
+fi
53
+set -x
54
+
55
+if ${HELM} repo list | grep -q "^stable" ; then
56
+    ${HELM} repo remove stable
57
+fi
58
+
59
+${HELM} repo add local http://localhost:8879/charts
60
+
61
+
62
+#OSH Makefile is bugged, so ensure helm is in the path
63
+if [[ ${HELM} != "helm" ]]
64
+then
65
+  export PATH=${PATH}:$(dirname ${HELM})
66
+fi
67
+
68
+{
69
+    cd "${SERVE_DIR}"
70
+    git clone --depth 1 https://git.openstack.org/openstack/openstack-helm-infra.git || true
71
+    cd openstack-helm-infra
41 72
 
42
-    ${HELM} repo add local http://localhost:8879/charts
73
+    make helm-toolkit
43 74
 }
44 75
 
45
-mkdir -p build
46
-cd build
47
-git clone --depth 1 https://git.openstack.org/openstack/openstack-helm-infra.git || true
48
-cd openstack-helm-infra
49
-git pull
50
-helm_serve
51
-make charts
76
+rm -rf "${SERVE_DIR}"

Loading…
Cancel
Save