Skip to content

Commit

Permalink
multiarch pre-build
Browse files Browse the repository at this point in the history
  • Loading branch information
oznu committed Apr 3, 2019
1 parent 783135c commit fdbbe11
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ npm-debug.log
package-lock.json
fixtures/space folder/
.vscode/settings.json

prebuilds
25 changes: 25 additions & 0 deletions .prebuild/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE:-library/alpine}:3.9

ARG QEMU_ARCH
ENV QEMU_ARCH=${QEMU_ARCH:-x86_64}

COPY .prebuild/qemu/qemu-${QEMU_ARCH}-static /usr/bin/

RUN apk add curl git gcc g++ make python paxctl

ENV NODE_VERSION 10.15.3

RUN set -x && curl -fLO https://github.com/oznu/alpine-node/releases/download/${NODE_VERSION}/node-v${NODE_VERSION}-linux-${QEMU_ARCH}-alpine.tar.gz \
&& tar -xzf node-v${NODE_VERSION}-linux-${QEMU_ARCH}-alpine.tar.gz -C /usr --strip-components=1 --no-same-owner \
&& rm -rf node-v${NODE_VERSION}-linux-${QEMU_ARCH}-alpine.tar.gz \
&& paxctl -cm `which node` \
&& npm set prefix /usr/local \
&& npm config set unsafe-perm true

RUN npm install -g prebuild

RUN mkdir /node-pty
WORKDIR /node-pty

CMD ["./.prebuild/build.sh"]
33 changes: 33 additions & 0 deletions .prebuild/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE:-library/debian}:9.6-slim

ARG QEMU_ARCH
ENV QEMU_ARCH=${QEMU_ARCH:-x86_64}

COPY .prebuild/qemu/qemu-${QEMU_ARCH}-static /usr/bin/

RUN apt-get update \
&& apt-get install -y gcc g++ make python curl

ENV NODE_VERSION 10.15.3

RUN case "${QEMU_ARCH}" in \
x86_64) NODE_ARCH='x64';; \
arm) NODE_ARCH='armv7l';; \
aarch64) NODE_ARCH='arm64';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac \
&& set -x \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$NODE_ARCH.tar.gz" \
&& tar -xzf "node-v$NODE_VERSION-linux-$NODE_ARCH.tar.gz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v$NODE_VERSION-linux-$NODE_ARCH.tar.gz" \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
&& npm set prefix /usr/local \
&& npm config set unsafe-perm true

RUN npm install -g prebuild

RUN mkdir /node-pty
WORKDIR /node-pty

CMD ["./.prebuild/build.sh"]
16 changes: 16 additions & 0 deletions .prebuild/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

. /etc/os-release

cd /node-pty
rm -rf node_modules

npm install --only=prod --ignore-scripts

prebuild --all

if [ $ID = "debian" ] && [ "$(uname -m)" = "x86_64" ]; then
echo "Building x86_64 32bit versions..."
apt-get install -y g++-multilib gcc-multilib
prebuild --all -a ia32
fi
Binary file added .prebuild/qemu/qemu-aarch64-static
Binary file not shown.
Binary file added .prebuild/qemu/qemu-arm-static
Binary file not shown.
Binary file added .prebuild/qemu/qemu-x86_64-static
Binary file not shown.
77 changes: 77 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
language: bash

matrix:
include:
# macos
- os: osx
language: node_js
node_js:
- "lts/*"

# windows
- os: windows
language: node_js
node_js:
- "lts/*"

# linux
- os: linux
env: BASE_IMAGE=library/alpine QEMU_ARCH=x86_64 DOCKERFILE="Dockerfile.alpine"
services:
- docker
- os: linux
env: BASE_IMAGE=arm32v6/alpine QEMU_ARCH=arm DOCKERFILE="Dockerfile.alpine"
services:
- docker
- os: linux
env: BASE_IMAGE=arm64v8/alpine QEMU_ARCH=aarch64 DOCKERFILE="Dockerfile.alpine"
services:
- docker
- os: linux
env: BASE_IMAGE=library/debian QEMU_ARCH=x86_64 DOCKERFILE="Dockerfile.debian"
services:
- docker
- os: linux
env: BASE_IMAGE=arm32v7/debian QEMU_ARCH=arm DOCKERFILE="Dockerfile.debian"
services:
- docker
- os: linux
env: BASE_IMAGE=arm64v8/debian QEMU_ARCH=aarch64 DOCKERFILE="Dockerfile.debian"
services:
- docker

before_script:
# linux
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get --yes --no-install-recommends install binfmt-support qemu-user-static ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run --rm --privileged multiarch/qemu-user-static:register --reset ; fi

# macos
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm install -g prebuild ; fi

# windows
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then npm install -g prebuild ; fi

script:
# linux
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker build -f .prebuild/$DOCKERFILE --build-arg BASE_IMAGE=${BASE_IMAGE} --build-arg QEMU_ARCH=${QEMU_ARCH} -t multiarch-build . ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run --rm -v $(pwd):/node-pty multiarch-build ; fi

# macos
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then prebuild --all ; fi

