Skip to content

Commit

Permalink
move installation of runtime out of the job
Browse files Browse the repository at this point in the history
  • Loading branch information
danielm-codefresh committed Jun 21, 2022
1 parent f67c35d commit ef6bae3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion csdp/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ configMapGenerator:
- name: codefresh-cm
behavior: create
literals:
- version=0.0.390
- version=0.0.391
4 changes: 2 additions & 2 deletions installer/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: csdp-installer
description: A Helm chart used for installing a CSDP runtime
type: application
version: 0.1.26
appVersion: v0.0.12
version: 0.1.27
appVersion: v0.0.13
65 changes: 34 additions & 31 deletions installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DEFAULT_GIT_SOURCE_NAME="default-git-source"

# Params:
check_required_param "namespace" "${NAMESPACE}"
check_required_param "csdp token" "${CSDP_TOKEN}"
check_required_param "csdp runtime token" "${CSDP_RUNTIME_TOKEN}"
check_required_param "runtime repo" "${CSDP_RUNTIME_REPO}"
check_required_param "git token" "${CSDP_RUNTIME_GIT_TOKEN}"
check_required_param "runtime cluster" "${CSDP_RUNTIME_CLUSTER}"
Expand Down Expand Up @@ -66,38 +66,41 @@ create_codefresh_secret() {
COMPONENTS=`echo $COMPONENTS | tr ' ' ','`
COMPONENTS="[${COMPONENTS}]"

RUNTIME_CREATE_ARGS="{
\"repo\": \"${CSDP_RUNTIME_REPO}\",
\"runtimeName\":\"${CSDP_RUNTIME_NAME}\",
\"cluster\":\"${CSDP_RUNTIME_CLUSTER}\",
\"ingressHost\":\"${CSDP_RUNTIME_INGRESS_URL}\",
\"ingressClass\":\"${CSDP_INGRESS_CLASS_NAME}\",
\"ingressController\":\"${CSDP_INGRESS_CONTROLLER}\",
\"componentNames\":${COMPONENTS},
\"runtimeVersion\":\"v0.0.0\",
\"managed\":${CSDP_MANAGED_RUNTIME}
}"

RUNTIME_CREATE_DATA="{\"operationName\":\"CreateRuntime\",\"variables\":{\"args\":$RUNTIME_CREATE_ARGS}"
RUNTIME_CREATE_DATA+=$',"query":"mutation CreateRuntime($args: RuntimeInstallationArgs\u0021) {\\n createRuntime(installationArgs: $args) {\\n name\\n newAccessToken\\n }\\n}\\n"}'
echo " --> Creating runtime with args:"
echo "$RUNTIME_CREATE_ARGS"

RUNTIME_CREATE_RESPONSE=`curl "${CSDP_URL}/2.0/api/graphql" \
-SsfL \
-H "Authorization: ${CSDP_TOKEN}" \
-H 'content-type: application/json' \
--compressed \
--insecure \
--data-raw "$RUNTIME_CREATE_DATA"`
if [ -z "$CSDP_RUNTIME_TOKEN" ] ; then
RUNTIME_CREATE_ARGS="{
\"repo\": \"${CSDP_RUNTIME_REPO}\",
\"runtimeName\":\"${CSDP_RUNTIME_NAME}\",
\"cluster\":\"${CSDP_RUNTIME_CLUSTER}\",
\"ingressHost\":\"${CSDP_RUNTIME_INGRESS_URL}\",
\"ingressClass\":\"${CSDP_INGRESS_CLASS_NAME}\",
\"ingressController\":\"${CSDP_INGRESS_CONTROLLER}\",
\"componentNames\":${COMPONENTS},
\"runtimeVersion\":\"v0.0.0\",
\"managed\":${CSDP_MANAGED_RUNTIME}
}"

RUNTIME_CREATE_DATA="{\"operationName\":\"CreateRuntime\",\"variables\":{\"args\":$RUNTIME_CREATE_ARGS}"
RUNTIME_CREATE_DATA+=$',"query":"mutation CreateRuntime($args: RuntimeInstallationArgs\u0021) {\\n createRuntime(installationArgs: $args) {\\n name\\n newAccessToken\\n }\\n}\\n"}'
echo " --> Creating runtime with args:"
echo "$RUNTIME_CREATE_ARGS"

RUNTIME_CREATE_RESPONSE=`curl "${CSDP_URL}/2.0/api/graphql" \
-SsfL \
-H "Authorization: ${CSDP_TOKEN}" \
-H 'content-type: application/json' \
--compressed \
--insecure \
--data-raw "$RUNTIME_CREATE_DATA"`

if `echo "$RUNTIME_CREATE_RESPONSE" | jq -e 'has("errors")'`; then
echo "Failed to create runtime"
echo ${RUNTIME_CREATE_RESPONSE}
exit 1
fi

if `echo "$RUNTIME_CREATE_RESPONSE" | jq -e 'has("errors")'`; then
echo "Failed to create runtime"
echo ${RUNTIME_CREATE_RESPONSE}
exit 1
CSDP_RUNTIME_TOKEN=`echo $RUNTIME_CREATE_RESPONSE | jq '.data.createRuntime.newAccessToken'`
fi

RUNTIME_ACCESS_TOKEN=`echo $RUNTIME_CREATE_RESPONSE | jq '.data.createRuntime.newAccessToken'`
RUNTIME_ENCRYPTION_IV=`hexdump -n 16 -e '4/4 "%08x" 1 "\n"' /dev/urandom`
echo " --> Runtime created!"
echo ""
Expand All @@ -110,7 +113,7 @@ create_codefresh_secret() {
name: $CODEFRESH_SECRET_NAME
namespace: $NAMESPACE
stringData:
token: $RUNTIME_ACCESS_TOKEN
token: $CSDP_RUNTIME_TOKEN
encryptionIV: $RUNTIME_ENCRYPTION_IV
" | kubectl apply -f -

Expand Down

0 comments on commit ef6bae3

Please sign in to comment.