@@ -8,11 +8,17 @@ const authManager = require('../../../../logic').auth.manager;
8
8
const Docker = require ( 'dockerode' ) ;
9
9
const { validatePipelineYaml } = require ( '../../helpers/validation' ) ;
10
10
const { printResult } = require ( '../root/validate.cmd' ) ;
11
-
11
+ const DEFAULTS = require ( '../../defaults' ) ;
12
+ const path = require ( 'path' ) ;
12
13
const regex = / # # [ 0 - 9 a - f ] { 24 } # # / i;
13
14
const imageName = 'codefresh/engine:master' ;
14
15
15
16
17
+ function _customizer ( objValue , srcValue ) {
18
+ if ( Array . isArray ( objValue ) ) {
19
+ return _ . compact ( objValue . concat ( srcValue ) ) ;
20
+ }
21
+ }
16
22
const run = new Command ( {
17
23
root : true ,
18
24
command : 'run <name>' ,
@@ -70,6 +76,10 @@ const run = new Command({
70
76
type : Boolean ,
71
77
default : false ,
72
78
} )
79
+ . option ( 'local-volume' , {
80
+ describe : 'Use your file system as volume in local run' ,
81
+ alias : 'vl' ,
82
+ } )
73
83
. example ( 'codefresh run PIPELINE_ID | PIPELINE_NAME -b=master' , 'Defining the source control context using a branch' )
74
84
. example ( 'codefresh run PIPELINE_ID | PIPELINE_NAME -s=52b992e783d2f84dd0123c70ac8623b4f0f938d1' , 'Defining the source control context using a commit' )
75
85
. example ( 'codefresh run PIPELINE_ID | PIPELINE_NAME -b=master -v key1=value1 -v key2=value2' , 'Setting variables through the command' )
@@ -99,9 +109,10 @@ const run = new Command({
99
109
const enableNotifications = argv [ 'enable-notifications' ] ;
100
110
const resetVolume = argv [ 'reset-volume' ] ;
101
111
const variablesFromFile = argv [ 'var-file' ] ;
102
- const contexts = argv [ ' context' ] ;
103
- const userYamlDescriptor = argv [ ' yaml' ] ;
112
+ const contexts = argv . context ;
113
+ const userYamlDescriptor = argv . yaml ;
104
114
const local = argv . local ;
115
+ const localVolume = argv [ 'local-volume' ] === true ? path . join ( DEFAULTS . CODEFRESH_PATH , pipelineName ) : argv [ 'local-volume' ] ;
105
116
106
117
try {
107
118
await pipeline . getPipelineByName ( pipelineName ) ;
@@ -118,26 +129,48 @@ const run = new Command({
118
129
119
130
if ( local ) {
120
131
const docker = new Docker ( ) ;
132
+ const cleanupActions = [ ] ;
133
+ const injectedOpts = { } ;
134
+ // TODO : Move to per command's handler so each command will be handled in a seperate handler
135
+ if ( userYamlDescriptor ) {
136
+ injectedOpts . Env = [ `OVERRIDE_WORKFLOW_YAML=${ userYamlDescriptor } ` ] ;
137
+ }
138
+
139
+ console . log ( `Updating Codefresh engine ==>` ) ;
121
140
docker . pull ( imageName , ( err , stream ) => {
122
141
docker . modem . followProgress ( stream , onFinished , onProgress ) ;
123
142
function onFinished ( err ) {
124
143
if ( ! err ) {
125
- console . log ( '\nDone pulling.' ) ;
144
+ console . log ( 'Finished Update.\n' ) ;
145
+
146
+ if ( localVolume ) {
147
+ injectedOpts . Env = [ `EXTERNAL_WORKSPACE=${ localVolume } ` ] ;
148
+ console . log ( `\nUsing ${ localVolume } as a local volume.\n` ) ;
149
+ }
150
+
126
151
const currentContext = authManager . getCurrentContext ( ) ;
127
- docker . run ( imageName , [ ] , [ ] , {
152
+ console . log ( `Running pipeline: ${ pipelineName } ` ) ;
153
+
154
+ docker . run ( imageName , [ ] , [ ] , _ . mergeWith ( {
128
155
Env : [
129
156
`ACCESS_TOKEN=${ currentContext . token } ` ,
130
157
`PIPELINE_ID=${ pipelineName } ` , `BRANCH=${ branch } ` ,
131
158
`CF_HOST=${ currentContext . url } ` ,
132
159
'DOCKER_SOCKET_PATH=/var/run/docker.sock' ,
133
- userYamlDescriptor && `OVERRIDE_WORKFLOW_YAML=${ userYamlDescriptor } ` ,
134
160
] ,
135
161
Hostconfig : {
136
162
Binds : [
137
163
'/var/run/docker.sock:/var/run/docker.sock' ,
138
164
] ,
139
165
} ,
140
- } , ( err , data ) => {
166
+ } , injectedOpts , _customizer ) , ( err , data ) => {
167
+ cleanupActions . forEach ( ( action ) => {
168
+ try {
169
+ action ( ) ;
170
+ } catch ( error ) {
171
+ console . error ( err ) ;
172
+ }
173
+ } ) ;
141
174
if ( err ) {
142
175
return console . error ( err ) ;
143
176
}
@@ -158,8 +191,10 @@ const run = new Command({
158
191
process . exit ( 1 ) ;
159
192
}
160
193
}
161
- function onProgress ( ) {
162
- stream . pipe ( process . stdout ) ;
194
+ function onProgress ( res ) {
195
+ if ( _ . get ( res , 'status' ) ) {
196
+ console . log ( res . status ) ;
197
+ }
163
198
}
164
199
} ) ;
165
200
} else {
0 commit comments