2023-01-26 08:35:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
# Params are in environment variables as PARAM_{SLUG}, e.g. PARAM_USER_ID
|
|
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
set -euo pipefail
|
2024-07-01 09:36:56 +00:00
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
edition="ce"
|
2023-01-26 08:35:11 +00:00
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
# Configure AWS CLI and kubectl environment
|
|
|
|
|
mkdir -p ~/.aws
|
|
|
|
|
cat > ~/.aws/config <<EOF
|
|
|
|
|
[default]
|
|
|
|
|
region = ap-south-1
|
|
|
|
|
output = json
|
|
|
|
|
EOF
|
2023-01-26 08:35:11 +00:00
|
|
|
|
2024-07-01 09:36:56 +00:00
|
|
|
aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID"
|
|
|
|
|
aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
|
2023-09-11 10:54:17 +00:00
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
export region="ap-south-1"
|
|
|
|
|
export cluster_name="uatx-cluster"
|
2023-01-26 08:35:11 +00:00
|
|
|
|
|
|
|
|
echo "Region: $region"
|
|
|
|
|
echo "Cluster name: $cluster_name"
|
|
|
|
|
echo "Pull Request Number: $PULL_REQUEST_NUMBER"
|
2023-08-03 15:27:47 +00:00
|
|
|
echo "DP_EFS_ID: $DP_EFS_ID"
|
2023-01-26 08:35:11 +00:00
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
# Set naming context
|
2024-07-01 09:36:56 +00:00
|
|
|
export NAMESPACE="$edition$PULL_REQUEST_NUMBER"
|
|
|
|
|
export CHARTNAME="$edition$PULL_REQUEST_NUMBER"
|
|
|
|
|
export SECRET="$edition$PULL_REQUEST_NUMBER"
|
|
|
|
|
export DBNAME="$edition$PULL_REQUEST_NUMBER"
|
|
|
|
|
export DOMAINNAME="$edition-$PULL_REQUEST_NUMBER.dp.appsmith.com"
|
2023-08-03 14:53:22 +00:00
|
|
|
export HELMCHART="appsmith"
|
2023-09-11 10:54:17 +00:00
|
|
|
export HELMCHART_URL="http://helm-ee.appsmith.com"
|
2025-06-25 13:38:25 +00:00
|
|
|
|
|
|
|
|
# Optional environment variables (already set externally)
|
2025-01-30 11:12:59 +00:00
|
|
|
export OPENAI_ASSISTANT_ID="$OPENAI_ASSISTANT_ID"
|
|
|
|
|
export OPENAI_API_KEY="$OPENAI_API_KEY"
|
|
|
|
|
export APPSMITH_CARBON_API_KEY="$APPSMITH_CARBON_API_KEY"
|
|
|
|
|
export APPSMITH_CARBON_API_BASE_PATH="$APPSMITH_CARBON_API_BASE_PATH"
|
|
|
|
|
export APPSMITH_AI_SERVER_MANAGED_HOSTING="$APPSMITH_AI_SERVER_MANAGED_HOSTING"
|
|
|
|
|
export IN_DOCKER="$IN_DOCKER"
|
2023-09-11 10:54:17 +00:00
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
# Update kubeconfig
|
2025-06-25 11:52:25 +00:00
|
|
|
aws eks update-kubeconfig --region "$region" --name "$cluster_name"
|
2023-01-26 08:35:11 +00:00
|
|
|
|
|
|
|
|
kubectl config set-context --current --namespace=default
|
|
|
|
|
kubectl get pods
|
|
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
# Optional cleanup logic
|
|
|
|
|
if [[ -n "${RECREATE-}" ]]; then
|
2025-10-03 12:49:47 +00:00
|
|
|
echo "Wiping the DP from MongoDB and Kubernetes since the reset flag was set"
|
2025-06-25 13:38:25 +00:00
|
|
|
pod_name="$(kubectl get pods -n "$NAMESPACE" -o json | jq -r '.items[0].metadata.name')"
|
2025-10-03 12:49:47 +00:00
|
|
|
# execute this db.dropDatabase() from the k8s cluster because there's network restrictions on Atlas cluster.
|
|
|
|
|
# The \$ is used to escape the $ character in the APPSMITH_DB_URL environment variable so it's interpolated inside the kubectl exec command.
|
|
|
|
|
kubectl exec "$pod_name" -n "$NAMESPACE" -- bash -c "mongosh \$APPSMITH_DB_URL --eval 'db.dropDatabase()'"
|
2024-07-01 09:36:56 +00:00
|
|
|
kubectl exec "$pod_name" -n "$NAMESPACE" -- bash -c "rm -rf /appsmith-stacks/*"
|
|
|
|
|
kubectl delete ns "$NAMESPACE" || true
|
|
|
|
|
kubectl patch pv "$NAMESPACE-appsmith" -p '{"metadata":{"finalizers":null}}' || true
|
|
|
|
|
kubectl delete pv "$NAMESPACE-appsmith" --grace-period=0 --force || true
|
2025-10-03 12:49:47 +00:00
|
|
|
echo "DP wiped from MongoDB and Kubernetes"
|
2023-08-03 18:10:06 +00:00
|
|
|
fi
|
|
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
# Create namespace and image pull secret
|
2024-07-01 09:36:56 +00:00
|
|
|
kubectl create ns "$NAMESPACE" || true
|
2023-04-14 10:57:17 +00:00
|
|
|
|
2024-07-01 09:36:56 +00:00
|
|
|
kubectl create secret docker-registry "$SECRET" \
|
2023-01-26 08:35:11 +00:00
|
|
|
--docker-server=https://index.docker.io/v1/ \
|
2024-07-01 09:36:56 +00:00
|
|
|
--docker-username="$DOCKER_HUB_USERNAME" \
|
2025-06-25 13:38:25 +00:00
|
|
|
--docker-password="$DOCKER_HUB_ACCESS_TOKEN" \
|
|
|
|
|
-n "$NAMESPACE" || true
|
2023-01-26 08:35:11 +00:00
|
|
|
|
2025-06-25 13:52:07 +00:00
|
|
|
# Add Helm repo (idempotent)
|
|
|
|
|
AWS_REGION=us-east-2 helm repo add appsmith-ee "$HELMCHART_URL" || echo "Helm repo already added."
|
2024-07-01 09:36:56 +00:00
|
|
|
helm repo update
|
2025-06-25 13:52:07 +00:00
|
|
|
|
|
|
|
|
# Attempt to install the plugin only if it's not installed
|
|
|
|
|
if ! helm plugin list | grep -q mapkubeapis; then
|
|
|
|
|
echo "Installing mapkubeapis plugin..."
|
|
|
|
|
helm plugin install https://github.com/helm/helm-mapkubeapis || echo "Plugin installation failed, continuing..."
|
|
|
|
|
else
|
|
|
|
|
echo "mapkubeapis plugin already installed."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Run mapkubeapis (safe to fail)
|
|
|
|
|
echo "Running helm mapkubeapis (optional)..."
|
|
|
|
|
helm mapkubeapis "$CHARTNAME" -n "$NAMESPACE" || echo "mapkubeapis failed, continuing..."
|
|
|
|
|
|
|
|
|
|
# Show chart metadata
|
|
|
|
|
helm show chart appsmith-ee/$HELMCHART || echo "helm show chart failed (non-blocking)."
|
2023-01-26 08:35:11 +00:00
|
|
|
|
2025-06-25 13:38:25 +00:00
|
|
|
echo "Deploying Appsmith Helm chart..."
|
2024-07-01 09:36:56 +00:00
|
|
|
helm upgrade -i "$CHARTNAME" "appsmith-ee/$HELMCHART" -n "$NAMESPACE" --create-namespace --recreate-pods \
|
2025-06-25 13:38:25 +00:00
|
|
|
--set _image.repository="$DOCKER_HUB_ORGANIZATION/appsmith-dp" \
|
|
|
|
|
--set _image.tag="$IMAGE_HASH" \
|
2023-09-11 10:54:17 +00:00
|
|
|
--set _image.pullPolicy="Always" \
|
2025-06-25 13:38:25 +00:00
|
|
|
--set image.pullSecrets="$SECRET" \
|
|
|
|
|
--set autoscaling.enabled=true \
|
|
|
|
|
--set autoscaling.minReplicas=1 \
|
|
|
|
|
--set autoscaling.maxReplicas=1 \
|
|
|
|
|
--set redis.enabled=false \
|
|
|
|
|
--set postgresql.enabled=false \
|
|
|
|
|
--set mongodb.enabled=false \
|
|
|
|
|
--set ingress.enabled=true \
|
2023-01-26 08:35:11 +00:00
|
|
|
--set "ingress.annotations.service\.beta\.kubernetes\.io/aws-load-balancer-ssl-cert=$AWS_RELEASE_CERT" \
|
|
|
|
|
--set "ingress.hosts[0].host=$DOMAINNAME, ingress.hosts[0].paths[0].path=/, ingress.hosts[0].paths[0].pathType=Prefix" \
|
2025-06-25 13:38:25 +00:00
|
|
|
--set autoupdate.enabled=false \
|
|
|
|
|
--set ingress.className="nginx" \
|
|
|
|
|
--set persistence.efs.enabled=true \
|
|
|
|
|
--set persistence.efs.driver="efs.csi.aws.com" \
|
|
|
|
|
--set persistence.storageClass="efs-sc" \
|
2024-07-01 09:36:56 +00:00
|
|
|
--set persistence.efs.volumeHandle="$DP_EFS_ID:/$edition/$edition$PULL_REQUEST_NUMBER" \
|
2023-09-20 08:08:09 +00:00
|
|
|
--set resources.requests.cpu="1m" \
|
2025-06-25 13:38:25 +00:00
|
|
|
--set resources.requests.memory="3072Mi" \
|
2024-12-31 12:31:48 +00:00
|
|
|
--set podDisruptionBudgets.enabled=false \
|
2023-04-14 05:17:45 +00:00
|
|
|
--set applicationConfig.APPSMITH_SENTRY_DSN="https://abf15a075d1347969df44c746cca7eaa@o296332.ingest.sentry.io/1546547" \
|
|
|
|
|
--set applicationConfig.APPSMITH_SENTRY_ENVIRONMENT="$NAMESPACE" \
|
2024-07-01 16:06:43 +00:00
|
|
|
--set applicationConfig.APPSMITH_DB_URL="mongodb+srv://$DB_USERNAME:$DB_PASSWORD@$DB_URL/$DBNAME?retryWrites=true&minPoolSize=1&maxPoolSize=10&maxIdleTimeMS=900000&authSource=admin" \
|
2025-01-30 11:26:11 +00:00
|
|
|
--set applicationConfig.OPENAI_ASSISTANT_ID="$OPENAI_ASSISTANT_ID" \
|
|
|
|
|
--set applicationConfig.OPENAI_API_KEY="$OPENAI_API_KEY" \
|
2025-01-30 11:12:59 +00:00
|
|
|
--set applicationConfig.APPSMITH_CARBON_API_KEY="$APPSMITH_CARBON_API_KEY" \
|
|
|
|
|
--set applicationConfig.APPSMITH_CARBON_API_BASE_PATH="$APPSMITH_CARBON_API_BASE_PATH" \
|
|
|
|
|
--set applicationConfig.APPSMITH_AI_SERVER_MANAGED_HOSTING="$APPSMITH_AI_SERVER_MANAGED_HOSTING" \
|
2025-06-25 13:13:49 +00:00
|
|
|
--set applicationConfig.IN_DOCKER="$IN_DOCKER" \
|
2025-06-25 12:51:38 +00:00
|
|
|
--set applicationConfig.APPSMITH_CUSTOMER_PORTAL_URL="https://release-customer.appsmith.com" \
|
2025-06-25 13:38:25 +00:00
|
|
|
--set affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key=instance_name \
|
|
|
|
|
--set affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].operator=In \
|
|
|
|
|
--set affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].values[0]=uatx-shared \
|
|
|
|
|
--set tolerations[0].key=instance_name \
|
|
|
|
|
--set tolerations[0].operator=Equal \
|
|
|
|
|
--set tolerations[0].value=uatx-shared \
|
|
|
|
|
--set tolerations[0].effect=NoSchedule
|