Download and use a custom Node binary instead of linking against

private V8 APIs from within our native Node module.
This commit is contained in:
Sean Gillespie 2018-02-13 09:58:11 -08:00
parent 0cb112b984
commit 05cb5368a4
No known key found for this signature in database
GPG key ID: BFAEBCDD042BD2A6
10 changed files with 65 additions and 16 deletions

1
.gitignore vendored
View file

@ -3,6 +3,7 @@
/.vscode/
coverage.cov
*.coverprofile
custom_node/
# Too much awesome to store in Git.
.pulumi

View file

@ -22,10 +22,8 @@
</Target>
<Target Name="EnsureCustomNode"
Condition="!Exists('$(NodeJSSdkDirectory)\custom_node\node.exe')">
<MakeDir Directories="$(NodeJSSdkDirectory)\custom_node" />
<Exec Command="aws s3 cp --only-show-errors s3://eng.pulumi.com/node/node-$(NodeVersion)-win-$(NodeArch).zip &quot;$(NodeJSSdkDirectory)\custom_node\node-$(NodeVersion)-win-$(NodeArch).zip&quot;"/>
<Exec Command="7z x -o&quot;$(NodeJSSdkDirectory)\custom_node&quot; &quot;$(NodeJSSdkDirectory)\custom_node\node-$(NodeVersion)-win-$(NodeArch).zip&quot;" />
Condition="!Exists('$(NodeJSSdkDirectory)\custom_node\node\node.exe')">
<Exec Command="powershell $(NodeJSSdkDirectory)\scripts\download_node.ps1" />
</Target>
<Target Name="CopyNodeSdkProtos">

View file

@ -32,8 +32,7 @@ RunGoBuild "github.com/pulumi/pulumi/sdk/nodejs/cmd/pulumi-langhost-nodejs"
CopyPackage "$Root\sdk\nodejs\bin" "pulumi"
Copy-Item "$Root\dist\sdk\nodejs\pulumi-langhost-nodejs-exec.cmd" "$PublishDir\bin"
New-Item -ItemType Directory -Force -Path "$PublishDir\bin\node" | Out-Null
Copy-Item "$Root\sdk\nodejs\custom_node\node.exe" "$PublishDir\bin\node"
Copy-Item "$Root\sdk\nodejs\custom_node\node\node.exe" "$PublishDir\bin\pulumi-langhost-nodejs-node.exe"
Remove-Item "$PublishDir\node_modules\pulumi\pulumi-langhost-nodejs-exec.cmd"
Remove-Item "$PublishDir\node_modules\pulumi\pulumi-provider-pulumi-nodejs.cmd"

View file

@ -51,6 +51,9 @@ run_go_build "${ROOT}/sdk/nodejs/cmd/pulumi-langhost-nodejs"
cp ${ROOT}/sdk/nodejs/pulumi-langhost-nodejs-exec ${PUBDIR}/bin/
cp ${ROOT}/sdk/nodejs/pulumi-provider-pulumi-nodejs ${PUBDIR}/bin/
# Copy over our custom Node build
cp ${ROOT}/sdk/nodejs/custom_node/node/node ${PUBDIR}/bin/pulumi-langhost-nodejs-node
# Copy packages
copy_package "${ROOT}/sdk/nodejs/bin/." "@pulumi/pulumi"

View file

