@@ -6,14 +6,14 @@ const { spawn, exec } = require('child_process')
6
6
const fs = require ( 'fs' )
7
7
8
8
const HELP = `
9
- ${ chalk . bold ( 'graph test' ) } ${ chalk . dim ( '[options] ') } ${ chalk . bold ( '<datasource> ') }
9
+ ${ chalk . bold ( 'graph test' ) } ${ chalk . bold ( '<datasource> ') } ${ chalk . dim ( '[options] ') }
10
10
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, --coverage Run tests in coverage mode
14
15
-f, --flags <flags>
15
16
`
16
- // -r, --root The root folder of the subgraph project. Default is the folder where the 'graph test' command is executed from.
17
17
18
18
module . exports = {
19
19
description : 'Runs rust binary for subgraph testing' ,
@@ -98,12 +98,14 @@ CMD ../binary-linux-20 \${ARGS}
98
98
}
99
99
} )
100
100
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
101
+ // TODOs:
102
+ // 1. Fix true/false options with gluegun.
103
+ // 2. If -v/--version is passed, delete current image and build again.
105
104
105
+ // Run a command to check if matchstick image already exists
106
106
exec ( 'docker images -q matchstick' , ( error , stdout , stderr ) => {
107
+ // Getting the current working folder that will be passed to the
108
+ // `docker run` command to be bind mounted.
107
109
let current_folder = process . cwd ( ) ;
108
110
let args = '' ;
109
111
@@ -119,12 +121,17 @@ CMD ../binary-linux-20 \${ARGS}
119
121
120
122
if ( args !== '' ) {
121
123
options . push ( '-e' )
122
- options . push ( `ARGS=${ args } ` ) ;
124
+ options . push ( `ARGS=${ args . trim ( ) } ` ) ;
123
125
}
124
126
125
127
options . push ( 'matchstick' )
126
128
129
+ // If a matchstick image does not exists, the command returns an empty string,
130
+ // else it'll return the image ID. Skip `docker build` if an image already exists
131
+ // Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
127
132
if ( stdout === "" ) {
133
+ // Build a docker image. If the process has executed successfully
134
+ // run a container from that image.
128
135
spawn (
129
136
'docker' ,
130
137
[ 'build' , '-f' , 'tests/.docker/Dockerfile' , '-t' , 'matchstick' , '.' ] ,
@@ -135,6 +142,7 @@ CMD ../binary-linux-20 \${ARGS}
135
142
}
136
143
} )
137
144
} else {
145
+ // Run the container from the existing matchstick docker image
138
146
spawn ( 'docker' , options , { stdio : 'inherit' } ) ;
139
147
}
140
148
} )
0 commit comments