From 3bd5de4b18775071e441fc42e252ab209e6daa63 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 24 Oct 2024 15:54:02 +0530 Subject: [PATCH 1/3] Handle deployment auctions in a separate process --- Dockerfile | 4 ++-- README.md | 3 +++ docker-compose.yml | 8 +++++++ scripts/handle-auctions.sh | 44 ++++++++++++++++++++++++++++++++++++++ run.sh => scripts/run.sh | 22 +++---------------- 5 files changed, 60 insertions(+), 21 deletions(-) create mode 100755 scripts/handle-auctions.sh rename run.sh => scripts/run.sh (89%) diff --git a/Dockerfile b/Dockerfile index 4bc7726..0547004 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 3a7d448..054c398 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/docker-compose.yml b/docker-compose.yml index c85a262..6269b35 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/scripts/handle-auctions.sh b/scripts/handle-auctions.sh new file mode 100755 index 0000000..6a583ce --- /dev/null +++ b/scripts/handle-auctions.sh @@ -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 diff --git a/run.sh b/scripts/run.sh similarity index 89% rename from run.sh rename to scripts/run.sh index 8b144ed..ba063e5 100755 --- a/run.sh +++ b/scripts/run.sh @@ -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 -- 2.45.2 From 07f6d5a0c9cc096c8e2ebdb99addf8804915cff3 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 24 Oct 2024 18:46:35 +0530 Subject: [PATCH 2/3] Run auction handler script from main script --- docker-compose.yml | 3 ++- scripts/handle-auctions.sh | 7 +++++-- scripts/run.sh | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6269b35..5876c43 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,10 +11,11 @@ services: cerc-webapp-auction-handler: image: cerc/webapp-deployer-backend:local restart: always + environment: + RUN_AUCTIONS_HANDLER: "true" volumes: - srv:/srv - config:/etc/config:ro - command: "./scripts/handle-auctions.sh" volumes: config: diff --git a/scripts/handle-auctions.sh b/scripts/handle-auctions.sh index 6a583ce..915d80e 100755 --- a/scripts/handle-auctions.sh +++ b/scripts/handle-auctions.sh @@ -11,8 +11,11 @@ if [ "$HANDLE_AUCTION_REQUESTS" = "true" ]; then exit 2 fi else - echo "Not handling auction requests, exiting..." - exit 0 + 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}" diff --git a/scripts/run.sh b/scripts/run.sh index ba063e5..b95241f 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$RUN_AUCTIONS_HANDLER" = "true" ]; then + exec "./scripts/handle-auctions.sh" +fi + function is_privileged { ip link add dummy0 type dummy >/dev/null if [[ $? -eq 0 ]]; then -- 2.45.2 From a65c01a42334ecac9ce2c7441991bb6732370d60 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 25 Oct 2024 14:14:35 +0530 Subject: [PATCH 3/3] Exit after running auction handler script --- scripts/run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/run.sh b/scripts/run.sh index b95241f..a9bdb4e 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -2,6 +2,7 @@ if [ "$RUN_AUCTIONS_HANDLER" = "true" ]; then exec "./scripts/handle-auctions.sh" + exit fi function is_privileged { -- 2.45.2