@ -14,9 +14,10 @@ TEST_FAST_TIMEOUT := 2m
include ../../build/common.mk
export PATH:=$(shell yarn bin 2>/dev/null):$(PATH)
export PATH:=custom_node/node:$(PATH)
ensure::
cd runtime/native && ./ensure_node_v8.sh
./scripts/download_node.sh
lint::
$(GOMETALINTER) cmd/pulumi-langhost-nodejs/main.go | sort ; exit "$${PIPESTATUS[0]}"
@ -24,16 +25,12 @@ lint::
build::
go install -ldflags "-X github.com/pulumi/pulumi/pkg/version.Version=${VERSION}" ${LANGUAGE_HOST}
cd runtime/native && node-gyp configure
cp -R ../proto/nodejs/. proto/
cd runtime/native/ && node-gyp build
tsc
cp package.json bin/
sed -i.bak "s/\$${VERSION}/$(VERSION)/g" bin/version.js bin/package.json && \
rm bin/version.js.bak bin/package.json.bak
cp -R proto/. bin/proto/
mkdir -p bin/runtime/native/
cp -R runtime/native/build/. bin/runtime/native/build/
mkdir -p bin/tests/runtime/langhost/cases/
find tests/runtime/langhost/cases/* -type d -exec cp -R {} bin/tests/runtime/langhost/cases/ \;
@ -41,6 +38,7 @@ install::
GOBIN=$(PULUMI_BIN) go install -ldflags "-X github.com/pulumi/pulumi/pkg/version.Version=${VERSION}" ${LANGUAGE_HOST}
cp pulumi-langhost-nodejs-exec "$(PULUMI_BIN)"
cp pulumi-provider-pulumi-nodejs "$(PULUMI_BIN)"
cp custom_node/node/node "$(PULUMI_BIN)/pulumi-langhost-nodejs-node"
rm -rf "$(PULUMI_NODE_MODULES)/$(NODE_MODULE_NAME)/tests"
test_fast::

View file

@ -1,2 +1,4 @@
#!/usr/bin/env node
require("@pulumi/pulumi/cmd/run");
#!/bin/sh
SDK_DIR=`dirname $0`/../node_modules
pulumi-langhost-nodejs-node $SDK_DIR/@pulumi/pulumi/cmd/run $@

View file

@ -1,3 +1,3 @@
#!/usr/bin/env node
require("./bin/cmd/run");
#!/bin/sh
node ./bin/cmd/run $@

View file

@ -7,7 +7,15 @@ import * as log from "../log";
import * as resource from "../resource";
import { debuggablePromise } from "./debuggable";
const nativeruntime = require("./native/build/Release/nativeruntime.node");
// Our closure serialization code links against v8 internals. On Windows,
// we can't dynamically link against v8 internals because their symbols are
// unexported. In order to address this problem, Pulumi programs run on a
// custom build of Node that has our closure serialization code as a built-in
// module called "pulumi_closure".
//
// `process.binding` invokes the Node bootstrap module loader in order to
// get to our builtin module.
const nativeruntime = (<any>process).binding("pulumi_closure");
/**
* Closure represents the serialized form of a JavaScript serverless function.

View file

@ -0,0 +1,19 @@
Set-StrictMode -Version 2.0
$ErrorActionPreference="Stop"
$NodeVersion="v6.10.2"
$NodeBase="custom_node\node"
$NodeExe="custom_node\node\node.exe"
if (Test-Path $NodeExe) {
Write-Output "skipping node.js executable download, as it already exists"
} else {
echo "node.js binary does not exist, downloading..."
aws s3 cp --only-show-errors "s3://eng.pulumi.com/releases/pulumi-node/windows/$NodeVersion.zip" "$NodeBase\$NodeVersion.zip"
$NodeZipPath = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
7z x -o$NodeZipPath "$NodeBase\$NodeVersion.zip"
Copy-Item $NodeZipPath\Release\node.exe $NodeExe
Remove-Item -Force -Recurse $NodeZipPath
Remove-Item -Force "$NodeBase\$NodeVersion.zip"
}

View file

@ -0,0 +1,21 @@
#!/bin/bash
set -e
set -o nounset -o errexit -o pipefail
NODE_VERSION=v6.10.2
NODE_BASE=custom_node/node
NODE_EXE=$NODE_BASE/node
if [ -f $NODE_EXE ]; then
echo "skipping node.js executable download, as it already exists"
else
echo "node.js binary does not exist, downloading..."
OS=$(go env GOOS)
aws s3 cp --only-show-errors s3://eng.pulumi.com/releases/pulumi-node/$OS/$NODE_VERSION.tgz $NODE_BASE/$NODE_VERSION.tgz
TEMPDIR=$(mktemp -d)
tar -xvzf $NODE_BASE/$NODE_VERSION.tgz -C $TEMPDIR
cp $TEMPDIR/out/Release/node $NODE_BASE
rm -rf $TEMPDIR
rm -f $NODE_BASE/$NODE_VERSION.tgz
fi
echo "done!"