Skip to content

Commit 83d3e6c

Browse files
Support ability to use local volume when running the pipeline --localy (#262)
1 parent b74bd82 commit 83d3e6c

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

lib/interface/cli/commands/pipeline/run.cmd.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ const authManager = require('../../../../logic').auth.manager;
88
const Docker = require('dockerode');
99
const { validatePipelineYaml } = require('../../helpers/validation');
1010
const { printResult } = require('../root/validate.cmd');
11-
11+
const DEFAULTS = require('../../defaults');
12+
const path = require('path');
1213
const regex = /##[0-9a-f]{24}##/i;
1314
const imageName = 'codefresh/engine:master';
1415

1516

17+
function _customizer(objValue, srcValue) {
18+
if (Array.isArray(objValue)) {
19+
return _.compact(objValue.concat(srcValue));
20+
}
21+
}
1622
const run = new Command({
1723
root: true,
1824
command: 'run <name>',
@@ -70,6 +76,10 @@ const run = new Command({
7076
type: Boolean,
7177
default: false,
7278
})
79+
.option('local-volume', {
80+
describe: 'Use your file system as volume in local run',
81+
alias: 'vl',
82+
})
7383
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -b=master', 'Defining the source control context using a branch')
7484
.example('codefresh run PIPELINE_ID | PIPELINE_NAME -s=52b992e783d2f84dd0123c70ac8623b4f0f938d1', 'Defining the source control context using a commit')
7585
.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({
99109
const enableNotifications = argv['enable-notifications'];
100110
const resetVolume = argv['reset-volume'];
101111
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;
104114
const local = argv.local;
115+
const localVolume = argv['local-volume'] === true ? path.join(DEFAULTS.CODEFRESH_PATH, pipelineName) : argv['local-volume'];
105116

106117
try {
107118
await pipeline.getPipelineByName(pipelineName);
@@ -118,26 +129,48 @@ const run = new Command({
118129

119130
if (local) {
120131
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 ==>`);
121140
docker.pull(imageName, (err, stream) => {
122141
docker.modem.followProgress(stream, onFinished, onProgress);
123142
function onFinished(err) {
124143
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+
126151
const currentContext = authManager.getCurrentContext();
127-
docker.run(imageName, [], [], {
152+
console.log(`Running pipeline: ${pipelineName}`);
153+
154+
docker.run(imageName, [], [], _.mergeWith({
128155
Env: [
129156
`ACCESS_TOKEN=${currentContext.token}`,
130157
`PIPELINE_ID=${pipelineName}`, `BRANCH=${branch}`,
131158
`CF_HOST=${currentContext.url}`,
132159
'DOCKER_SOCKET_PATH=/var/run/docker.sock',
133-
userYamlDescriptor && `OVERRIDE_WORKFLOW_YAML=${userYamlDescriptor}`,
134160
],
135161
Hostconfig: {
136162
Binds: [
137163
'/var/run/docker.sock:/var/run/docker.sock',
138164
],
139165
},
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+
});
141174
if (err) {
142175
return console.error(err);
143176
}
@@ -158,8 +191,10 @@ const run = new Command({
158191
process.exit(1);
159192
}
160193
}
161-
function onProgress() {
162-
stream.pipe(process.stdout);
194+
function onProgress(res) {
195+
if (_.get(res, 'status')) {
196+
console.log(res.status);
197+
}
163198
}
164199
});
165200
} else {

lib/logic/auth/contexts/Context.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Context {
2626
this.status = 'Valid';
2727
} catch (err) {
2828
this.status = 'Revoked';
29+
if (err.code === 'ECONNREFUSED') {
30+
this.status = 'Cant connect to server';
31+
}
2932
}
3033
}
3134

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.9.18",
3+
"version": "0.9.19",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)