Handle deployment auctions in a separate process (#21)
Part of [Service provider auctions for web deployments](https://www.notion.so/Service-provider-auctions-for-web-deployments-104a6b22d47280dbad51d28aa3a91d75) and cerc-io/stack-orchestrator#948 Requires cerc-io/stack-orchestrator#957 Reviewed-on: #21 Reviewed-by: ashwin <ashwin@noreply.git.vdb.to> Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
parent
16276e80d0
commit
cad9406579
@ -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 run.sh .
|
COPY scripts .
|
||||||
CMD ["./run.sh"]
|
CMD ["./scripts/run.sh"]
|
||||||
|
@ -133,6 +133,9 @@ 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,6 +8,15 @@ 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:
|
||||||
|
47
scripts/handle-auctions.sh
Executable file
47
scripts/handle-auctions.sh
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
#!/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
|
@ -1,5 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$RUN_AUCTIONS_HANDLER" = "true" ]; then
|
||||||
|
exec "./scripts/handle-auctions.sh"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
function is_privileged {
|
function is_privileged {
|
||||||
ip link add dummy0 type dummy >/dev/null
|
ip link add dummy0 type dummy >/dev/null
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
@ -37,11 +42,6 @@ fi
|
|||||||
|
|
||||||
AUCTION_OPTS=""
|
AUCTION_OPTS=""
|
||||||
if [ "$HANDLE_AUCTION_REQUESTS" = "true" ]; then
|
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"
|
AUCTION_OPTS="--auction-requests"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ STORAGE_ROOT="${STORAGE_ROOT:-/srv}"
|
|||||||
DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-$STORAGE_ROOT/deployments}"
|
DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-$STORAGE_ROOT/deployments}"
|
||||||
LOG_DIR="${LOG_DIR:-$STORAGE_ROOT/logs}"
|
LOG_DIR="${LOG_DIR:-$STORAGE_ROOT/logs}"
|
||||||
CONTAINERS_DIR="${CONTAINER_DIR:-$STORAGE_ROOT/containers}"
|
CONTAINERS_DIR="${CONTAINER_DIR:-$STORAGE_ROOT/containers}"
|
||||||
|
REGISTRY_LOCK_FILE="${REGISTRY_LOCK_FILE:-/srv/registry_mutex_lock_file}"
|
||||||
|
|
||||||
if [[ ! -d "${DEPLOYMENTS_DIR}" ]]; then
|
if [[ ! -d "${DEPLOYMENTS_DIR}" ]]; then
|
||||||
mkdir -p "${DEPLOYMENTS_DIR}"
|
mkdir -p "${DEPLOYMENTS_DIR}"
|
||||||
@ -126,6 +127,7 @@ while true; do
|
|||||||
echo "########### UNDEPLOY ############"
|
echo "########### UNDEPLOY ############"
|
||||||
laconic-so undeploy-webapp-from-registry \
|
laconic-so undeploy-webapp-from-registry \
|
||||||
--laconic-config /etc/config/laconic.yml \
|
--laconic-config /etc/config/laconic.yml \
|
||||||
|
--registry-lock-file "${REGISTRY_LOCK_FILE}" \
|
||||||
--deployment-parent-dir "${DEPLOYMENTS_DIR}" \
|
--deployment-parent-dir "${DEPLOYMENTS_DIR}" \
|
||||||
--delete-names \
|
--delete-names \
|
||||||
--delete-volumes \
|
--delete-volumes \
|
||||||
@ -148,6 +150,7 @@ while true; do
|
|||||||
laconic-so deploy-webapp-from-registry \
|
laconic-so deploy-webapp-from-registry \
|
||||||
--kube-config /etc/config/kube.yml \
|
--kube-config /etc/config/kube.yml \
|
||||||
--laconic-config /etc/config/laconic.yml \
|
--laconic-config /etc/config/laconic.yml \
|
||||||
|
--registry-lock-file "${REGISTRY_LOCK_FILE}" \
|
||||||
--image-registry ${IMAGE_REGISTRY} \
|
--image-registry ${IMAGE_REGISTRY} \
|
||||||
--deployment-parent-dir "${DEPLOYMENTS_DIR}" \
|
--deployment-parent-dir "${DEPLOYMENTS_DIR}" \
|
||||||
--dns-suffix ${DEPLOYMENT_DNS_SUFFIX} \
|
--dns-suffix ${DEPLOYMENT_DNS_SUFFIX} \
|
||||||
@ -174,20 +177,6 @@ while true; do
|
|||||||
echo "############ DEPLOY FAILURE STATUS $rc #############"
|
echo "############ DEPLOY FAILURE STATUS $rc #############"
|
||||||
fi
|
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
|
# Cleanup any build leftovers
|
||||||
if [[ "${SYSTEM_PRUNE:-false}" == "true" ]]; then
|
if [[ "${SYSTEM_PRUNE:-false}" == "true" ]]; then
|
||||||
docker system prune --all --force
|
docker system prune --all --force
|
Loading…
Reference in New Issue
Block a user