deploy.sh 7.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# 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 -euo pipefail
19
20
21
22
23
24
25
26
27
28
29
trap 'echo "Error at line $LINENO. Exiting."' ERR

required_tools=(envsubst kubectl helm)

for tool in "${required_tools[@]}"; do
  if ! command -v "$tool" >/dev/null 2>&1; then
    echo "Error: Required tool '$tool' is not installed or not in PATH."
    exit 1
  fi
done

30

31
32
33
# Use system helm
HELM_CMD=$(which helm)

34
# Set default values only if not already set
35
36
export NAMESPACE="${NAMESPACE:=dynamo-cloud}"  # Default namespace
export RELEASE_NAME="${RELEASE_NAME:=${NAMESPACE}}"  # Default release name is same as namespace
37
38
export DOCKER_USERNAME="${DOCKER_USERNAME:-}"  # Default docker username is empty
export DOCKER_PASSWORD="${DOCKER_PASSWORD:-}"  # Default docker password is empty
39
export DOCKER_SERVER="${DOCKER_SERVER:=<your-docker-server>}"  # Default docker server
40
41
42
export PIPELINES_DOCKER_SERVER="${PIPELINES_DOCKER_SERVER:=${DOCKER_SERVER}}"
export PIPELINES_DOCKER_USERNAME="${PIPELINES_DOCKER_USERNAME:=${DOCKER_USERNAME}}"
export PIPELINES_DOCKER_PASSWORD="${PIPELINES_DOCKER_PASSWORD:=${DOCKER_PASSWORD}}"
43
44
export IMAGE_TAG="${IMAGE_TAG:=latest}"  # Default image tag
export DYNAMO_INGRESS_SUFFIX="${DYNAMO_INGRESS_SUFFIX:=dynamo-cloud.com}"
45
export DOCKER_SECRET_NAME="${DOCKER_SECRET_NAME:=docker-imagepullsecret}"
46
47
48
49
export INGRESS_ENABLED="${INGRESS_ENABLED:=false}"
export ISTIO_ENABLED="${ISTIO_ENABLED:=false}"
export ISTIO_GATEWAY="${ISTIO_GATEWAY:=istio-system/istio-ingressgateway}"
export INGRESS_CLASS="${INGRESS_CLASS:=nginx}"
50
export VIRTUAL_SERVICE_SUPPORTS_HTTPS="${VIRTUAL_SERVICE_SUPPORTS_HTTPS:=false}"
51
export ENABLE_LWS="${ENABLE_LWS:=false}"
52
53
54

# Add command line options
INTERACTIVE=false
55
INSTALL_CRDS=false
56
YAML_ONLY=false
57
58
59
60
61
62
63
64
# Parse command line arguments
while [[ $# -gt 0 ]]; do
  key="$1"
  case $key in
    --interactive)
      INTERACTIVE=true
      shift
      ;;
65
66
67
68
    --crds)
      INSTALL_CRDS=true
      shift
      ;;
69
70
71
72
    --yaml-only)
      YAML_ONLY=true
      shift
      ;;
73
74
75
76
    --help)
      echo "Usage: $0 [options]"
      echo "Options:"
      echo "  --interactive       Run in interactive mode"
77
      echo "  --yaml-only         Only generate generated-values.yaml and exit"
78
      echo "  --help              Show this help message"
79
      echo "  --crds              Also install the CRDs"
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
      exit 0
      ;;
    *)
      echo "Unknown option: $1"
      echo "Use --help for usage information."
      exit 1
      ;;
  esac
done

if [ "$INTERACTIVE" = true ]; then
  source network-config-wizard.sh
fi


95
# Check if required variables are set
96
97
if [ "$DOCKER_SERVER" = "<your-docker-server>" ]; then
    echo "Error: Please set your DOCKER_SERVER in the script or via environment variable"
98
99
100
    exit 1
fi

101
102
103
104
# Creates a docker registry secret. Only proceed if both username and password are set
if [[ -n "${DOCKER_USERNAME:-}" && -n "${DOCKER_PASSWORD:-}" ]]; then
  echo "Creating/updating Docker registry secret '$DOCKER_SECRET_NAME' in namespace '$NAMESPACE'..."

105
106
107
108
109
110
  # Transform docker.io URLs to index.docker.io/v1/
  DOCKER_SERVER_FOR_SECRET="$DOCKER_SERVER"
  if [[ "$DOCKER_SERVER" == "docker.io" || "$DOCKER_SERVER" == "docker.io/"* ]]; then
    DOCKER_SERVER_FOR_SECRET="https://index.docker.io/v1/"
  fi

111
112
113
  kubectl create secret docker-registry "$DOCKER_SECRET_NAME" \
    --docker-username="$DOCKER_USERNAME" \
    --docker-password="$DOCKER_PASSWORD" \
114
    --docker-server="$DOCKER_SERVER_FOR_SECRET" \
