-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e278d0
commit 0ce45c9
Showing
10 changed files
with
1,026 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var config = {}; | ||
|
||
config.languages = { | ||
'java': { | ||
'name': 'java', | ||
'file': 'Main.java', | ||
'script': 'java.sh', | ||
'docker': 'openjdk:11' | ||
}, | ||
'python': { | ||
'name': 'python', | ||
'file': 'Main.py', | ||
'script': 'python.sh', | ||
'docker': 'python' | ||
}, | ||
'c': { | ||
'name': 'c', | ||
'file': 'Main.c', | ||
'script': 'c.sh', | ||
'docker': 'gcc' | ||
} | ||
} | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,33 @@ | ||
const Docker = require('dockerode'); | ||
const config = require('./config'); | ||
|
||
const express = require("express"); | ||
const app = express(); | ||
const bodyParser = require('body-parser'); | ||
const cors = require('cors'); | ||
|
||
const util = require('util'); | ||
const exec = util.promisify(require('child_process').exec); | ||
|
||
var docker = new Docker({ socketPath: '/var/run/docker.sock' }); | ||
app.use(cors()); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
const run = require('./routes.js'); | ||
app.use('/run', run); | ||
|
||
run(); | ||
var docker = new Docker({ socketPath: '/var/run/docker.sock' }); | ||
|
||
async function run() { | ||
docker.createContainer({ Image: 'myimage1:1.0', name: 'test1' }, (err, container) => { | ||
// Pull all images on startup & make sure all scripts are executable | ||
for (const property in config.languages) { | ||
exec("chmod +x ./languages/" + config.languages[property].script); | ||
docker.pull(config.languages[property].docker, (err, stream) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
exec(`docker cp ./temp/abc.java ${container.id}:Main.java && docker cp ./languages/scripts/java.sh ${container.id}:java.sh`).then((stdout, stderr) => { | ||
container.start((err, data) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
container.attach({ stream: true, stdout: true, stderr: true }, function (err, stream) { | ||
stream.pipe(process.stdout); | ||
sleep(5000).then(() => { | ||
container.kill((err, data) => { | ||
container.remove((err, data) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(data); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
stream.pipe(process.stdout); | ||
}); | ||
} | ||
|
||
function sleep(ms) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} | ||
app.listen(8000, () => { | ||
console.log("Express listening on port 8000"); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
echo "Compiling with gcc..." | ||
gcc -Wall Main.c -o Main | ||
echo "Running c program..." | ||
./Main |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/bash | ||
ls -l | ||
echo "Compiling java program..." | ||
javac Main.java | ||
echo "Running java program..." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
echo "Running python file..." | ||
python3 Main.py |
Oops, something went wrong.