Skip to content

Commit 41287a8

Browse files
committed
Build executer's Docker images only when building tracers libraries
1 parent 4c92a2a commit 41287a8

File tree

6 files changed

+56
-45
lines changed

6 files changed

+56
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [2.0.2]
10+
### Fixed
11+
- Build executer's Docker images only when building tracers libraries
12+
913
## [2.0.1]
1014
### Added
1115
- Dockerize the building process.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@algorithm-visualizer/tracer-generator",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Visualization Libraries for Algorithm Visualizer",
55
"scripts": {
66
"build": "node ./node_modules/webpack/bin/webpack --bail --progress --config webpack.config.js && chmod +x ./bin/*"

src/languages/Builder.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import path from 'path';
22
import fs from 'fs-extra';
3-
import Promise from 'bluebird';
43
import * as tracers from '/specs/tracers';
54
import * as randomizers from '/specs/randomizers';
65
import { execute } from '/common/util';
6+
import Commander from '/languages/Commander';
77

8-
class Builder {
8+
class Builder extends Commander {
99
constructor({ name, commands }) {
10-
this.name = name;
10+
super({ name });
1111
this.commands = commands;
1212
this.build = this.build.bind(this);
1313
}
1414

15-
get cwd() {
16-
return path.resolve(__dirname, this.name);
17-
}
18-
1915
spec(callback, all = false) {
2016
Object.values(all ? { ...tracers, ...randomizers } : tracers).forEach(tracer => {
2117
const { name, content } = callback(tracer);
@@ -33,23 +29,25 @@ class Builder {
3329
}
3430

3531
build() {
36-
const command = this.commands.join(' && ');
37-
if (fs.existsSync(path.resolve(this.cwd, 'builder', 'Dockerfile'))) {
38-
const imageTag = `${this.name}-builder`;
39-
return execute(`docker build -t ${imageTag} ./builder`, this.cwd)
40-
.then(() => execute([
41-
`docker run --rm`,
42-
'-w=/usr/tracers',
43-
`-v=$PWD/tracers:/usr/tracers:rw`,
44-
imageTag,
45-
'/bin/bash -c',
46-
`"${command}"`,
47-
].join(' '), this.cwd));
48-
} else if (command) {
49-
return execute(command, path.resolve(this.cwd, 'tracers'));
50-
} else {
51-
return Promise.resolve();
52-
}
32+
return fs.pathExists(path.resolve(this.cwd, 'builder', 'Dockerfile'))
33+
.then(exists => {
34+
const command = this.commands.join(' && ');
35+
if (exists) {
36+
return execute(`docker build -t ${this.builderImageTag} ./builder`, this.cwd)
37+
.then(() => execute([
38+
`docker run --rm`,
39+
'-w=/usr/tracers',
40+
`-v=$PWD/tracers:/usr/tracers:rw`,
41+
this.builderImageTag,
42+
'/bin/bash -c',
43+
`"${command}"`,
44+
].join(' '), this.cwd));
45+
} else if (command) {
46+
return execute(command, path.resolve(this.cwd, 'tracers'));
47+
}
48+
})
49+
.then(() => fs.pathExists(path.resolve(this.cwd, 'executer', 'Dockerfile')))
50+
.then(exists => exists && execute(`docker build -t ${this.executerImageTag} ./executer`, this.cwd));
5351
}
5452
}
5553

src/languages/Commander.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import path from 'path';
2+
3+
class Commander {
4+
constructor({ name }) {
5+
this.name = name;
6+
this.builderImageTag = `${this.name}-builder`;
7+
this.executerImageTag = `${this.name}-executer`;
8+
}
9+
10+
get cwd() {
11+
return path.resolve(__dirname, this.name);
12+
}
13+
}
14+
15+
export default Commander;

src/languages/Exeuter.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
1-
import path from 'path';
21
import { execute } from '/common/util';
2+
import Commander from '/languages/Commander';
33

4-
class Executer {
4+
class Executer extends Commander {
55
constructor({ name, compileCommand, runCommand }) {
6-
this.name = name;
6+
super({ name });
77
this.compileCommand = compileCommand;
88
this.runCommand = runCommand;
99
this.compile = this.compile.bind(this);
1010
this.run = this.run.bind(this);
1111
}
1212

13-
get cwd() {
14-
return path.resolve(__dirname, this.name);
15-
}
16-
1713
execute(tempPath, command) {
18-
const imageTag = `${this.name}-executer`;
19-
return execute(`docker build -t ${imageTag} ./executer`, this.cwd)
2014
// TODO: memory limit + time limit + space limit?
21-
.then(() => execute([
22-
`docker run --rm`,
23-
'-w=/usr/judge',
24-
`-v=$PWD/tracers:/usr/bin/tracers:ro`,
25-
`-v=${tempPath}:/usr/judge:rw`,
26-
`-e MAX_TRACES=${1e6} -e MAX_TRACERS=${1e2}`, // Load from /common/config
27-
imageTag,
28-
`"${command}"`,
29-
].join(' '), this.cwd));
15+
return execute([
16+
`docker run --rm`,
17+
'-w=/usr/judge',
18+
`-v=$PWD/tracers:/usr/bin/tracers:ro`,
19+
`-v=${tempPath}:/usr/judge:rw`,
20+
`-e MAX_TRACES=${1e6} -e MAX_TRACERS=${1e2}`, // TODO: load from /common/config
21+
this.executerImageTag,
22+
'/bin/bash -c',
23+
`"${command}"`,
24+
].join(' '), this.cwd);
3025
}
3126

3227
compile(tempPath) {

src/languages/cpp/tracers/include/Randomize.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ namespace Randomize {
1414
Randomizer() {
1515
}
1616

17-
virtual T create() {
18-
}
17+
virtual T create() = 0;
1918
};
2019

2120

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy