@@ -2,7 +2,7 @@ const os = require('os')
2
2
const chalk = require ( 'chalk' )
3
3
const fetch = require ( 'node-fetch' )
4
4
const semver = require ( 'semver' )
5
- const { exec } = require ( 'child_process' )
5
+ const { spawn , exec } = require ( 'child_process' )
6
6
const fs = require ( 'fs' )
7
7
8
8
const HELP = `
@@ -11,8 +11,9 @@ ${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>
11
11
${ chalk . dim ( 'Options:' ) }
12
12
-h, --help Show usage information
13
13
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
14
- -c , --flags <flags>
14
+ -f , --flags <flags>
15
15
`
16
+ // -r, --root The root folder of the subgraph project. Default is the folder where the 'graph test' command is executed from.
16
17
17
18
module . exports = {
18
19
description : 'Runs rust binary for subgraph testing' ,
@@ -97,38 +98,45 @@ CMD ../binary-linux-20 \${ARGS}
97
98
}
98
99
} )
99
100
100
- exec ( `docker build -t matchstick .` , ( error , stdout , stderr ) => {
101
- print . info ( 'Building Matchstick image...' ) ;
101
+ // TODO:
102
+ // 1. Check if image exists - done
103
+ // 2. Check if ARGS are passed. Add them to the options there are ARGS - done
104
+ // ?? 3. Add option to pass root/host folder
102
105
103
- if ( error ) {
104
- print . info ( 'A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.' ) ;
105
- print . info ( `error: ${ error . message } ` )
106
+ exec ( 'docker images -q matchstick' , ( error , stdout , stderr ) => {
107
+ let current_folder = process . cwd ( ) ;
108
+ let args = '' ;
109
+
110
+ if ( datasource ) {
111
+ args = args + datasource
106
112
}
107
- if ( stderr ) {
108
- print . info ( 'A problem occurred while trying to build the Matchstick Docker image. Please attend to the errors below.' ) ;
109
- print . info ( `stderr: ${ stderr } ` )
113
+
114
+ if ( coverage ) {
115
+ args = args + ' ' + '-c'
110
116
}
111
117
112
- //docker run -it --rm --mount type=bind,source=$PWD,target=/matchstick -e ARGS="-c" matchstick
113
- let runCommand = `docker run --rm --mount type=bind,source=$PWD,target=/matchstick -e ARGS="${ datasource || '' } ${ coverage ? '-c' : '' } " matchstick` ;
114
-
115
- exec ( runCommand , ( error , stdout , stderr ) => {
116
- print . info ( 'Running Matchstick image...' ) ;
117
-
118
- if ( error ) {
119
- print . info ( 'A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.' ) ;
120
- print . info ( `error: ${ error . message } ` )
121
- process . exit ( 1 ) ;
122
- }
123
- if ( stderr ) {
124
- print . info ( 'A problem occurred while trying to run the Matchstick Docker image. Please attend to the errors below.' ) ;
125
- print . info ( `stderr: ${ stderr } ` )
126
- process . exit ( 1 ) ;
127
- }
128
- print . info ( stdout )
129
- process . exit ( ) ;
130
- } )
131
- } )
118
+ let options = [ 'run' , '-it' , '--rm' , '--mount' , `type=bind,source=${ current_folder } ,target=/matchstick` ] ;
119
+
120
+ if ( args !== '' ) {
121
+ options . push ( '-e' )
122
+ options . push ( `ARGS=${ args } ` ) ;
123
+ }
132
124
125
+ options . push ( 'matchstick' )
126
+
127
+ if ( stdout === "" ) {
128
+ spawn (
129
+ 'docker' ,
130
+ [ 'build' , '-f' , 'tests/.docker/Dockerfile' , '-t' , 'matchstick' , '.' ] ,
131
+ { stdio : 'inherit' }
132
+ ) . on ( 'close' , code => {
133
+ if ( code === 0 ) {
134
+ spawn ( 'docker' , options , { stdio : 'inherit' } ) ;
135
+ }
136
+ } )
137
+ } else {
138
+ spawn ( 'docker' , options , { stdio : 'inherit' } ) ;
139
+ }
140
+ } )
133
141
} ,
134
- }
142
+ }
0 commit comments