Compare commits

...

4 Commits

Author SHA1 Message Date
Steven
17bbf69346 Publish
- @now/node-server@0.6.1-canary.2
 - @now/python@0.1.1-canary.2
2019-05-03 19:48:26 -04:00
Steven
4fb4229c90 Remove python/pip installer (#459)
* Remove python/pip installer

* Add back PYTHONUSERBASE env var
2019-05-03 19:46:47 -04:00
Steven
03b7586b50 [now-node-server] Fix unit tests 2019-05-03 14:09:45 -04:00
Mickaël Allonneau
a1427866ca [now-node-server] 'config.includeFiles' accepts a string (#442)
* 1st try (fails)

* 2nd try (fails)

* 3rd try (fails)

* 4th try (fail)
2019-05-03 13:54:33 -04:00
7 changed files with 30 additions and 66 deletions

View File

@@ -50,8 +50,12 @@ async function compile(workPath, downloadedFiles, entrypoint, config) {
});
if (config && config.includeFiles) {
const includeFiles = typeof config.includeFiles === 'string'
? [config.includeFiles]
: config.includeFiles;
// eslint-disable-next-line no-restricted-syntax
for (const pattern of config.includeFiles) {
for (const pattern of includeFiles) {
// eslint-disable-next-line no-await-in-loop
const files = await glob(pattern, inputDir);

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node-server",
"version": "0.6.1-canary.1",
"version": "0.6.1-canary.2",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -0,0 +1,5 @@
const express = require('express');
const app = express();
app.listen();

View File

@@ -9,6 +9,13 @@
"templates/**"
]
}
},
{
"src": "accepts-string/index.js",
"use": "@now/node-server",
"config": {
"includeFiles": "templates/**"
}
}
],
"probes": [

View File

@@ -1,48 +0,0 @@
import execa from 'execa';
// downloads and installs `pip` (respecting
// process.env.PYTHONUSERBASE), and returns
// the absolute path to it
export async function downloadAndInstallPip() {
const { PYTHONUSERBASE } = process.env;
if (!PYTHONUSERBASE) {
// this is the directory in which `pip` will be
// installed to. `--user` will assume `~` if this
// is not set, and `~` is not writeable on AWS Lambda.
// let's refuse to proceed
throw new Error(
'Could not install "pip": "PYTHONUSERBASE" env var is not set'
);
}
console.log('installing python...');
try {
await execa('uname', ['-a'], { stdio: 'inherit' });
await execa('yum-config-manager', ['--enable', 'epel'], {
stdio: 'inherit',
});
await execa(
'yum',
['install', '-y', 'https://centos6.iuscommunity.org/ius-release.rpm'],
{ stdio: 'inherit' }
);
//await execa('yum', ['update'], { stdio: 'inherit' });
await execa(
'yum',
[
'install',
'-y',
'python36u',
'python36u-libs',
'python36u-devel',
'python36u-pip',
],
{ stdio: 'inherit' }
);
} catch (err) {
console.log('could not install python');
throw err;
}
return '/usr/bin/pip3.6';
}

View File

@@ -12,7 +12,6 @@ import {
shouldServe,
BuildOptions,
} from '@now/build-utils';
import { downloadAndInstallPip } from './download-and-install-pip';
async function pipInstall(pipPath: string, workDir: string, ...args: string[]) {
const target = '.';
@@ -69,20 +68,16 @@ export const config = {
export const build = async ({
workPath,
files,
files: originalFiles,
entrypoint,
meta = {},
}: BuildOptions) => {
console.log('downloading files...');
// eslint-disable-next-line no-param-reassign
files = await download(files, workPath);
// this is where `pip` will be installed to
// we need it to be under `/tmp`
const downloadedFiles = await download(originalFiles, workPath);
const foundLockFile = 'Pipfile.lock' in downloadedFiles;
const pyUserBase = await getWriteableDirectory();
process.env.PYTHONUSERBASE = pyUserBase;
const pipPath = meta.isDev ? 'pip3' : await downloadAndInstallPip();
const pipPath = 'pip3';
try {
// See: https://stackoverflow.com/a/44728772/376773
@@ -92,8 +87,10 @@ export const build = async ({
//
// distutils.errors.DistutilsOptionError: must supply either home
// or prefix/exec-prefix -- not both
const setupCfg = join(workPath, 'setup.cfg');
await writeFile(setupCfg, '[install]\nprefix=\n');
if (meta.isDev) {
const setupCfg = join(workPath, 'setup.cfg');
await writeFile(setupCfg, '[install]\nprefix=\n');
}
} catch (err) {
console.log('failed to create "setup.cfg" file');
throw err;
@@ -102,10 +99,7 @@ export const build = async ({
await pipInstall(pipPath, workPath, 'werkzeug');
await pipInstall(pipPath, workPath, 'requests');
const entryDirectory = dirname(entrypoint);
const requirementsTxt = join(entryDirectory, 'requirements.txt');
if (files['Pipfile.lock']) {
if (foundLockFile) {
console.log('found "Pipfile.lock"');
// Install pipenv.
@@ -115,6 +109,8 @@ export const build = async ({
}
const fsFiles = await glob('**', workPath);
const entryDirectory = dirname(entrypoint);
const requirementsTxt = join(entryDirectory, 'requirements.txt');
if (fsFiles[requirementsTxt]) {
console.log('found local "requirements.txt"');

View File

@@ -1,6 +1,6 @@
{
"name": "@now/python",
"version": "0.1.1-canary.1",
"version": "0.1.1-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {