108 lines
2.7 KiB
Bash
Executable File
108 lines
2.7 KiB
Bash
Executable File
#!/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 &
|
|
|
|
LOG_OPTS=""
|
|
LOG_DIR="${LOG_DIR}"
|
|
|
|
if [[ -z "$LOG_DIR" ]] && [[ -d "/srv/containers/logs" ]]; then
|
|
LOG_DIR=/srv/containers/logs
|
|
fi
|
|
|
|
if [[ -n "$LOG_DIR" ]]; then
|
|
LOG_OPTS="$LOG_OPTS --log-dir \"$LOG_DIR\""
|
|
fi
|
|
|
|
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 \
|
|
--include-tags "$INCLUDE_TAGS" \
|
|
--exclude-tags "$EXCLUDE_TAGS" \
|
|
$EXTRA_UNDEPLOY_OPTS \
|
|
--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 \
|
|
--include-tags "$INCLUDE_TAGS" \
|
|
--exclude-tags "$EXCLUDE_TAGS" \
|
|
$LOG_OPTS \
|
|
$EXTRA_DEPLOY_OPTS \
|
|
--discover
|
|
|
|
# Cleanup any build leftovers
|
|
podman system prune --all --force
|
|
sleep 15
|
|
done
|