Add logs to debug why api is not working
This commit is contained in:
parent
16276e80d0
commit
d696169370
176
run.sh
176
run.sh
@ -109,96 +109,96 @@ if [[ -n "$IMAGE_REGISTRY_CREDS" ]]; then
|
||||
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
|
||||
# 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 "=============================================================="
|
||||
# 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 "########### 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
|
||||
# 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
|
||||
# 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
|
||||
# # 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,63 +108,93 @@ export class RegHelper {
|
||||
}
|
||||
|
||||
async deploymentRequestStatus(requestId?: string) {
|
||||
console.log('Starting deploymentRequestStatus with requestId:', requestId);
|
||||
|
||||
const requests: any[] = [];
|
||||
const deployments: any[] = [];
|
||||
|
||||
// Querying for removal requests
|
||||
const removalRequests = await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRemovalRequest',
|
||||
});
|
||||
console.log('Removal requests:', removalRequests);
|
||||
|
||||
if (requestId) {
|
||||
console.log('Fetching request by ID:', requestId);
|
||||
const request = await this.getRecordById(requestId);
|
||||
if (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
|
||||
}));
|
||||
} else {
|
||||
requests.push(...await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRequest',
|
||||
}));
|
||||
deployments.push(...await this.queryRecords({
|
||||
|
||||
console.log('Fetching deployments for request:', requestId);
|
||||
const foundDeployments = await this.queryRecords({
|
||||
type: 'ApplicationDeploymentRecord',
|
||||
}));
|
||||
request: requestId
|
||||
});
|
||||
deployments.push(...foundDeployments);
|
||||
console.log('Deployments for request:', 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.reverse();
|
||||
console.log('Sorted requests:', requests);
|
||||
|
||||
const deploymentsByRequest = new Map<string, any>();
|
||||
for (const d of deployments) {
|
||||
deploymentsByRequest.set(d.attributes.request, d);
|
||||
}
|
||||
console.log('Deployments by request:', deploymentsByRequest);
|
||||
|
||||
const removalsByRequest = new Map<string, any>();
|
||||
for (const rr of removalRequests) {
|
||||
if (rr.attributes.request) {
|
||||
removalsByRequest.set(rr.attributes.request, rr);
|
||||
}
|
||||
}
|
||||
console.log('Removals by request:', removalsByRequest);
|
||||
|
||||
const latestByHostname = new Map<string, any>();
|
||||
|
||||
const ret = [];
|
||||
for (const r of requests) {
|
||||
console.log('Processing request:', r.id);
|
||||
const status = new RequestStatus(r.id, r.createTime);
|
||||
ret.push(status);
|
||||
|
||||
const app = await this.getRecord(r.attributes.application);
|
||||
if (!app) {
|
||||
console.log('Error: Application not found for request:', r.id);
|
||||
status.lastState = 'ERROR';
|
||||
continue;
|
||||
}
|
||||
|
||||
status.app = r.attributes.application;
|
||||
const hostname = r.attributes.dns ?? generateHostnameForApp(app);
|
||||
console.log('Hostname for app:', hostname);
|
||||
|
||||
if (deploymentsByRequest.has(r.id)) {
|
||||
const deployment = deploymentsByRequest.get(r.id);
|
||||
status.url = deployment.attributes.url;
|
||||
status.lastUpdate = deployment.createTime;
|
||||
console.log('Deployment found for request:', r.id, 'with deployment:', deployment);
|
||||
|
||||
if (!latestByHostname.has(hostname)) {
|
||||
latestByHostname.set(hostname, status);
|
||||
@ -179,11 +209,13 @@ export class RegHelper {
|
||||
}
|
||||
|
||||
if (removalsByRequest.has(r.id)) {
|
||||
console.log('Removal request found for request:', r.id);
|
||||
status.lastState = 'CANCELLED';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (latestByHostname.has(hostname)) {
|
||||
console.log('Cancellation found for hostname:', hostname);
|
||||
status.lastState = 'CANCELLED';
|
||||
continue;
|
||||
}
|
||||
@ -191,6 +223,7 @@ export class RegHelper {
|
||||
latestByHostname.set(hostname, status);
|
||||
}
|
||||
|
||||
console.log('Final status array:', ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user