Skip to content

Commit 36e4f25

Browse files
committed
Update
1 parent acba592 commit 36e4f25

File tree

8 files changed

+226
-0
lines changed

8 files changed

+226
-0
lines changed

.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/graph-cli.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/test-docker.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const os = require('os')
2+
const chalk = require('chalk')
3+
const fetch = require('node-fetch')
4+
const semver = require('semver')
5+
const { exec } = require('child_process')
6+
const fs = require('fs')
7+
8+
const HELP = `
9+
${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
10+
11+
${chalk.dim('Options:')}
12+
-h, --help Show usage information
13+
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
14+
-c, --flags <flags>
15+
`
16+
17+
module.exports = {
18+
description: 'Runs rust binary for subgraph testing',
19+
run: async toolbox => {
20+
// Obtain tools
21+
let { print } = toolbox
22+
23+
// Read CLI parameters
24+
let { h, help, v, version, c, coverage, l, lib } = toolbox.parameters.options
25+
let datasource = toolbox.parameters.first
26+
27+
// Support both long and short option variants
28+
help = help || h
29+
version = version || v
30+
coverage = coverage || c
31+
32+
// Show help text if requested
33+
if (help) {
34+
print.info(HELP)
35+
return
36+
}
37+
38+
if(version) {
39+
let url = `https://github.com/LimeChain/matchstick/releases/download/${version || "0.2.0"}/binary-linux-20`;
40+
41+
let res = await fetch(url)
42+
.then(response => {
43+
if (response.status === 404){
44+
print.info(`Error: Invalid Matchstick version '${version}'`);
45+
process.exit(1);
46+
}
47+
})
48+
}
49+
50+
// TODO: Move these in separate file (in a function maybe)
51+
let contents = `FROM ubuntu:20.04
52+
ENV ARGS=""
53+
RUN apt update
54+
RUN apt install -y nodejs
55+
RUN apt install -y npm
56+
COPY ./ ./
57+
RUN npm run codegen
58+
RUN npm run build
59+
RUN apt install -y postgresql
60+
RUN apt install -y curl
61+
RUN apt-get update && apt-get -y install cmake protobuf-compiler
62+
RUN curl -OL https://github.com/LimeChain/matchstick/releases/download/${version || "0.2.1a"}/binary-linux-20
63+
RUN mv binary-linux-20 matchstick
64+
RUN chmod a+x matchstick
65+
CMD ./matchstick \${ARGS}`
66+
67+
let dir = 'tests/.docker';
68+
69+
if (!fs.existsSync(dir)){
70+
fs.mkdirSync(dir, { recursive: true });
71+
}
72+
73+
fs.writeFileSync('tests/.docker/Dockerfile', contents, (err) => {
74+
if (err) {
75+
print.info('A problem occurred while generating the Dockerfile. Please attend to the errors below.');
76+
print.info(err);
77+
}
78+
else {
79+
print.info('Successfully generated Dockerfile.')
80+
}
81+
})
82+
83+
exec(`docker build -f tests/.docker/Dockerfile -t matchstick . `, (error, stdout, stderr) => {
84+
print.info('Building Matchstick image...');
85+
86+
if (error) {
87+
print.info('A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.');
88+
print.info(`error: ${error.message}`)
89+
}
90+
if (stderr) {
91+
print.info('A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.');
92+
print.info(`stderr: ${stderr}`)
93+
}
94+
95+
let runCommand = `docker run -e ARGS="${datasource || ""}${coverage ? "-c" : ""}" --rm matchstick`;
96+
97+
console.log("runCommand output");
98+
console.log(runCommand);
99+
print.info("runCommand output");
100+
print.info(runCommand);
101+
102+
exec(runCommand, (error, stdout, stderr) => {
103+
print.info('Running Matchstick image...');
104+
105+
if (error) {
106+
print.info('A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.');
107+
print.info(`error: ${error.message}`)
108+
process.exit(1);
109+
}
110+
if (stderr) {
111+
print.info('A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.');
112+
print.info(`stderr: ${stderr}`)
113+
process.exit(1);
114+
}
115+
print.info(stdout)
116+
process.exit();
117+
})
118+
})
119+
120+
},
121+
}

0 commit comments

Comments
 (0)