# windows - older versions of node to not work - only supporting Node.js 10+
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then prebuild -t 10.0.0 -t 11.0.0 --include-regex "\.(node|exe|dll|pdb)$" ; fi
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then prebuild -a ia32 -t 10.0.0 -t 11.0.0 --include-regex "\.(node|exe|dll|pdb)$" ; fi
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then prebuild -t 4.0.0 -t 4.0.4 -r electron --include-regex "\.(node|exe|dll|pdb)$" ; fi
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then prebuild -a ia32 -t 4.0.0 -t 4.0.4 -r electron --include-regex "\.(node|exe|dll|pdb)$" ; fi

deploy:
provider: releases
api_key:
secure: C58j8hbP3nb3HRahErbfhKVWvqD7+sv9jz8HBq36jrM9gR7Gyydo4CZg3lEBen3Qy0qpfd0em5XEmtKBSGCl+x+ruavb3VcVTdBTdy1KVZExiY8nNT+JLlUFp7SOHozCSuxf6iau+eP6bO9rAZzaHbYp0yNv+7r89gXNRzEfcJkoQi/TDwV62flJcRHLVZI7PfSC3q/BrxryWonK+TaDUx6ksyaQSJoauxBQ2+y50OEMYFAwfUnIVeBqV9gu7xKpeydbLwIWXBJ7ApuyEarrPXbUx23Wuau7i3hZHElfSW2vPIKEUDWuPaYqzNX9VkRPk736kg5jyspEZ9zj/xxVefqb/Z64Wp04vohftPCMdAOLi13ZnRdQY0G6hBjJvcmQr8oBZdIndrDulvA3lU+8VwYQ9aAi5xn3+zF7qQfTbpLBNXhlZzUOznrmcJh5IydK2sm8SEHKd9feUt3OLFkMkyaFK+ESIEWdjy0hDhIaGRXKQlfcEtNBt2L8rvuOzI4T0ZXC9UnMKdMK7MAOIbW8ht+ziZNE4S7nyqw7CaLyxDf/tr7HIVOI6ztk5CY1If+Ffw3BBnmyMjNhc/40EXK5bItqrHmIWkC9H7sfl8vKs3jp6BeHOwsuTakZon7vRmwMXFsFrOFwLteBAfB0rpI1n54QYfKLa7JjQaHhk9cUf3E=
file_glob: true
file: prebuilds/*.tar.gz
skip_cleanup: true
on:
repo: oznu/node-pty-prebuilt-multiarch
tags: true
129 changes: 37 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,54 @@
# node-pty
# node-pty-prebuilt-multiarch

[![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty)](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty?branchName=master)
[![Travis CI build status](https://travis-ci.org/oznu/node-pty-prebuilt-multiarch.svg)](https://travis-ci.org/oznu/node-pty-prebuilt-multiarch)

`forkpty(3)` bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.
This project is a parallel fork of [`node-pty`](https://github.com/Microsoft/node-pty)
providing prebuilt packages for certain Node.js and Electron versions.

This is useful for:
Inspired by [daviwil/node-pty-prebuilt](https://github.com/daviwil/node-pty-prebuilt).

- Writing a terminal emulator (eg. via [xterm.js](https://github.com/sourcelair/xterm.js)).
- Getting certain programs to *think* you're a terminal, such as when you need a program to send you control sequences.
## Usage

`node-pty` supports Linux, macOS and Windows. Windows support is possible by utilizing the [Windows conpty API](https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line-introducing-the-windows-pseudo-console-conpty/) on Windows 1809+ and the [winpty](https://github.com/rprichard/winpty) library in older version.
Thanks to the excellent [`prebuild`](https://github.com/prebuild/prebuild) and
[`prebuild-install`](https://github.com/prebuild/prebuild) modules, using this module
is extremely easy. You merely have to change your `node-pty` dependency to
`node-pty-prebuilt-multiarch` and then change any `require` statements in your code from
`require('node-pty')` to `require('node-pty-prebuilt-multiarch')`.

## Real-world Uses
> **NOTE**: We started shipping prebuilds as of node-pty version 0.8.1, no prior versions
> are provided! If you were using an earlier version of `node-pty` you will need
> to update your code to account for any API changes that may have occurred.
`node-pty` powers many different terminal emulators, including:
## How It Works

- [Microsoft Visual Studio Code](https://code.visualstudio.com)
- [Hyper](https://hyper.is/)
- [Upterm](https://github.com/railsware/upterm)
- [Script Runner](https://github.com/ioquatix/script-runner) for Atom.
- [Theia](https://github.com/theia-ide/theia)
- [FreeMAN](https://github.com/matthew-matvei/freeman) file manager
- [atom-xterm](https://atom.io/packages/atom-xterm) - Atom plugin for providing terminals inside your Atom workspace.
- [Termination](https://atom.io/packages/termination) - Another Atom plugin that provides terminals inside your Atom workspace.
We maintain a parallel fork of the `node-pty` codebase that will be updated as new
releases are shipped. When we merge new updates to the code into the `prebuild`
branch, new prebuilt packages for our supported Node.js and Electron versions
are updated to the corresponding [GitHub release](https://github.com/oznu/node-pty-prebuilt-multiarch/releases).

Do you use node-pty in your application as well? Please open a [Pull Request](https://github.com/Tyriar/node-pty/pulls) to include it here. We would love to have it in our list.
When `node-pty-prebuilt` is installed as a package dependency, the install script
checks to see if there's a prebuilt package on this repo for the OS, ABI version,
and architecture of the current process and then downloads it, extracting it into
the module path. If a corresponding prebuilt package is not found, `node-gyp`
is invoked to build the package for the current platform.

## Example Usage
## Prebuilt Versions

```js
var os = require('os');
var pty = require('node-pty');
| OS | Architectures |
| --------------- |-------------------------------|
| macOS | amd64 |
| Linux (glibc) | ia32, amd64, arm32v6, arm64v8 |
| Linux (musl) | amd64, arm32v6, arm64v8 |
| Windows* | ia32, amd64 |

var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
We currently build packages for all versions of Node.js and Electron that are supported by the `prebuild` module on Linux and macOS. You can see the full list of versions by checking out the [`supportedTargets`](https://github.com/lgeiger/node-abi/blob/master/index.js#L51) list in [`node-abi`](https://github.com/lgeiger/node-abi/blob/master/index.js#L51).

var ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.env.HOME,
env: process.env
});

ptyProcess.on('data', function(data) {
process.stdout.write(data);
});

ptyProcess.write('ls\r');
ptyProcess.resize(100, 40);
ptyProcess.write('ls\r');
```

## Building

```bash
# Install dependencies and build C++
npm install
# Compile TypeScript -> JavaScript
npm run tsc
```

## Dependencies

### Linux/Ubuntu

```
sudo apt install -y make python build-essential
```

### Windows

`npm install` requires some tools to be present in the system like Python and C++ compiler. Windows users can easily install them by running the following command in PowerShell as administrator. For more information see https://github.com/felixrieseberg/windows-build-tools:

```sh
npm install --global --production windows-build-tools
```

The Windows SDK is also needed which can be [downloaded here](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk). Only the "Desktop C++ Apps" components are needed to be installed.

## Debugging

[The wiki](https://github.com/Microsoft/node-pty/wiki/Debugging) contains instructions for debugging node-pty.

## Security

All processes launched from node-pty will launch at the same permission level of the parent process. Take care particularly when using node-pty inside a server that's accessible on the internet. We recommend launching the pty inside a container to protect your host machine.

## Thread Safety

Note that node-pty is not thread safe so running it across multiple worker threads in node.js could cause issues.

## Troubleshooting

**Powershell gives error 8009001d**

> Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.
This happens when PowerShell is launched with no `SystemRoot` environment variable present.

## pty.js

This project is forked from [chjj/pty.js](https://github.com/chjj/pty.js) with the primary goals being to provide better support for later Node.JS versions and Windows.
*On Windows, we only provide prebuilt binaries for Node.js 10 or higher.

## License

Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).<br>
Copyright (c) 2016, Daniel Imms (MIT License).<br>
Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).
Copyright (c) 2016, Daniel Imms (MIT License).
Copyright (c) 2018, Microsoft Corporation (MIT License).
Copyright (c) 2018, David Wilson (MIT License).
Copyright (c) 2018, oznu (MIT License).
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "node-pty",
"name": "node-pty-prebuilt-multiarch",
"description": "Fork pseudoterminals in Node.JS",
"author": {
"name": "Microsoft Corporation"
Expand All @@ -10,7 +10,7 @@
"types": "./typings/node-pty.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/Tyriar/node-pty.git"
"url": "git://github.com/oznu/node-pty-prebuilt-multiarch.git"
},
"files": [
"binding.gyp",
Expand All @@ -20,9 +20,9 @@
"deps/",
"typings/"
],
"homepage": "https://github.com/Tyriar/node-pty",
"homepage": "https://github.com/oznu/node-pty-prebuilt-multiarch",
"bugs": {
"url": "https://github.com/Tyriar/node-pty/issues"
"url": "https://github.com/oznu/node-pty-prebuilt-multiarch/issues"
},
"keywords": [
"pty",
Expand All @@ -36,13 +36,14 @@
"tsc": "tsc",
"watch": "tsc -w",
"lint": "tslint 'src/**/*.ts'",
"install": "node scripts/install.js",
"install": "prebuild-install || node scripts/install.js",
"postinstall": "node scripts/post-install.js",
"test": "cross-env NODE_ENV=test mocha -R spec --exit lib/*.test.js",
"prepublish": "npm run tsc"
},
"dependencies": {
"nan": "2.12.1"
"nan": "2.12.1",
"prebuild-install": "^5.2.5"
},
"devDependencies": {
"@types/mocha": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion typings/node-pty.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

declare module 'node-pty' {
declare module 'node-pty-prebuilt-multiarch' {
/**
* Forks a process as a pseudoterminal.
* @param file The file to launch.
Expand Down

0 comments on commit fdbbe11

Please sign in to comment.