Handle deployment auctions in a separate process #21

Merged
ashwin merged 3 commits from deep-stack/webapp-deployment-status-api:pm-separate-auctions into main 2024-10-25 09:00:47 +00:00
5 changed files with 60 additions and 21 deletions
Showing only changes of commit 3bd5de4b18 - Show all commits

View File

@ -44,5 +44,5 @@ COPY . /app/
WORKDIR /app/
RUN rm -rf node_modules && yarn && yarn clean && yarn build:release
COPY run.sh .
CMD ["./run.sh"]
COPY scripts .
CMD ["./scripts/run.sh"]

View File

@ -133,6 +133,9 @@ OPENPGP_PASSPHRASE="SECRET"
OPENPGP_PRIVATE_KEY_FILE="/etc/config/webapp-deployer-api.my.domain.com.pgp.key"
LACONIC_CONFIG="/etc/config/registry.yml"
LRN=lrn://laconic/deployers/webapp-deployer-api.my.domain.com
CHECK_INTERVAL=15
AUCTION_CHECK_INTERVAL=10
HANDLE_AUCTION_REQUESTS=true
AUCTION_BID_AMOUNT=50000
```

View File

@ -8,6 +8,14 @@ services:
ports:
- 9555
cerc-webapp-auction-handler:
image: cerc/webapp-deployer-backend:local
restart: always
volumes:
- srv:/srv
- config:/etc/config:ro
command: "./scripts/handle-auctions.sh"
volumes:
config:
srv:

44
scripts/handle-auctions.sh Executable file
View File

@ -0,0 +1,44 @@
#!/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, exiting..."
exit 0
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

View File

@ -37,11 +37,6 @@ 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
@ -49,6 +44,7 @@ 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}"
@ -126,6 +122,7 @@ while true; do
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 \
@ -148,6 +145,7 @@ while true; do
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} \
@ -174,20 +172,6 @@ while true; do
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