Compare commits
1 Commits
main
...
ag-debug-a
Author | SHA1 | Date | |
---|---|---|---|
|
2b04f4d5a7 |
@ -10,4 +10,3 @@ SYSTEM_PRUNE=false
|
|||||||
WEBAPP_IMAGE_PRUNE=true
|
WEBAPP_IMAGE_PRUNE=true
|
||||||
CHECK_INTERVAL=5
|
CHECK_INTERVAL=5
|
||||||
FQDN_POLICY="allow"
|
FQDN_POLICY="allow"
|
||||||
DEPLOYMENT_IP="k8s.cluster.ip.address"
|
|
@ -44,5 +44,5 @@ COPY . /app/
|
|||||||
WORKDIR /app/
|
WORKDIR /app/
|
||||||
RUN rm -rf node_modules && yarn && yarn clean && yarn build:release
|
RUN rm -rf node_modules && yarn && yarn clean && yarn build:release
|
||||||
|
|
||||||
COPY scripts .
|
COPY run.sh .
|
||||||
CMD ["./scripts/run.sh"]
|
CMD ["./run.sh"]
|
||||||
|
@ -133,9 +133,6 @@ OPENPGP_PASSPHRASE="SECRET"
|
|||||||
OPENPGP_PRIVATE_KEY_FILE="/etc/config/webapp-deployer-api.my.domain.com.pgp.key"
|
OPENPGP_PRIVATE_KEY_FILE="/etc/config/webapp-deployer-api.my.domain.com.pgp.key"
|
||||||
LACONIC_CONFIG="/etc/config/registry.yml"
|
LACONIC_CONFIG="/etc/config/registry.yml"
|
||||||
LRN=lrn://laconic/deployers/webapp-deployer-api.my.domain.com
|
LRN=lrn://laconic/deployers/webapp-deployer-api.my.domain.com
|
||||||
CHECK_INTERVAL=15
|
|
||||||
|
|
||||||
AUCTION_CHECK_INTERVAL=10
|
|
||||||
HANDLE_AUCTION_REQUESTS=true
|
HANDLE_AUCTION_REQUESTS=true
|
||||||
AUCTION_BID_AMOUNT=50000
|
AUCTION_BID_AMOUNT=50000
|
||||||
```
|
```
|
||||||
|
@ -8,15 +8,6 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 9555
|
- 9555
|
||||||
|
|
||||||
cerc-webapp-auction-handler:
|
|
||||||
image: cerc/webapp-deployer-backend:local
|
|
||||||
restart: always
|
|
||||||
environment:
|
|
||||||
RUN_AUCTIONS_HANDLER: "true"
|
|
||||||
volumes:
|
|
||||||
- srv:/srv
|
|
||||||
- config:/etc/config:ro
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
config:
|
config:
|
||||||
srv:
|
srv:
|
||||||
|
204
run.sh
Executable file
204
run.sh
Executable file
@ -0,0 +1,204 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
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 [ -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
|
||||||
|
|
||||||
|
AUCTION_OPTS=""
|
||||||
|
if [ "$HANDLE_AUCTION_REQUESTS" = "true" ]; then
|
||||||
|
if [ -z "$AUCTION_BID_AMOUNT" ]; then
|
||||||
|
echo "AUCTION_BID_AMOUNT is required when handling auction requsts."
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
AUCTION_OPTS="--auction-requests"
|
||||||
|
fi
|
||||||
|
|
||||||
|
STORAGE_ROOT="${STORAGE_ROOT:-/srv}"
|
||||||
|
DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-$STORAGE_ROOT/deployments}"
|
||||||
|
LOG_DIR="${LOG_DIR:-$STORAGE_ROOT/logs}"
|
||||||
|
CONTAINERS_DIR="${CONTAINER_DIR:-$STORAGE_ROOT/containers}"
|
||||||
|
|
||||||
|
if [[ ! -d "${DEPLOYMENTS_DIR}" ]]; then
|
||||||
|
mkdir -p "${DEPLOYMENTS_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
LOG_OPTS=""
|
||||||
|
if [[ -n "${LOG_DIR}" ]]; then
|
||||||
|
if [[ ! -d "${LOG_DIR}" ]]; then
|
||||||
|
mkdir -p "${LOG_DIR}"
|
||||||
|
fi
|
||||||
|
LOG_OPTS="--log-dir $LOG_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d "${CONTAINERS_DIR}" ]]; then
|
||||||
|
mkdir -p "${CONTAINERS_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$CLEAN_DEPLOYMENTS" == "true" ]]; then
|
||||||
|
echo "Cleaning deployments directory..."
|
||||||
|
rm -rf ${DEPLOYMENTS_DIR}/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$CLEAN_CONTAINERS" == "true" ]]; then
|
||||||
|
echo "Cleaning containers directory..."
|
||||||
|
rm -rf ${CONTAINERS_DIR}/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$CLEAN_LOGS" == "true" ]] && [[ -n "$LOG_DIR" ]]; then
|
||||||
|
echo "Cleaning logs directory..."
|
||||||
|
rm -rf ${LOG_DIR}/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -d "${UPLOAD_DIRECTORY}" ]]; then
|
||||||
|
mkdir -p "${UPLOAD_DIRECTORY}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
STORAGE_DRIVER="${STORAGE_DRIVER}"
|
||||||
|
if [[ -z "${STORAGE_DRIVER}" ]]; then
|
||||||
|
if [[ "true" == "`is_privileged`" ]]; then
|
||||||
|
STORAGE_DRIVER="overlay"
|
||||||
|
else
|
||||||
|
STORAGE_DRIVER="vfs"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "Using '$STORAGE_DRIVER' storage driver."
|
||||||
|
|
||||||
|
cat > /etc/containers/storage.conf <<EOF
|
||||||
|
[storage]
|
||||||
|
driver = "${STORAGE_DRIVER}"
|
||||||
|
runroot = "${CONTAINERS_DIR}/podman/run"
|
||||||
|
graphroot = "${CONTAINERS_DIR}/podman/storage"
|
||||||
|
[storage.options.overlay]
|
||||||
|
mount_program = "/usr/bin/fuse-overlayfs"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [[ -n "$IMAGE_REGISTRY_CREDS" ]]; then
|
||||||
|
docker login --password "$IMAGE_REGISTRY_CREDS" --username ${IMAGE_REGISTRY_USER:-ANY} $IMAGE_REGISTRY
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd /app/
|
||||||
|
while true; do
|
||||||
|
UPDATE_OPTS=""
|
||||||
|
if [[ "true" == "${ONLY_NEW_REQUESTS:-true}" ]] && [[ ! -f "${DEPLOYMENTS_DIR}/autodeploy.state" ]]; then
|
||||||
|
UPDATE_OPTS="--only-update-state"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=============================================================="
|
||||||
|
ps -ef | grep node | grep 'yarn start' >/dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "########### STARTING API ############"
|
||||||
|
echo "Starting API"
|
||||||
|
yarn start &
|
||||||
|
fi
|
||||||
|
|
||||||
|
# echo "########### UNDEPLOY ############"
|
||||||
|
# laconic-so undeploy-webapp-from-registry \
|
||||||
|
# --laconic-config /etc/config/laconic.yml \
|
||||||
|
# --deployment-parent-dir "${DEPLOYMENTS_DIR}" \
|
||||||
|
# --delete-names \
|
||||||
|
# --delete-volumes \
|
||||||
|
# --state-file "${DEPLOYMENTS_DIR}/autoremove.state" \
|
||||||
|
# --include-tags "$INCLUDE_TAGS" \
|
||||||
|
# --exclude-tags "$EXCLUDE_TAGS" \
|
||||||
|
# --lrn "$LRN" \
|
||||||
|
# --min-required-payment ${MIN_REQUIRED_PAYMENT:-0} \
|
||||||
|
# $EXTRA_UNDEPLOY_OPTS \
|
||||||
|
# $UPDATE_OPTS \
|
||||||
|
# --discover
|
||||||
|
# rc=$?
|
||||||
|
# if [ $rc -eq 0 ]; then
|
||||||
|
# echo "############ UNDEPLOY SUCCESS #############"
|
||||||
|
# else
|
||||||
|
# echo "############ UNDEPLOY FAILURE STATUS $rc #############"
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# 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 "${DEPLOYMENTS_DIR}" \
|
||||||
|
# --dns-suffix ${DEPLOYMENT_DNS_SUFFIX} \
|
||||||
|
# --record-namespace-dns lrn://${DEPLOYMENT_RECORD_NAMESPACE}/dns \
|
||||||
|
# --record-namespace-deployments lrn://${DEPLOYMENT_RECORD_NAMESPACE}/deployments \
|
||||||
|
# --state-file "${DEPLOYMENTS_DIR}/autodeploy.state" \
|
||||||
|
# --include-tags "$INCLUDE_TAGS" \
|
||||||
|
# --exclude-tags "$EXCLUDE_TAGS" \
|
||||||
|
# --fqdn-policy "${FQDN_POLICY:-prohibit}" \
|
||||||
|
# --lrn "$LRN" \
|
||||||
|
# --min-required-payment ${MIN_REQUIRED_PAYMENT:-0} \
|
||||||
|
# --config-upload-dir "$UPLOAD_DIRECTORY" \
|
||||||
|
# --private-key-file "$OPENPGP_PRIVATE_KEY_FILE" \
|
||||||
|
# --private-key-passphrase "$OPENPGP_PASSPHRASE" \
|
||||||
|
# $AUCTION_OPTS \
|
||||||
|
# $LOG_OPTS \
|
||||||
|
# $EXTRA_DEPLOY_OPTS \
|
||||||
|
# $UPDATE_OPTS \
|
||||||
|
# --discover
|
||||||
|
# rc=$?
|
||||||
|
# if [ $rc -eq 0 ]; then
|
||||||
|
# echo "############ DEPLOY SUCCESS #############"
|
||||||
|
# else
|
||||||
|
# echo "############ DEPLOY FAILURE STATUS $rc #############"
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# if [ "$HANDLE_AUCTION_REQUESTS" = "true" ]; then
|
||||||
|
# echo "############ DEPLOYMENT AUCTION #############"
|
||||||
|
# laconic-so handle-deployment-auction \
|
||||||
|
# --laconic-config /etc/config/laconic.yml \
|
||||||
|
# --state-file "${DEPLOYMENTS_DIR}/autoauction.state" \
|
||||||
|
# --bid-amount ${AUCTION_BID_AMOUNT}
|
||||||
|
# rc=$?
|
||||||
|
# if [ $rc -eq 0 ]; then
|
||||||
|
# echo "############ DEPLOYMENT AUCTION SUCCESS #############"
|
||||||
|
# else
|
||||||
|
# echo "############ DEPLOYMENT AUCTION FAILURE STATUS $rc #############"
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# # Cleanup any build leftovers
|
||||||
|
# if [[ "${SYSTEM_PRUNE:-false}" == "true" ]]; then
|
||||||
|
# docker system prune --all --force
|
||||||
|
# fi
|
||||||
|
# if [[ "${WEBAPP_IMAGE_PRUNE:-true}" == "true" ]]; then
|
||||||
|
# APP_IMAGES="$(docker image ls --quiet --filter 'reference=laconic-webapp')"
|
||||||
|
# DANGLING_IMAGES="$(docker image ls --quiet --filter 'dangling=true')"
|
||||||
|
# if [[ -n "$APP_IMAGES" ]] || [[ -n "$DANGLING_IMAGES" ]]; then
|
||||||
|
# echo "Pruning images: $APP_IMAGES $DANGLING_IMAGES"
|
||||||
|
# docker image rm -f $APP_IMAGES $DANGLING_IMAGES
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
sleep ${CHECK_INTERVAL:-15}
|
||||||
|
done
|
@ -1,47 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ ! -f "/etc/config/laconic.yml" ]; then
|
|
||||||
echo "/etc/config/laconic.yml is required."
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$HANDLE_AUCTION_REQUESTS" = "true" ]; then
|
|
||||||
if [ -z "$AUCTION_BID_AMOUNT" ]; then
|
|
||||||
echo "AUCTION_BID_AMOUNT is required when handling auction requsts."
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Not handling auction requests"
|
|
||||||
|
|
||||||
# k8s integration only supports "always" restart policy, so wait indefinitely
|
|
||||||
# TODO: Exit container once restart policy is supported
|
|
||||||
tail -f /dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
STORAGE_ROOT="${STORAGE_ROOT:-/srv}"
|
|
||||||
DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-$STORAGE_ROOT/deployments}"
|
|
||||||
REGISTRY_LOCK_FILE="${REGISTRY_LOCK_FILE:-/srv/registry_mutex_lock_file}"
|
|
||||||
|
|
||||||
if [[ ! -d "${DEPLOYMENTS_DIR}" ]]; then
|
|
||||||
mkdir -p "${DEPLOYMENTS_DIR}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd /app/
|
|
||||||
while true; do
|
|
||||||
echo "=============================================================="
|
|
||||||
|
|
||||||
echo "############ DEPLOYMENT AUCTION #############"
|
|
||||||
laconic-so handle-deployment-auction \
|
|
||||||
--laconic-config /etc/config/laconic.yml \
|
|
||||||
--registry-lock-file "${REGISTRY_LOCK_FILE}" \
|
|
||||||
--state-file "${DEPLOYMENTS_DIR}/autoauction.state" \
|
|
||||||
--bid-amount ${AUCTION_BID_AMOUNT}
|
|
||||||
rc=$?
|
|
||||||
if [ $rc -eq 0 ]; then
|
|
||||||
echo "############ DEPLOYMENT AUCTION SUCCESS #############"
|
|
||||||
else
|
|
||||||
echo "############ DEPLOYMENT AUCTION FAILURE STATUS $rc #############"
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep ${AUCTION_CHECK_INTERVAL:-10}
|
|
||||||
done
|
|
200
scripts/run.sh
200
scripts/run.sh
@ -1,200 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ "$RUN_AUCTIONS_HANDLER" = "true" ]; then
|
|
||||||
exec "./scripts/handle-auctions.sh"
|
|
||||||
exit
|
|
||||||
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 [ -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 [ "$FQDN_POLICY" = "allow" ] && [ -z "$DEPLOYMENT_IP" ]; then
|
|
||||||
echo "DEPLOYMENT_IP is required with 'allow' FQDN_POLICY"
|
|
||||||
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
|
|
||||||
|
|
||||||
AUCTION_OPTS=""
|
|
||||||
if [ "$HANDLE_AUCTION_REQUESTS" = "true" ]; then
|
|
||||||
AUCTION_OPTS="--auction-requests"
|
|
||||||
fi
|
|
||||||
|
|
||||||
STORAGE_ROOT="${STORAGE_ROOT:-/srv}"
|
|
||||||
DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-$STORAGE_ROOT/deployments}"
|
|
||||||
LOG_DIR="${LOG_DIR:-$STORAGE_ROOT/logs}"
|
|
||||||
CONTAINERS_DIR="${CONTAINER_DIR:-$STORAGE_ROOT/containers}"
|
|
||||||
REGISTRY_LOCK_FILE="${REGISTRY_LOCK_FILE:-/srv/registry_mutex_lock_file}"
|
|
||||||
|
|
||||||
if [[ ! -d "${DEPLOYMENTS_DIR}" ]]; then
|
|
||||||
mkdir -p "${DEPLOYMENTS_DIR}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
LOG_OPTS=""
|
|
||||||
if [[ -n "${LOG_DIR}" ]]; then
|
|
||||||
if [[ ! -d "${LOG_DIR}" ]]; then
|
|
||||||
mkdir -p "${LOG_DIR}"
|
|
||||||
fi
|
|
||||||
LOG_OPTS="--log-dir $LOG_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -d "${CONTAINERS_DIR}" ]]; then
|
|
||||||
mkdir -p "${CONTAINERS_DIR}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$CLEAN_DEPLOYMENTS" == "true" ]]; then
|
|
||||||
echo "Cleaning deployments directory..."
|
|
||||||
rm -rf ${DEPLOYMENTS_DIR}/*
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$CLEAN_CONTAINERS" == "true" ]]; then
|
|
||||||
echo "Cleaning containers directory..."
|
|
||||||
rm -rf ${CONTAINERS_DIR}/*
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$CLEAN_LOGS" == "true" ]] && [[ -n "$LOG_DIR" ]]; then
|
|
||||||
echo "Cleaning logs directory..."
|
|
||||||
rm -rf ${LOG_DIR}/*
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -d "${UPLOAD_DIRECTORY}" ]]; then
|
|
||||||
mkdir -p "${UPLOAD_DIRECTORY}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
STORAGE_DRIVER="${STORAGE_DRIVER}"
|
|
||||||
if [[ -z "${STORAGE_DRIVER}" ]]; then
|
|
||||||
if [[ "true" == "`is_privileged`" ]]; then
|
|
||||||
STORAGE_DRIVER="overlay"
|
|
||||||
else
|
|
||||||
STORAGE_DRIVER="vfs"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo "Using '$STORAGE_DRIVER' storage driver."
|
|
||||||
|
|
||||||
cat > /etc/containers/storage.conf <<EOF
|
|
||||||
[storage]
|
|
||||||
driver = "${STORAGE_DRIVER}"
|
|
||||||
runroot = "${CONTAINERS_DIR}/podman/run"
|
|
||||||
graphroot = "${CONTAINERS_DIR}/podman/storage"
|
|
||||||
[storage.options.overlay]
|
|
||||||
mount_program = "/usr/bin/fuse-overlayfs"
|
|
||||||
EOF
|
|
||||||
|
|
||||||
if [[ -n "$IMAGE_REGISTRY_CREDS" ]]; then
|
|
||||||
docker login --password "$IMAGE_REGISTRY_CREDS" --username ${IMAGE_REGISTRY_USER:-ANY} $IMAGE_REGISTRY
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd /app/
|
|
||||||
while true; do
|
|
||||||
UPDATE_OPTS=""
|
|
||||||
if [[ "true" == "${ONLY_NEW_REQUESTS:-true}" ]] && [[ ! -f "${DEPLOYMENTS_DIR}/autodeploy.state" ]]; then
|
|
||||||
UPDATE_OPTS="--only-update-state"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "=============================================================="
|
|
||||||
ps -ef | grep node | grep 'yarn start' >/dev/null
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "########### STARTING API ############"
|
|
||||||
echo "Starting API"
|
|
||||||
yarn start &
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "########### UNDEPLOY ############"
|
|
||||||
laconic-so undeploy-webapp-from-registry \
|
|
||||||
--laconic-config /etc/config/laconic.yml \
|
|
||||||
--registry-lock-file "${REGISTRY_LOCK_FILE}" \
|
|
||||||
--deployment-parent-dir "${DEPLOYMENTS_DIR}" \
|
|
||||||
--delete-names \
|
|
||||||
--delete-volumes \
|
|
||||||
--state-file "${DEPLOYMENTS_DIR}/autoremove.state" \
|
|
||||||
--include-tags "$INCLUDE_TAGS" \
|
|
||||||
--exclude-tags "$EXCLUDE_TAGS" \
|
|
||||||
--lrn "$LRN" \
|
|
||||||
--min-required-payment 0 \
|
|
||||||
$EXTRA_UNDEPLOY_OPTS \
|
|
||||||
$UPDATE_OPTS \
|
|
||||||
--discover
|
|
||||||
rc=$?
|
|
||||||
if [ $rc -eq 0 ]; then
|
|
||||||
echo "############ UNDEPLOY SUCCESS #############"
|
|
||||||
else
|
|
||||||
echo "############ UNDEPLOY FAILURE STATUS $rc #############"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "############ DEPLOY #############"
|
|
||||||
laconic-so deploy-webapp-from-registry \
|
|
||||||
--kube-config /etc/config/kube.yml \
|
|
||||||
--laconic-config /etc/config/laconic.yml \
|
|
||||||
--registry-lock-file "${REGISTRY_LOCK_FILE}" \
|
|
||||||
--image-registry ${IMAGE_REGISTRY} \
|
|
||||||
--deployment-parent-dir "${DEPLOYMENTS_DIR}" \
|
|
||||||
--dns-suffix ${DEPLOYMENT_DNS_SUFFIX} \
|
|
||||||
--record-namespace-dns lrn://${DEPLOYMENT_RECORD_NAMESPACE}/dns \
|
|
||||||
--record-namespace-deployments lrn://${DEPLOYMENT_RECORD_NAMESPACE}/deployments \
|
|
||||||
--state-file "${DEPLOYMENTS_DIR}/autodeploy.state" \
|
|
||||||
--include-tags "$INCLUDE_TAGS" \
|
|
||||||
--exclude-tags "$EXCLUDE_TAGS" \
|
|
||||||
--fqdn-policy "${FQDN_POLICY:-prohibit}" \
|
|
||||||
--ip "${DEPLOYMENT_IP}" \
|
|
||||||
--lrn "$LRN" \
|
|
||||||
--min-required-payment ${MIN_REQUIRED_PAYMENT:-0} \
|
|
||||||
--config-upload-dir "$UPLOAD_DIRECTORY" \
|
|
||||||
--private-key-file "$OPENPGP_PRIVATE_KEY_FILE" \
|
|
||||||
--private-key-passphrase "$OPENPGP_PASSPHRASE" \
|
|
||||||
--recreate-on-deploy \
|
|
||||||
$AUCTION_OPTS \
|
|
||||||
$LOG_OPTS \
|
|
||||||
$EXTRA_DEPLOY_OPTS \
|
|
||||||
$UPDATE_OPTS \
|
|
||||||
--discover
|
|
||||||
rc=$?
|
|
||||||
if [ $rc -eq 0 ]; then
|
|
||||||
echo "############ DEPLOY SUCCESS #############"
|
|
||||||
else
|
|
||||||
echo "############ DEPLOY FAILURE STATUS $rc #############"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cleanup any build leftovers
|
|
||||||
if [[ "${SYSTEM_PRUNE:-false}" == "true" ]]; then
|
|
||||||
docker system prune --all --force
|
|
||||||
fi
|
|
||||||
if [[ "${WEBAPP_IMAGE_PRUNE:-true}" == "true" ]]; then
|
|
||||||
APP_IMAGES="$(docker image ls --quiet --filter 'reference=laconic-webapp')"
|
|
||||||
DANGLING_IMAGES="$(docker image ls --quiet --filter 'dangling=true')"
|
|
||||||
if [[ -n "$APP_IMAGES" ]] || [[ -n "$DANGLING_IMAGES" ]]; then
|
|
||||||
echo "Pruning images: $APP_IMAGES $DANGLING_IMAGES"
|
|
||||||
docker image rm -f $APP_IMAGES $DANGLING_IMAGES
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
sleep ${CHECK_INTERVAL:-15}
|
|
||||||
done
|
|
@ -108,8 +108,12 @@ export class RegHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deploymentRequestStatus(requestId?: string) {
|
async deploymentRequestStatus(requestId?: string) {
|
||||||
|
console.log('Starting deploymentRequestStatus with requestId:', requestId);
|
||||||
|
|
||||||
const requests: any[] = [];
|
const requests: any[] = [];
|
||||||
const deployments: any[] = [];
|
const deployments: any[] = [];
|
||||||
|
|
||||||
|
// Querying for removal requests
|
||||||
const removalRequests = await this.queryRecords({
|
const removalRequests = await this.queryRecords({
|
||||||
type: 'ApplicationDeploymentRemovalRequest',
|
type: 'ApplicationDeploymentRemovalRequest',
|
||||||
});
|
});
|
||||||
@ -118,53 +122,75 @@ export class RegHelper {
|
|||||||
const request = await this.getRecordById(requestId);
|
const request = await this.getRecordById(requestId);
|
||||||
if (request) {
|
if (request) {
|
||||||
requests.push(request);
|
requests.push(request);
|
||||||
|
console.log('Found request:', request);
|
||||||
|
} else {
|
||||||
|
console.log('Request not found for requestId:', requestId);
|
||||||
}
|
}
|
||||||
deployments.push(...await this.queryRecords({
|
|
||||||
type: 'ApplicationDeploymentRecord', request: requestId
|
const foundDeployments = await this.queryRecords({
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
requests.push(...await this.queryRecords({
|
|
||||||
type: 'ApplicationDeploymentRequest',
|
|
||||||
}));
|
|
||||||
deployments.push(...await this.queryRecords({
|
|
||||||
type: 'ApplicationDeploymentRecord',
|
type: 'ApplicationDeploymentRecord',
|
||||||
}));
|
request: requestId
|
||||||
|
});
|
||||||
|
deployments.push(...foundDeployments);
|
||||||
|
} else {
|
||||||
|
console.log('Fetching all ApplicationDeploymentRequests');
|
||||||
|
const allRequests = await this.queryRecords({
|
||||||
|
type: 'ApplicationDeploymentRequest',
|
||||||
|
});
|
||||||
|
requests.push(...allRequests);
|
||||||
|
console.log('All requests:', allRequests);
|
||||||
|
|
||||||
|
console.log('Fetching all ApplicationDeploymentRecords');
|
||||||
|
const allDeployments = await this.queryRecords({
|
||||||
|
type: 'ApplicationDeploymentRecord',
|
||||||
|
});
|
||||||
|
deployments.push(...allDeployments);
|
||||||
|
console.log('All deployments:', allDeployments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Sorting requests by createTime');
|
||||||
requests.sort((a, b) => a.createTime === b.createTime ? 0 : a.createTime > b.createTime ? 1 : -1,);
|
requests.sort((a, b) => a.createTime === b.createTime ? 0 : a.createTime > b.createTime ? 1 : -1,);
|
||||||
requests.reverse();
|
requests.reverse();
|
||||||
|
console.log('Sorted requests:', requests);
|
||||||
|
|
||||||
const deploymentsByRequest = new Map<string, any>();
|
const deploymentsByRequest = new Map<string, any>();
|
||||||
for (const d of deployments) {
|
for (const d of deployments) {
|
||||||
deploymentsByRequest.set(d.attributes.request, d);
|
deploymentsByRequest.set(d.attributes.request, d);
|
||||||
}
|
}
|
||||||
|
console.log('Deployments by request:', deploymentsByRequest);
|
||||||
|
|
||||||
const removalsByRequest = new Map<string, any>();
|
const removalsByRequest = new Map<string, any>();
|
||||||
for (const rr of removalRequests) {
|
for (const rr of removalRequests) {
|
||||||
if (rr.attributes.request) {
|
if (rr.attributes.request) {
|
||||||
removalsByRequest.set(rr.attributes.request, rr);
|
removalsByRequest.set(rr.attributes.request, rr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('Removals by request:', removalsByRequest);
|
||||||
|
|
||||||
const latestByHostname = new Map<string, any>();
|
const latestByHostname = new Map<string, any>();
|
||||||
|
|
||||||
const ret = [];
|
const ret = [];
|
||||||
for (const r of requests) {
|
for (const r of requests) {
|
||||||
|
console.log('Processing request:', r.id);
|
||||||
const status = new RequestStatus(r.id, r.createTime);
|
const status = new RequestStatus(r.id, r.createTime);
|
||||||
ret.push(status);
|
ret.push(status);
|
||||||
|
|
||||||
const app = await this.getRecord(r.attributes.application);
|
const app = await this.getRecord(r.attributes.application);
|
||||||
if (!app) {
|
if (!app) {
|
||||||
|
console.log('Error: Application not found for request:', r.id);
|
||||||
status.lastState = 'ERROR';
|
status.lastState = 'ERROR';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
status.app = r.attributes.application;
|
status.app = r.attributes.application;
|
||||||
const hostname = r.attributes.dns ?? generateHostnameForApp(app);
|
const hostname = r.attributes.dns ?? generateHostnameForApp(app);
|
||||||
|
console.log('Hostname for app:', hostname);
|
||||||
|
|
||||||
if (deploymentsByRequest.has(r.id)) {
|
if (deploymentsByRequest.has(r.id)) {
|
||||||
const deployment = deploymentsByRequest.get(r.id);
|
const deployment = deploymentsByRequest.get(r.id);
|
||||||
status.url = deployment.attributes.url;
|
status.url = deployment.attributes.url;
|
||||||
status.lastUpdate = deployment.createTime;
|
status.lastUpdate = deployment.createTime;
|
||||||
|
console.log('Deployment found for request:', r.id, 'with deployment:', deployment);
|
||||||
|
|
||||||
if (!latestByHostname.has(hostname)) {
|
if (!latestByHostname.has(hostname)) {
|
||||||
latestByHostname.set(hostname, status);
|
latestByHostname.set(hostname, status);
|
||||||
@ -179,11 +205,13 @@ export class RegHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (removalsByRequest.has(r.id)) {
|
if (removalsByRequest.has(r.id)) {
|
||||||
|
console.log('Removal request found for request:', r.id);
|
||||||
status.lastState = 'CANCELLED';
|
status.lastState = 'CANCELLED';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (latestByHostname.has(hostname)) {
|
if (latestByHostname.has(hostname)) {
|
||||||
|
console.log('Cancellation found for hostname:', hostname);
|
||||||
status.lastState = 'CANCELLED';
|
status.lastState = 'CANCELLED';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -191,6 +219,7 @@ export class RegHelper {
|
|||||||
latestByHostname.set(hostname, status);
|
latestByHostname.set(hostname, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Final status array:', ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user