Skip to content

Commit

Permalink
Merge pull request #141 from prona-p4-learning-platform/firecracker-p…
Browse files Browse the repository at this point in the history
…rovider

Firecracker provider, closes #7 and #94
  • Loading branch information
srieger1 authored Oct 23, 2023
2 parents 1f3a734 + 61750a4 commit ad32807
Show file tree
Hide file tree
Showing 6 changed files with 959 additions and 54 deletions.
9 changes: 6 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"start:localmultiuservm": "ts-node src/LocalMultiuserVMApplication.ts",
"start:openstack": "ts-node src/OpenStackApplication.ts",
"start:docker": "ts-node src/DockerApplication.ts",
"start:firecracker": "ts-node --files src/FirecrackerApplication.ts",
"lint": "eslint src/**/**/*.{js,ts,tsx}",
"compile": "tsc --noEmit"
},
Expand All @@ -25,8 +26,9 @@
"@types/dockerode": "^3.3.15",
"@types/express": "^4.17.17",
"@types/jest": "^29.4.0",
"@types/jsonwebtoken": "^9.0.1",
"@types/jsonwebtoken": "^9.0.2",
"@types/mongodb": "^3.6.20",
"@types/netmask": "^2.0.2",
"@types/node": "^18.14.5",
"@types/ssh2": "^0.5.52",
"@types/supertest": "^2.0.10",
Expand All @@ -41,7 +43,7 @@
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.1.6"
},
"dependencies": {
"axios": "^0.26.1",
Expand All @@ -52,10 +54,11 @@
"dockerode": "^3.3.4",
"jsonwebtoken": "^9.0.0",
"mongodb": "^3.7.3",
"netmask": "^2.0.2",
"node-pty": "^0.10.1",
"npm": "^9.6.2",
"path-to-regexp": "^6.2.1",
"ssh2": "^1.11.0",
"ssh2": "^1.14.0",
"toad-scheduler": "^2.2.0",
"ws": "^8.13.0"
}
Expand Down
15 changes: 15 additions & 0 deletions backend/src/FirecrackerApplication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import api from "./Api";
import serverCreator from "./Server";
import MongoDBPersister from "./database/MongoDBPersister";
import MongoDBAuthenticationProvider from "./authentication/MongoDBAuthenticationProvider";
import FirecrackerProvider from "./providers/FirecrackerProvider";

const persister = new MongoDBPersister(process.env.MONGODB_URL);
console.log("Attempting to start Firecracker Application.");
serverCreator(
api(
persister,
[new MongoDBAuthenticationProvider(persister)],
new FirecrackerProvider()
)
);
28 changes: 26 additions & 2 deletions backend/src/providers/DockerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,28 @@ export default class DockerProvider implements InstanceProvider {
timestampCreated +
" and should be deleted"
);
Environment.deleteInstanceEnvironments(container.Id);
this.deleteServer(container.Id)
.then(() => {
console.log(
"Deleted expired container" +
container.Names +
" expiration date: " +
timestampCreated +
" deadline: " +
deadline
);
Environment.deleteInstanceEnvironments(container.Id);
})
.catch((err) => {
return reject(
new Error(
"DockerProvider: Failed to delete container to be pruned. " +
container.Names +
" " +
err
)
);
});
}
}
});
Expand Down Expand Up @@ -408,7 +429,7 @@ export default class DockerProvider implements InstanceProvider {
rejected = true;
return reject(
new Error(
"DockerProvider: Container was not stated. Check image and cmd used to init the container."
"DockerProvider: Container was not started. Check image and cmd used to init the container."
)
);
} else {
Expand Down Expand Up @@ -472,10 +493,12 @@ export default class DockerProvider implements InstanceProvider {
const sshConn = new Client();
sshConn
.on("ready", () => {
sshConn.end();
resolved = true;
return resolve();
})
.on("error", (err) => {
sshConn.end();
console.log(
"DockerProvider: SSH connection failed - retrying..." + err
);
Expand All @@ -485,6 +508,7 @@ export default class DockerProvider implements InstanceProvider {
port: port,
username: process.env.SSH_USERNAME,
password: process.env.SSH_PASSWORD,
readyTimeout: 1000,
});
await providerInstance.sleep(1000);
timeout -= 1;
Expand Down
Loading

0 comments on commit ad32807

Please sign in to comment.