From 8470ec67081ed8a410a7f83d85d34d098ba1a38c Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Thu, 8 Dec 2022 10:17:25 +0900 Subject: [PATCH 1/5] serve-java-app: support legacy spring app --- app_serving/serve-java-app.yaml | 112 ++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 36 deletions(-) diff --git a/app_serving/serve-java-app.yaml b/app_serving/serve-java-app.yaml index b2c02be1..1f54f662 100644 --- a/app_serving/serve-java-app.yaml +++ b/app_serving/serve-java-app.yaml @@ -16,6 +16,9 @@ spec: # options: build/deploy/all - name: type value: "all" + # options: spring/springboot + - name: app_type + value: "spring" - name: target_cluster_id value: "C011b88fa" - name: app_name @@ -218,26 +221,24 @@ spec: echo "Fetching app artifact.." | tee -a $BUILD_LOG - # TODO: How to pass auth info here? artifact_url="{{workflow.parameters.artifact_url}}" curl -L -O $artifact_url 2> >(tee -a $BUILD_LOG >&2) + artifact=${artifact_url##*\/} # fetch Dockerfile & manifests from git git clone https://github.com/openinfradev/app-serve-template.git - cp -r ./app-serve-template/Dockerfile . - ls -l . - - ############### - # Build Image # - ############### - echo "Composing Dockerfile..." | tee -a $BUILD_LOG - - # Replace port number in Dockerfile - artifact=${artifact_url##*\/} - sed -i "s/FILENAME/$artifact/g" ./Dockerfile - sed -i "s/PORTNUM/{{workflow.parameters.port}}/g" ./Dockerfile + app_type={{workflow.parameters.app_type}} + if [[ "$app_type" == "SPRING" ]]; then + cp ./app-serve-template/Dockerfile.spring ./Dockerfile + sed -i "s/FILENAME/$artifact/g" ./Dockerfile + else + cp ./app-serve-template/Dockerfile.springboot ./Dockerfile + sed -i "s/FILENAME/$artifact/g" ./Dockerfile + sed -i "s/PORTNUM/{{workflow.parameters.port}}/g" ./Dockerfile + fi + ls -l . # Debug cat Dockerfile | tee -a $BUILD_LOG @@ -297,28 +298,59 @@ spec: cd /apps git clone https://github.com/openinfradev/app-serve-template.git - # new logic for helm chart - cd /apps/app-serve-template/chart - - # replace variable for the app - echo "Replacing variables in helm chart..." | tee -a $DEPLOY_LOG - image_name="{{workflow.parameters.image_url}}" - sed -i "s#EXECUTABLE_PATH#{{workflow.parameters.executable_path}}#g" ./values.yaml - sed -i "s/PORT_NUM/{{workflow.parameters.port}}/g" ./values.yaml - sed -i "s/APP_NAME/{{workflow.parameters.app_name}}/g" ./values.yaml ./Chart.yaml - sed -i "s#IMAGE_URL#${image_name}#g" ./values.yaml - sed -i "s/PROFILE/{{workflow.parameters.profile}}/g" ./values.yaml - sed -i "s/PV_ENABLED/{{workflow.parameters.pv_enabled}}/g" ./values.yaml - sed -i "s/PV_STORAGE_CLASS/{{workflow.parameters.pv_storage_class}}/g" ./values.yaml - sed -i "s/PV_ACCESS_MODE/{{workflow.parameters.pv_access_mode}}/g" ./values.yaml - sed -i "s/PV_SIZE/{{workflow.parameters.pv_size}}/g" ./values.yaml - sed -i "s#PV_MOUNT_PATH#{{workflow.parameters.pv_mount_path}}#g" ./values.yaml - - # TODO: parse image tag and use it as APP_VERSION in Chart.yaml? - # - - # Debug - cat values.yaml + app_type={{workflow.parameters.app_type}} + ## For legacy spring app case ## + if [[ "$app_type" == "SPRING" ]]; then + cd /apps/app-serve-template + # replace variable for the tomcat value-override file + echo "Replacing variables in tomcat chart..." | tee -a $DEPLOY_LOG + image_name="{{workflow.parameters.image_url}}" + registry=$(echo $image_name | awk -F/ '{ print $1 }') + image_tag=$(echo $image_name | awk -F: '{ print $2 }') + + # extract repository part using param expansion + temp1="${image_name%:*}" + repository="${temp1#*/}" + + sed -i "s/APP_NAME/{{workflow.parameters.app_name}}/g" ./tomcat-vo.yaml + sed -i "s#REGISTRY#${registry}#g" ./tomcat-vo.yaml + sed -i "s#REPOSITORY#${repository}#g" ./tomcat-vo.yaml + sed -i "s/TAG/${image_tag}/g" ./tomcat-vo.yaml + sed -i "s/PV_ENABLED/{{workflow.parameters.pv_enabled}}/g" ./tomcat-vo.yaml + sed -i "s/PV_STORAGE_CLASS/{{workflow.parameters.pv_storage_class}}/g" ./tomcat-vo.yaml + sed -i "s/PV_ACCESS_MODE/{{workflow.parameters.pv_access_mode}}/g" ./tomcat-vo.yaml + sed -i "s/PV_SIZE/{{workflow.parameters.pv_size}}/g" ./tomcat-vo.yaml + ## Currently, tomcat chart doesn't allow mount path override of default PVC. + ## To override the path, extra PVC needs to be created. + #sed -i "s#PV_MOUNT_PATH#{{workflow.parameters.pv_mount_path}}#g" ./tomcat-vo.yaml + # Debug + cat tomcat-vo.yaml + + ## For springboot app case ## + else + # new logic for helm chart + cd /apps/app-serve-template/chart + + # replace variable for the app + echo "Replacing variables in helm chart..." | tee -a $DEPLOY_LOG + image_name="{{workflow.parameters.image_url}}" + sed -i "s#EXECUTABLE_PATH#{{workflow.parameters.executable_path}}#g" ./values.yaml + sed -i "s/PORT_NUM/{{workflow.parameters.port}}/g" ./values.yaml + sed -i "s/APP_NAME/{{workflow.parameters.app_name}}/g" ./values.yaml ./Chart.yaml + sed -i "s#IMAGE_URL#${image_name}#g" ./values.yaml + sed -i "s/PROFILE/{{workflow.parameters.profile}}/g" ./values.yaml + sed -i "s/PV_ENABLED/{{workflow.parameters.pv_enabled}}/g" ./values.yaml + sed -i "s/PV_STORAGE_CLASS/{{workflow.parameters.pv_storage_class}}/g" ./values.yaml + sed -i "s/PV_ACCESS_MODE/{{workflow.parameters.pv_access_mode}}/g" ./values.yaml + sed -i "s/PV_SIZE/{{workflow.parameters.pv_size}}/g" ./values.yaml + sed -i "s#PV_MOUNT_PATH#{{workflow.parameters.pv_mount_path}}#g" ./values.yaml + + # TODO: parse image tag and use it as APP_VERSION in Chart.yaml? + # + + # Debug + cat values.yaml + fi # Prepare kubeconfig echo "Preparing kubeconfig for target cluster..." | tee -a $DEPLOY_LOG @@ -336,7 +368,13 @@ spec: echo "Starting deployment..." | tee -a $DEPLOY_LOG # If make this strict, use asa_id as prefix to guarantee uniqueness of helm release. kubectl create ns {{workflow.parameters.namespace}} || true - helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f values-{{workflow.parameters.resource_spec}}.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) + + ## For legacy spring app case ## + if [[ "$app_type" == "SPRING" ]]; then + helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f tomcat-vo.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) + else + helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f values-{{workflow.parameters.resource_spec}}.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) + fi # Just make sure helm release is deployed before status cmd sleep 1 @@ -359,6 +397,8 @@ spec: kubectl wait --for=condition=Available --timeout=300s -n {{workflow.parameters.namespace}} deploy/{{workflow.parameters.app_name}} 2> >(tee -a $DEPLOY_LOG >&2) + echo "Deployment status has changed to 'Available'. Checking replicas.." | tee -a $DEPLOY_LOG + # Check num of replicas ready=false SLEEP_INTERVAL=5 From ba8b3ee4dc719be8fac29f94e177d1efb1e69716 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Thu, 8 Dec 2022 10:45:14 +0900 Subject: [PATCH 2/5] serve-java-app: use 80 port for endpoint --- app_serving/serve-java-app.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/app_serving/serve-java-app.yaml b/app_serving/serve-java-app.yaml index 1f54f662..d4a829b3 100644 --- a/app_serving/serve-java-app.yaml +++ b/app_serving/serve-java-app.yaml @@ -436,7 +436,6 @@ spec: # Writing endpoint to file kubectl get svc {{workflow.parameters.app_name}} -n {{workflow.parameters.namespace}} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' > /mnt/out/endpoint - echo ":{{workflow.parameters.port}}" >> /mnt/out/endpoint - name: parse-failed-step volumes: From 149ba7593d0e0b7bdc53a04a23e9ba1ccc7d2096 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Fri, 9 Dec 2022 17:11:14 +0900 Subject: [PATCH 3/5] serve-java-app: use lower case --- app_serving/serve-java-app.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app_serving/serve-java-app.yaml b/app_serving/serve-java-app.yaml index d4a829b3..baf3bba1 100644 --- a/app_serving/serve-java-app.yaml +++ b/app_serving/serve-java-app.yaml @@ -230,7 +230,7 @@ spec: echo "Composing Dockerfile..." | tee -a $BUILD_LOG app_type={{workflow.parameters.app_type}} - if [[ "$app_type" == "SPRING" ]]; then + if [[ "$app_type" == "spring" ]]; then cp ./app-serve-template/Dockerfile.spring ./Dockerfile sed -i "s/FILENAME/$artifact/g" ./Dockerfile else @@ -300,7 +300,7 @@ spec: app_type={{workflow.parameters.app_type}} ## For legacy spring app case ## - if [[ "$app_type" == "SPRING" ]]; then + if [[ "$app_type" == "spring" ]]; then cd /apps/app-serve-template # replace variable for the tomcat value-override file echo "Replacing variables in tomcat chart..." | tee -a $DEPLOY_LOG @@ -370,7 +370,7 @@ spec: kubectl create ns {{workflow.parameters.namespace}} || true ## For legacy spring app case ## - if [[ "$app_type" == "SPRING" ]]; then + if [[ "$app_type" == "spring" ]]; then helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f tomcat-vo.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) else helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f values-{{workflow.parameters.resource_spec}}.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) From 177be3fba72447f137f8ade4092f88320ee22e08 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Mon, 12 Dec 2022 10:01:38 +0900 Subject: [PATCH 4/5] serve-java-app: clone tomcat chart --- app_serving/serve-java-app.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app_serving/serve-java-app.yaml b/app_serving/serve-java-app.yaml index baf3bba1..a5ee80c0 100644 --- a/app_serving/serve-java-app.yaml +++ b/app_serving/serve-java-app.yaml @@ -301,6 +301,9 @@ spec: app_type={{workflow.parameters.app_type}} ## For legacy spring app case ## if [[ "$app_type" == "spring" ]]; then + # Clone tomcat chart + git clone https://github.com/openinfradev/helm-charts.git + cd /apps/app-serve-template # replace variable for the tomcat value-override file echo "Replacing variables in tomcat chart..." | tee -a $DEPLOY_LOG @@ -371,8 +374,12 @@ spec: ## For legacy spring app case ## if [[ "$app_type" == "spring" ]]; then - helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f tomcat-vo.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) + cd /apps/helm-charts/tomcat + ## TODO: this might be temporary. Once everything is confirmed, + ## the helm chart can be pulled from internal helm repo. + helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f /apps/app-serve-template/tomcat-vo.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) else + cd /apps/app-serve-template/chart helm upgrade --install --kubeconfig /etc/kubeconfig_temp -f values-{{workflow.parameters.resource_spec}}.yaml -n {{workflow.parameters.namespace}} {{workflow.parameters.app_name}} . 2> >(tee -a $DEPLOY_LOG >&2) fi From 5c0246ab52d7e7ff6a0259a1b58f1a5132f51e40 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Tue, 13 Dec 2022 18:29:31 +0900 Subject: [PATCH 5/5] add git_repo_url param --- app_serving/serve-java-app.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app_serving/serve-java-app.yaml b/app_serving/serve-java-app.yaml index a5ee80c0..aaff827c 100644 --- a/app_serving/serve-java-app.yaml +++ b/app_serving/serve-java-app.yaml @@ -60,6 +60,8 @@ spec: # tks_info service URL - name: tks_info_host value: "tks-info.tks" + - name: git_repo_url + value: "github.com/openinfradev" templates: - name: exit-handler @@ -226,7 +228,7 @@ spec: artifact=${artifact_url##*\/} # fetch Dockerfile & manifests from git - git clone https://github.com/openinfradev/app-serve-template.git + git clone https://{{workflow.parameters.git_repo_url}}/app-serve-template.git echo "Composing Dockerfile..." | tee -a $BUILD_LOG app_type={{workflow.parameters.app_type}} @@ -296,13 +298,13 @@ spec: # fetch manifests from git cd /apps - git clone https://github.com/openinfradev/app-serve-template.git + git clone https://{{workflow.parameters.git_repo_url}}/app-serve-template.git app_type={{workflow.parameters.app_type}} ## For legacy spring app case ## if [[ "$app_type" == "spring" ]]; then # Clone tomcat chart - git clone https://github.com/openinfradev/helm-charts.git + git clone https://{{workflow.parameters.git_repo_url}}/helm-charts.git cd /apps/app-serve-template # replace variable for the tomcat value-override file