115
116
117
118
    --namespace "$NAMESPACE" \
    --dry-run=client -o yaml | kubectl apply -f -
else
  echo "DOCKER_USERNAME and/or DOCKER_PASSWORD not set — skipping docker secret creation."
119
120
fi

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

# Function to retry commands
retry_command() {
    local -r cmd="$1"
    local -r max_attempts=${2:-3}
    local -r delay=${3:-5}
    local attempt=1

    until eval "$cmd"; do
        if ((attempt >= max_attempts)); then
            echo "Command '$cmd' failed after $attempt attempts"
            return 1
        fi
        echo "Command '$cmd' failed, attempt $attempt of $max_attempts. Retrying in ${delay}s..."
        ((attempt++))
        sleep "$delay"
    done
}

140
# Update the helm repo and build the dependencies
141
142
143
retry_command "$HELM_CMD repo add nats https://nats-io.github.io/k8s/helm/charts/" 5 5 && \
retry_command "$HELM_CMD repo update" 5 5

144
145
146
147
148

# Generate the values file
echo "Generating values file with:"
echo "NAMESPACE: $NAMESPACE"
echo "RELEASE_NAME: $RELEASE_NAME"
149
150
151
152
echo "IMAGE_TAG: $IMAGE_TAG"
echo "DOCKER_USERNAME: $DOCKER_USERNAME"
echo "DOCKER_SERVER: $DOCKER_SERVER"
echo "DOCKER_PASSWORD: [HIDDEN]"
153
154
155
156
echo "PIPELINES_DOCKER_SERVER: $PIPELINES_DOCKER_SERVER"
echo "PIPELINES_DOCKER_USERNAME: $PIPELINES_DOCKER_USERNAME"
echo "PIPELINES_DOCKER_PASSWORD: [HIDDEN]"
echo "DOCKER_SECRET_NAME: $DOCKER_SECRET_NAME"
157
158
159
160
161
echo "INGRESS_ENABLED: $INGRESS_ENABLED"
echo "ISTIO_ENABLED: $ISTIO_ENABLED"
echo "INGRESS_CLASS: $INGRESS_CLASS"
echo "ISTIO_GATEWAY: $ISTIO_GATEWAY"
echo "DYNAMO_INGRESS_SUFFIX: $DYNAMO_INGRESS_SUFFIX"
162
echo "VIRTUAL_SERVICE_SUPPORTS_HTTPS: $VIRTUAL_SERVICE_SUPPORTS_HTTPS"
163
echo "INSTALL_CRDS: $INSTALL_CRDS"
164

165
envsubst '${NAMESPACE} ${RELEASE_NAME} ${DOCKER_USERNAME} ${DOCKER_PASSWORD} ${DOCKER_SERVER} ${IMAGE_TAG} ${DYNAMO_INGRESS_SUFFIX} ${PIPELINES_DOCKER_SERVER} ${PIPELINES_DOCKER_USERNAME} ${PIPELINES_DOCKER_PASSWORD} ${DOCKER_SECRET_NAME} ${INGRESS_ENABLED} ${ISTIO_ENABLED} ${INGRESS_CLASS} ${ISTIO_GATEWAY} ${VIRTUAL_SERVICE_SUPPORTS_HTTPS} ${ENABLE_LWS}' < dynamo-platform-values.yaml > generated-values.yaml
166
echo "generated file contents:"
167
cat generated-values.yaml
168

169
echo ""
170
echo "Generated values file saved as generated-values.yaml"
171
172
173
174
if [ "$YAML_ONLY" = true ]; then
  echo "--yaml-only flag detected; skipping Helm deployment steps."
  exit 0
fi
175

176
# Build dependencies before installation
177
178
179
180
echo "Building helm dependencies..."
cd platform
retry_command "$HELM_CMD dep build" 5 5
cd ..
181

182
183
184
185
186
187
# Install/upgrade the helm chart for the CRDs
if [ "$INSTALL_CRDS" = true ]; then
  echo "Installing/upgrading helm chart for the CRDs..."
  $HELM_CMD upgrade --install dynamo-crds crds/ --namespace default --wait --atomic
fi

188
189
190
191
192
193
# Build Platform
echo "Building platform..."
$HELM_CMD dep build ./platform/

# Install platform
echo "Installing platform..."
194
helm upgrade --install dynamo-platform ./platform/ \
195
196
197
198
199
  --namespace ${NAMESPACE} \
  --set "dynamo-operator.controllerManager.manager.image.repository=${DOCKER_SERVER}/dynamo-operator" \
  --set "dynamo-operator.controllerManager.manager.image.tag=${IMAGE_TAG}" \
  --set "dynamo-operator.imagePullSecrets[0].name=docker-imagepullsecret" \
  --set controller.env.DYNAMO_CLOUD=${DYNAMO_CLOUD}
200
echo "Helm chart deployment complete"