Skip to content

Commit

Permalink
Pre-registration process (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Rodríguez Baquero authored Jul 18, 2023
1 parent 53ee509 commit c262a44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
25 changes: 23 additions & 2 deletions container/shim/src/modules/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export async function register(initial = false) {

verifyHWRequirements(requirements, stats);

if (initial) {
await sendPreRegisterRequest(postOptions({ nodeId: NODE_ID }));
}

if (VERSION !== DEV_VERSION && initial) {
let speedtest;
try {
Expand Down Expand Up @@ -218,7 +222,6 @@ async function sendRegisterRequest(initial, registerOptions) {
);

if (!success) {
debug(error);
throw new Error(error);
}

Expand All @@ -235,14 +238,32 @@ async function sendRegisterRequest(initial, registerOptions) {

if (initial) prefillCache();
} catch (err) {
debug("Failed registration %s", err.message);
debug("Failed registration: %s", err.message);
if (initial) {
// we don't try again if we fail the initial registration
process.exit(0);
}
}
}

async function sendPreRegisterRequest(postOptions) {
debug("Pre-registering with orchestrator");

try {
const res = await fetch(`${ORCHESTRATOR_URL}/pre-register`, postOptions);

if (!res.ok) {
throw new Error(await res.text());
}

debug("Successful pre-registration");
} catch (err) {
debug("Failed pre-registration: %s", err.message);
// we don't try again if we fail the pre-registration
process.exit(0);
}
}

let deregistering;
export async function deregister() {
if (!ORCHESTRATOR_REGISTRATION) return;
Expand Down
7 changes: 0 additions & 7 deletions container/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ echo "$(date -u) [container] Disk: $(df -h /usr/src/app/shared | awk '(NR>1)')"
mkdir -p /usr/src/app/shared/ssl
mkdir -p /usr/src/app/shared/nginx_log

# Clean up old cached CAR files if not already cleaned up
if [ ! -f "/usr/src/app/shared/cleaned_cache" ]; then
echo "$(date -u) [container] Cleaning up old cached CAR files"
grep -rl '/usr/src/app/shared/nginx_cache' -e 'carentity' -e 'carall' | xargs rm -f
touch /usr/src/app/shared/cleaned_cache
fi

L1_CONF_FILE=/etc/nginx/conf.d/L1.conf

# If we have a cert, start nginx with TLS, else without (but always start the shim)
Expand Down

0 comments on commit c262a44

Please sign in to comment.