90 lines
2.2 KiB
Bash
90 lines
2.2 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
if [ -z "$DEPLOYMENT_DNS_SUFFIX" ]; then
|
||
|
echo "DEPLOYMENT_DNS_SUFFIX is required."
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
|
if [ -z "$DEPLOYMENT_RECORD_NAMESPACE" ]; then
|
||
|
echo "DEPLOYMENT_RECORD_NAMESPACE is required."
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
|
if [ -z "$IMAGE_REGISTRY" ]; then
|
||
|
echo "IMAGE_REGISTRY is required."
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
|
if [ ! -f "/etc/config/laconic.yml" ]; then
|
||
|
echo "/etc/config/laconic.yml is required."
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
|
if [ ! -f "/etc/config/kube.yml" ]; then
|
||
|
echo "/etc/config/kube.yml is required."
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
|
if [ ! -z "$IMAGE_REGISTRY_CREDS" ]; then
|
||
|
docker login --password "$IMAGE_REGISTRY_CREDS" --username ${IMAGE_REGISTRY_USER:-ANY} $IMAGE_REGISTRY
|
||
|
fi
|
||
|
|
||
|
function is_privileged {
|
||
|
ip link add dummy0 type dummy >/dev/null
|
||
|
if [[ $? -eq 0 ]]; then
|
||
|
echo "true"
|
||
|
ip link delete dummy0 >/dev/null
|
||
|
else
|
||
|
echo "false"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
if [[ "true" == "`is_privileged`" ]]; then
|
||
|
echo "Using 'overlay' storage driver."
|
||
|
else
|
||
|
echo "Using 'vfs' storage driver."
|
||
|
sed -i 's/"overlay"/"vfs"/g' /etc/containers/storage.conf
|
||
|
fi
|
||
|
|
||
|
if [ ! -d "/srv/deployments/webapps" ]; then
|
||
|
mkdir -p /srv/deployments/webapps
|
||
|
fi
|
||
|
|
||
|
if [ "$CLEAN_STATE" == "true" ]; then
|
||
|
echo "Removing existing state..."
|
||
|
rm -f /srv/deployments//webapps/*.state
|
||
|
fi
|
||
|
|
||
|
echo "Starting API"
|
||
|
cd /app/
|
||
|
yarn start &
|
||
|
|
||
|
while true; do
|
||
|
echo "=============================================================="
|
||
|
|
||
|
echo "########### UNDEPLOY ############"
|
||
|
laconic-so undeploy-webapp-from-registry \
|
||
|
--laconic-config /etc/config/laconic.yml \
|
||
|
--deployment-parent-dir /srv/deployments/webapps \
|
||
|
--delete-names \
|
||
|
--delete-volumes \
|
||
|
--state-file /srv/deployments/webapps/autoremove.state \
|
||
|
--discover
|
||
|
|
||
|
echo "############ DEPLOY #############"
|
||
|
laconic-so deploy-webapp-from-registry \
|
||
|
--kube-config /etc/config/kube.yml \
|
||
|
--laconic-config /etc/config/laconic.yml \
|
||
|
--image-registry ${IMAGE_REGISTRY} \
|
||
|
--deployment-parent-dir /srv/deployments/webapps \
|
||
|
--dns-suffix ${DEPLOYMENT_DNS_SUFFIX} \
|
||
|
--record-namespace-dns crn://${DEPLOYMENT_RECORD_NAMESPACE}/dns \
|
||
|
--record-namespace-deployments crn://${DEPLOYMENT_RECORD_NAMESPACE}/deployments \
|
||
|
--state-file /srv/deployments/webapps/autodeploy.state \
|
||
|
--discover
|
||
|
|
||
|
# Cleanup any build leftovers
|
||
|
podman system prune --all --force
|
||
|
sleep 15
|
||
|
done
|