Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions bin/fun-nas-rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node

/* eslint-disable quotes */

'use strict';

const program = require('commander');
const getVisitor = require('../lib/visitor').getVisitor;
const notifier = require('../lib/update-notifier');

program
.name('fun nas rm')
.description('Remove remote NAS file.')
.usage('[options] <nas_dir>')
.option('-r, --recursive', 'remove folders recursively')
.option('-f, --force', 'remove files without prompting for confirmation')
.parse(process.argv);


if (!program.args.length) {
console.error();
console.error(" error: missing argument [nasDir]");
program.help();
}

notifier.notify();

getVisitor(true).then((visitor) => {
visitor.pageview('/fun/nas/rm').send();

require('../lib/commands/nas/rm')(program.args[0], program)
.then(() => {
visitor.event({
ec: 'rm',
ea: `rm`,
el: 'success',
dp: '/fun/nas/rm'
}).send();
})
.catch(error => {
visitor.event({
ec: 'rm',
ea: `rm`,
el: 'error',
dp: '/fun/nas/rm'
}).send();

require('../lib/exception-handler')(error);
});

});
3 changes: 2 additions & 1 deletion bin/fun-nas.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ program
.command('info', 'Print nas config information, such as local temp directory of NAS.')
.command('init', 'For each service with NAS config, create local NAS folder and deploy fun nas server service.')
.command('sync', 'Synchronize the local NAS directory with the remote NAS file system.')
.command('ls', 'List contents of remote NAS directory');
.command('ls', 'List contents of remote NAS directory')
.command('rm', 'Remove remote NAS file.');

