diff --git a/.github/workflows/cleanup-dp.yml b/.github/workflows/cleanup-dp.yml index b572786cbe..e105c83789 100644 --- a/.github/workflows/cleanup-dp.yml +++ b/.github/workflows/cleanup-dp.yml @@ -42,5 +42,6 @@ jobs: DB_PASSWORD: ${{ secrets.DB_PASSWORD }} DB_URL: ${{ secrets.DB_URL }} GH_TOKEN: ${{ secrets.APPSMITH_DEPLOY_PREVIEW_PAT }} + DP_EFS_ID: ${{ secrets.APPSMITH_DP_EFS_ID }} run: /bin/bash ./scripts/cleanup_dp.sh diff --git a/.github/workflows/on-demand-build-docker-image-deploy-preview.yml b/.github/workflows/on-demand-build-docker-image-deploy-preview.yml index 5f93ddffd3..663dac954e 100644 --- a/.github/workflows/on-demand-build-docker-image-deploy-preview.yml +++ b/.github/workflows/on-demand-build-docker-image-deploy-preview.yml @@ -237,6 +237,8 @@ jobs: DB_USERNAME: ${{ secrets.DB_USERNAME }} DB_PASSWORD: ${{ secrets.DB_PASSWORD }} DB_URL: ${{ secrets.DB_URL }} + DP_EFS_ID: ${{ secrets.APPSMITH_DP_EFS_ID }} + REDIS_URL: ${{ secrets.APPSMITH_DP_REDIS_URL }} run: | echo "environment variables set to deploy the image" $IMAGE_HASH /bin/bash ./scripts/deploy_preview.sh diff --git a/scripts/cleanup_dp.sh b/scripts/cleanup_dp.sh index 47cb3e4b9a..24c4766a9a 100755 --- a/scripts/cleanup_dp.sh +++ b/scripts/cleanup_dp.sh @@ -40,5 +40,7 @@ for i in $deployed_charts helm uninstall $i -n $i kubectl delete ns $i || true mongosh "mongodb+srv://$DB_USERNAME:$DB_PASSWORD@$DB_URL/$i?retryWrites=true&minPoolSize=1&maxPoolSize=10&maxIdleTimeMS=900000&authSource=admin" --eval 'db.dropDatabase()' + ACCESS_POINT_ID=$(aws efs describe-access-points --file-system-id "$APPSMITH_DP_EFS_ID" | jq -r '.AccessPoints[] | select(.Name=="'"$pr"'") | .AccessPointId') + aws efs delete-access-point --access-point-id $ACCESS_POINT_ID fi done diff --git a/scripts/deploy_preview.sh b/scripts/deploy_preview.sh index 64f0043a1a..3dd287e894 100755 --- a/scripts/deploy_preview.sh +++ b/scripts/deploy_preview.sh @@ -28,14 +28,29 @@ export AWS_ACCESS_KEY_ID=$(echo $sts_output | jq -r '.Credentials''.AccessKeyId' export AWS_SECRET_ACCESS_KEY=$(echo $sts_output | jq -r '.Credentials''.SecretAccessKey');\ export AWS_SESSION_TOKEN=$(echo $sts_output | jq -r '.Credentials''.SessionToken'); +# If recreate option is give first delete the existing resources and create them later. +if [[ -n "${RECREATE-}" ]] +then + kubectl delete ns $NAMESPACE || true + mongosh "mongodb+srv://$DB_USERNAME:$DB_PASSWORD@$DB_URL/$DBNAME?retryWrites=true&minPoolSize=1&maxPoolSize=10&maxIdleTimeMS=900000&authSource=admin" --eval 'db.dropDatabase()' + ACCESS_POINT_ID=$(aws efs describe-access-points --file-system-id "$DP_EFS_ID" | jq -r '.AccessPoints[] | select(.Name=="'"$PULL_REQUEST_NUMBER"'") | .AccessPointId') + aws efs delete-access-point --access-point-id $ACCESS_POINT_ID +fi + +## Use DP-EFS and create ACCESS_POINT +ACCESS_POINT=$(aws efs create-access-point --file-system-id $DP_EFS_ID --tags Key=Name,Value=$PULL_REQUEST_NUMBER) +ACCESS_POINT_ID=$(echo $ACCESS_POINT | jq -r '.AccessPointId') + export NAMESPACE=ce"$PULL_REQUEST_NUMBER" export CHARTNAME=ce"$PULL_REQUEST_NUMBER" export SECRET=ce"$PULL_REQUEST_NUMBER" export DBNAME=ce"$PULL_REQUEST_NUMBER" export DOMAINNAME=ce-"$PULL_REQUEST_NUMBER".dp.appsmith.com + + export HELMCHART="appsmith" -export HELMCHART_URL="http://helm.appsmith.com" -export HELMCHART_VERSION="2.0.2" +export HELMCHART_URL="http://helm-ee.appsmith.com" +export HELMCHART_VERSION="3.0.4" aws eks update-kubeconfig --region $region --name $cluster_name --profile eksci @@ -45,12 +60,7 @@ kubectl config set-context --current --namespace=default echo "Getting the pods" kubectl get pods -if [[ -n "${RECREATE-}" ]] -then - kubectl delete ns $NAMESPACE || true - mongosh "mongodb+srv://$DB_USERNAME:$DB_PASSWORD@$DB_URL/$DBNAME?retryWrites=true&minPoolSize=1&maxPoolSize=10&maxIdleTimeMS=900000&authSource=admin" --eval 'db.dropDatabase()' -fi - +echo "Create Namespace and secret to isolate resources." echo "Use kubernetes secret to Pull Image" kubectl create ns $NAMESPACE || true @@ -59,18 +69,23 @@ kubectl create secret docker-registry $SECRET \ --docker-username=$DOCKER_HUB_USERNAME \ --docker-password=$DOCKER_HUB_ACCESS_TOKEN -n $NAMESPACE -echo "Add appsmith-ce to helm repo" -AWS_REGION=ap-south-1 helm repo add $HELMCHART $HELMCHART_URL +echo "Add appsmith-ee to helm repo" +helm repo add "$HELMCHART" "$HELMCHART_URL" echo "Deploy appsmith helm chart" -helm upgrade -i $CHARTNAME appsmith/appsmith -n $NAMESPACE \ - --create-namespace --recreate-pods --set image.repository=$DOCKER_HUB_ORGANIZATION/appsmith-dp --set image.tag=$IMAGE_HASH \ - --set image.pullSecrets=$SECRET --set redis.enabled=false --set mongodb.enabled=false --set ingress.enabled=true \ +helm upgrade -i $CHARTNAME appsmith-ee/$HELMCHART -n $NAMESPACE --create-namespace --recreate-pods \ + --set _image.repository=$DOCKER_HUB_ORGANIZATION/appsmith-dp --set _image.tag=$IMAGE_HASH \ + --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 \ --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" \ - --set ingress.className="nginx" --set applicationConfig.APPSMITH_CLOUD_SERVICES_BASE_URL="https://release-cs.appsmith.com" \ - --set image.pullPolicy="Always" --set autoupdate.enabled="true" --set persistence.size=2Gi \ + --set autoupdate.enabled=false --set persistence.efs.enabled=true --set ingress.className="nginx" \ + --set persistence.efs.driver=efs.csi.aws.com --set persistence.storageClass=efs-dp-appsmith \ + --set persistence.efs.volumeHandle=$DP_EFS_ID::$ACCESS_POINT_ID \ --set applicationConfig.APPSMITH_SENTRY_DSN="https://abf15a075d1347969df44c746cca7eaa@o296332.ingest.sentry.io/1546547" \ --set applicationConfig.APPSMITH_SENTRY_ENVIRONMENT="$NAMESPACE" \ --set applicationConfig.APPSMITH_MONGODB_URI="mongodb+srv://$DB_USERNAME:$DB_PASSWORD@$DB_URL/$DBNAME?retryWrites=true&minPoolSize=1&maxPoolSize=10&maxIdleTimeMS=900000&authSource=admin" \ + --set applicationConfig.APPSMITH_REDIS_URL="$APPSMITH_DP_REDIS_URL:6379" \ + --set applicationConfig.APPSMITH_DISABLE_EMBEDDED_KEYCLOAK=\"1\" \ + --set applicationConfig.APPSMITH_ENABLE_EMBEDDED_DB=\"0\" \ --version $HELMCHART_VERSION