8000 Coco/fix no execution permission when decompressing by coco-super · Pull Request #782 · alibaba/funcraft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Coco/fix no execution permission when decompressing #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
18 changes: 9 additions & 9 deletions lib/build/build.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ async function buildFunction(buildName, tpl, baseDir, useDocker, stages, verbose

const runtime = functionRes.Properties.Runtime;
const codeUri = functionRes.Properties.CodeUri;
const asbCodeUri = path.resolve(baseDir, functionRes.Properties.CodeUri);
const absCodeUri = path.resolve(baseDir, functionRes.Properties.CodeUri);

await assertCodeUriExist(asbCodeUri);
await assertCodeUriExist(absCodeUri);

if (runtime === 'java8' && (asbCodeUri.endsWith('.zip') || asbCodeUri.endsWith('.jar') || asbCodeUri.endsWith('.war'))) {
if (runtime === 'java8' && (absCodeUri.endsWith('.zip') || absCodeUri.endsWith('.jar') || absCodeUri.endsWith('.war'))) {
console.warn(red(`\nDetectionWarning: your codeuri is '${codeUri}', and 'fun build' will not compile your functions. It is recommended that you modify ${serviceName}/${functionName}'s 'CodeUri' property to the directory where 'pom.xml' is located.`));
}

Expand All @@ -197,19 +197,19 @@ async function buildFunction(buildName, tpl, baseDir, useDocker, stages, verbose
funcArtifactDir = await artifact.generateArtifactDirectory(rootArtifactsDir, serviceName, functionName);
await artifact.cleanDirectory(funcArtifactDir);
} else {
funcArtifactDir = asbCodeUri;
funcArtifactDir = absCodeUri;
}

const Builder = fcBuilders.Builder;
const taskFlows = await Builder.detectTaskFlow(runtime, asbCodeUri);
const taskFlows = await Builder.detectTaskFlow(runtime, absCodeUri);

const funfilePath = await getOrConvertFunfile(asbCodeUri);
const funfilePath = await getOrConvertFunfile(absCodeUri);

let imageTag;

// convert Funfile to dockerfile if Funfile exist
if (funfilePath) {
imageTag = await processFunfile(serviceName, serviceRes, asbCodeUri, funfilePath, baseDir, funcArtifactDir, runtime, functionName);
imageTag = await processFunfile(serviceName, serviceRes, absCodeUri, funfilePath, baseDir, funcArtifactDir, runtime, functionName);
}

// For build stage, Fun needn't compile functions only if there are no manifest file and no Funfile.
Expand All @@ -224,9 +224,9 @@ async function buildFunction(buildName, tpl, baseDir, useDocker, stages, verbose
}

if (useDocker || funfilePath) { // force docker if funfilePath exist
await builder.buildInDocker(serviceName, serviceRes, functionName, functionRes, baseDir, asbCodeUri, funcArtifactDir, verbose, imageTag, stages);
await builder.buildInDocker(serviceName, serviceRes, functionName, functionRes, baseDir, absCodeUri, funcArtifactDir, verbose, imageTag, stages);
} else {
await builder.buildInProcess(serviceName, functionName, asbCodeUri, runtime, funcArtifactDir, verbose, stages);
await builder.buildInProcess(serviceName, functionName, absCodeUri, runtime, funcArtifactDir, verbose, stages);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async function pullImage(imageName) {

const registry = await dockerOpts.resolveDockerRegistry();

return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {

console.log(`begin pulling image ${resolveImageName}, you can also use ` + yellow(`'docker pull ${resolveImageName}'`) + ' to pull image by yourself.');

Expand Down
4 changes: 2 additions & 2 deletions lib/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ async function saveNasMappings(nasYmlPath, nasMappings) {
async function copyEntryPoint(tplPath, codeUri, packageName) {
const packagePaths = packageName.split('.');

const asbCodeUri = path.resolve(path.dirname(tplPath), codeUri);
const entryPointPath = path.join(asbCodeUri, 'src', 'main', 'java', ...packagePaths, 'Entrypoint.java');
const absCodeUri = path.resolve(path.dirname(tplPath), codeUri);
const entryPointPath = path.join(absCodeUri, 'src', 'main', 'java', ...packagePaths, 'Entrypoint.java');

const sourcePath = path.resolve(__dirname, './utils/classLoader/Entrypoint.java');
const content = await fs.readFile(sourcePath, {
Expand Down
3 changes: 1 addition & 2 deletions lib/import/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ async function outputFunctionCode(serviceName, functionName, fullOutputDir) {
console.log(` ${green('✔')} ${functionName} - ${grey('Function')}`);
});
const fullTargetCodeDir = path.join(fullOutputDir, serviceName, functionName);
return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
response.pipe(unzipper.Extract({ path: fullTargetCodeDir })).on('error', err => {
bar.interrupt(err);
reject(err);
}).on('finish', resolve);
});

}

async function getServiceResource(serviceMeta, fullOutputDir, recursive, onlyConfig) {
Expand Down
2 changes: 1 addition & 1 deletion lib/init/vcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function downloadRepoZip(repoType, repoUrl, repoDir, outputDir, checkout)
debug('finish download.');
});

return new Promise((resolve, reject) => response.pipe(unzipper.Extract({ path: outputDir })).on('error', err => {
return await new Promise((resolve, reject) => response.pipe(unzipper.Extract({ path: outputDir })).on('error', err => {
if (bar) {
bar.interrupt(err);
}
Expand Down
27 changes: 15 additions & 12 deletions lib/local/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const debug = require('debug')('fun:local');
const path = require('path');
const fs = require('fs-extra');
const rimraf = require('rimraf');
const unzipper = require('unzipper');
const extract = require('extract-zip');
const tmpDir = require('temp-dir');
const uuid = require('uuid');
const { DEFAULT_NAS_PATH_SUFFIX } = require('../tpl');
Expand All @@ -20,22 +20,25 @@ function isZipArchive(codeUri) {

async function processZipCodeIfNecessary(codeUri) {

if (isZipArchive(codeUri)) {
const stream = fs.createReadStream(codeUri);
if (!isZipArchive(codeUri)) { return null; }

const tmpCodeDir = path.join(tmpDir, uuid.v4());
const tmpCodeDir = path.join(tmpDir, uuid.v4());

await fs.ensureDir(tmpCodeDir);
await fs.ensureDir(tmpCodeDir);

console.log(`codeUri is a zip format, will unzipping to ${tmpCodeDir}`);
console.log(`codeUri is a zip format, will unzipping to ${tmpCodeDir}`);

await stream.pipe(unzipper.Extract({ path: tmpCodeDir })).promise();
return tmpCodeDir;
}

return null;
return await new Promise((resolve, reject) => {
// use extract-zip instead of unzipper https://github.com/alibaba/funcraft/issues/756
extract(codeUri, { dir: tmpCodeDir }, (err) => {
if (err) {
reject(err);
return;
}
resolve(tmpCodeDir);
});
});
}

class Invoke {

constructor(serviceName, serviceRes, functionName, functionRes, debugPort, debugIde, baseDir, tmpDir, debuggerPath, debugArgs, nasBaseDir) {
Expand Down
4 changes: 1 addition & 3 deletions lib/package/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ async function packTo(file, funignore, targetPath, prefix = '') {
throw new Error('file %s must be a regular file or directory.', file);
}

return new Promise((resolve, reject) => {

return await new Promise((resolve, reject) => {
output.on('close', () => {
const compressedSize = zipArchiver.pointer();
resolve({ count, compressedSize });
Expand All @@ -253,7 +252,6 @@ async function packTo(file, funignore, targetPath, prefix = '') {
} catch (err) {
reject(err);
}

});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function getEvent(eventFile, ec = 'local invoke', dp = '/fun/local/invoke'

if (!eventFile) { return event; }

return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {

let input;

Expand Down
83 changes: 64 additions & 19 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"dotenv": "^6.0.0",
"draftlog": "^1.0.12",
"express": "^4.16.4",
"extract-zip": "^1.6.7",
"fs-extra": "^8.1.0",
"get-stdin": "^6.0.0",
"git-ignore-parser": "0.0.2",
Expand Down
Loading
0