Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support legacy spring app #128

Merged
merged 5 commits into from
Dec 13, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 83 additions & 37 deletions app_serving/serve-java-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -297,28 +298,62 @@ 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
# Clone tomcat chart
git clone https://github.com/openinfradev/helm-charts.git
zugwan marked this conversation as resolved.
Show resolved Hide resolved

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
Expand All @@ -336,7 +371,17 @@ 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
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

# Just make sure helm release is deployed before status cmd
sleep 1
Expand All @@ -359,6 +404,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
Expand Down Expand Up @@ -396,7 +443,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:
Expand Down