// Print help information if commands are unknown.
program.on('command:*', (cmds) => {
Expand Down
30 changes: 30 additions & 0 deletions lib/commands/nas/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const rmNasFile = require('../../nas/rm');
const { parseNasPath } = require('../../nas/path');
const { detectTplPath } = require('../../tpl');
const path = require('path');
const validate = require('../../validate/validate');
const { red } = require('colors');

async function rm(nasDir, options) {

const tplPath = await detectTplPath();

if (!tplPath) {
throw new Error(red('Current folder not a fun project\nThe folder must contains template.[yml|yaml] or faas.[yml|yaml] .'));
} else if (path.basename(tplPath).startsWith('template')) {
await validate(tplPath);

const isRecursive = options.recursive;
const isForce = options.force;

const { nasPath, serviceName } = await parseNasPath(nasDir);

await rmNasFile(serviceName, nasPath, isRecursive, isForce);
} else {
throw new Error(red('The template file name must be template.[yml|yaml].'));
}
}

module.exports = rm;
4 changes: 2 additions & 2 deletions lib/docker-opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ async function resolveRuntimeToDockerImage(runtime, isBuild) {
const name = runtimeImageMap[runtime];
var imageName;
if (isBuild) {
imageName = `aliyunfc/runtime-${name}:build-1.5.5`;
imageName = `aliyunfc/runtime-${name}:build-1.5.6`;
} else {
imageName = `aliyunfc/runtime-${name}:1.5.5`;
imageName = `aliyunfc/runtime-${name}:1.5.6`;
}

const dockerImageRepo = await resolveDockerImageRepo();
Expand Down
6 changes: 3 additions & 3 deletions lib/fc-utils/fc-fun-nas-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/nas/cp/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ async function upload(srcPath, dstPath, nasHttpTriggerPath) {

await uploadSplitFiles(needToUploadfiles, nasTmpDir, nasHttpTriggerPath);

console.log('Merging split files and unzipping');
await sendMergeRequest(nasHttpTriggerPath, nasTmpDir, dstDir, fileName, zipHash);
console.log(`${green('✔')} merge and unzip done`);
}

rimraf.sync(tmpDir);
Expand Down
9 changes: 8 additions & 1 deletion lib/nas/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const definition = require('../definition');
const constants = require('./constants');
const { green } = require('colors');
const tips = require('./tips');

const nas = require('../nas');
const _ = require('lodash');
async function deployNasService(baseDir, tpl) {
const profile = await getProfile();

Expand Down Expand Up @@ -73,6 +74,12 @@ async function deployNasService(baseDir, tpl) {
console.log(`Waiting for service ${nasServiceName} to be deployed...`);
await deployService(baseDir, nasServiceName, nasServiceRes);
console.log(green(`service ${nasServiceName} deploy success\n`));

const nasMappings = await nas.convertNasConfigToNasMappings(baseDir, nasConfig, serviceName);
console.log(green(`Create local NAS directory of service ${serviceName}:`));
_.forEach(nasMappings, (mappings) => {
console.log(`\t${mappings.localNasDir}`);
});
}

console.log();
Expand Down
23 changes: 23 additions & 0 deletions lib/nas/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const { sendCmdReqequest, getNasHttpTriggerPath } = require('./request');
const { green } = require('colors');

function generateRmCmd(nasPath, isRecursiveOpt, isForceOpt) {
let cmd = 'rm ' + (isRecursiveOpt ? '-R ' : '') + (isForceOpt ? '-f ' : '') + nasPath;
return cmd;
}

async function rm(serviceName, nasPath, isRecursiveOpt, isForceOpt) {
console.log('Removing...');
const nasHttpTriggerPath = await getNasHttpTriggerPath(serviceName);

const rmCmd = generateRmCmd(nasPath, isRecursiveOpt, isForceOpt);

const rmResponse = await sendCmdReqequest(nasHttpTriggerPath, rmCmd);

console.log(rmResponse.data.stdout);
console.log(rmResponse.data.stderr);
console.log(`${green('✔')} remove ${nasPath} done`);
}

module.exports = rm;
2 changes: 1 addition & 1 deletion lib/validate/schema/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const functionSchema = {
},
'Runtime': {
'type': 'string',
'enum': ['nodejs6', 'nodejs8', 'python2.7', 'python3', 'java8', 'php7.2', 'nodejs10', 'dotnetcore2.1']
'enum': ['nodejs6', 'nodejs8', 'python2.7', 'python3', 'java8', 'php7.2', 'nodejs10', 'dotnetcore2.1', 'custom']
},
'CodeUri': {
'type': 'string'
Expand Down
3 changes: 2 additions & 1 deletion test/commands/nas/mock-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ const tpl = {

module.exports = {
nasConfig,
tpl
tpl,
vpcConfig
};
57 changes: 57 additions & 0 deletions test/commands/nas/rm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';


const expect = require('expect.js');
const sinon = require('sinon');
const proxyquire = require('proxyquire');
const sandbox = sinon.createSandbox();
const assert = sinon.assert;
const path = require('path');

const rmNasFile = sandbox.stub();
const validate = sandbox.stub();

const tpl = {
detectTplPath: sandbox.stub().returns('/template.yml')
};

const rmStub = proxyquire('../../../lib/commands/nas/rm', {
'../../validate/validate': validate,
'../../nas/rm': rmNasFile,
'../../tpl': tpl
});

describe('command rm test', () => {
const options =
{
recursive: true,
force: true
};

afterEach(() => {
sandbox.reset();
});

it('valid nas path', async () => {
const nasPath = 'nas://demo:/mnt/nas';

await rmStub(nasPath, options);
const mntDir = path.join('/', 'mnt', 'nas');
assert.calledWith(rmNasFile, 'demo', mntDir, options.recursive, options.force);
});

it('invalid nas path', async () => {
const nasPath = '://demo://mnt/nas';
let err;

try {
await rmStub(nasPath, options);
assert.notCalled(rmNasFile);
} catch (error) {
err = error;
}
expect(err).to.eql(new Error('nas path err: ' + nasPath));

});
});

4 changes: 2 additions & 2 deletions test/docker-opts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('test generateLocalInvokeOpts', () => {
'OpenStdin': true,
'StdinOnce': true,
'Tty': false,
'Image': 'aliyunfc/runtime-nodejs8:1.5.5',
'Image': 'aliyunfc/runtime-nodejs8:1.5.6',
'HostConfig': {
'AutoRemove': true,
'Mounts': [
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('test generateLocalInvokeOpts', () => {
'StdinOnce': true,
'Tty': false,
'User': null,
'Image': 'aliyunfc/runtime-nodejs8:1.5.5',
'Image': 'aliyunfc/runtime-nodejs8:1.5.6',
'Env': [
'LD_LIBRARY_PATH=/code/.fun/root/usr/lib:/code/.fun/root/usr/lib/x86_64-linux-gnu:/code:/code/lib:/usr/local/lib',
'PATH=/code/.fun/root/usr/local/bin:/code/.fun/root/usr/local/sbin:/code/.fun/root/usr/bin:/code/.fun/root/usr/sbin:/code/.fun/root/sbin:/code/.fun/root/bin:/code/.fun/python/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/bin',
Expand Down
8 changes: 4 additions & 4 deletions test/local/invoke.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe('test invoke construct and init', async () => {
expect(invoke.codeMount).to.eql(codeMount);
expect(invoke.mounts).to.eql([codeMount]);
expect(invoke.containerName).to.contain('fun_local_');
expect(invoke.imageName).to.contain('aliyunfc/runtime-python3.6:1.5.5');
expect(invoke.imageName).to.contain('aliyunfc/runtime-python3.6:1.5.6');

assert.calledWith(docker.pullImageIfNeed, 'aliyunfc/runtime-python3.6:1.5.5');
assert.calledWith(docker.pullImageIfNeed, 'aliyunfc/runtime-python3.6:1.5.6');
});

it('test init with nas config', async () => {
Expand Down Expand Up @@ -109,9 +109,9 @@ describe('test invoke construct and init', async () => {
expect(invoke.codeMount).to.eql(codeMount);
expect(invoke.mounts).to.eql([codeMount, ...nasMounts]);
expect(invoke.containerName).to.contain('fun_local_');
expect(invoke.imageName).to.eql('aliyunfc/runtime-python3.6:1.5.5');
expect(invoke.imageName).to.eql('aliyunfc/runtime-python3.6:1.5.6');

assert.calledWith(docker.pullImageIfNeed, 'aliyunfc/runtime-python3.6:1.5.5');
assert.calledWith(docker.pullImageIfNeed, 'aliyunfc/runtime-python3.6:1.5.6');
});
});

Expand Down
1 change: 1 addition & 0 deletions test/nas/cp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('nas cp test', () => {
const mntDir = path.join('/', 'mnt', 'nas');
const nasHttpTriggerPath = `/proxy/${constants.FUN_NAS_SERVICE_PREFIX}fun-nas-test/fun-nas-function/`;
assert.calledWith(upload, srcPath, mntDir, nasHttpTriggerPath, false);

});

it('src path undefined test', async () => {
Expand Down
Loading