Skip to content
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

Refresh codebase, use Taskcluster CI #2

Merged
merged 20 commits into from
Feb 7, 2022
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*log
.env
.git
.taskcluster.yml
Dockerfile
node_modules
64 changes: 33 additions & 31 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 8,
"ecmaVersion": 12,
"ecmaFeatures": "impliedStrict"
},

Expand All @@ -11,35 +11,37 @@
},

"rules": {
"max-len": [2, 120, 2],
"quotes": [2, "single"],
"complexity": [1, 10],
"curly": 2,
"default-case": 2,
"no-lonely-if": 2,
"no-multiple-empty-lines": [1, { "max": 1} ],
"no-nested-ternary": 2,
"quote-props": [2, "as-needed"],
"space-after-keywords": 1,
"space-before-blocks": 1,
"space-before-function-parentheses": [1, "never"],
"space-in-brackets": [1, "never"],
"space-in-parens": [1, "never"],
"no-underscore-dangle": [0],
"no-extra-parens": 2,
"indent": [2, 2, {"indentSwitchCase": true}],
"consistent-this": [1, "that"],
"operator-assignment": [2, "always"],
"semi": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"no-eq-null": 2,
"no-floating-decimal": 2,
"no-self-compare": 2,
"no-throw-literal": 2,
"radix": 2,
"yoda": [1, "never"],
"comma-dangle": [2, "always-multiline"],
"strict": [2,"never"],
"no-process-exit": [0],
"max-len": ["error", 120, 2],
"quotes": ["error", "single"],
"complexity": ["warn", 10],
"curly": "error",
"default-case": "error",
"no-lonely-if": "error",
"no-multiple-empty-lines": ["warn", { "max": 1} ],
"no-nested-ternary": "error",
"quote-props": ["error", "as-needed"],
"keyword-spacing": ["warn"],
"space-before-blocks": "warn",
"space-before-function-paren": ["warn", {"anonymous": "never", "named": "never", "asyncArrow": "always"}],
"object-curly-spacing": ["warn", "never"],
"array-bracket-spacing": ["warn", "never"],
"computed-property-spacing": ["warn", "never"],
"space-in-parens": ["warn", "never"],
"no-underscore-dangle": ["off"],
"no-extra-parens": "error",
"indent": ["error", 2, {"SwitchCase": 1}],
"consistent-this": ["warn", "that"],
"operator-assignment": ["error", "always"],
"semi": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"no-eq-null": "error",
"no-floating-decimal": "error",
"no-self-compare": "error",
"no-throw-literal": "error",
"radix": "error",
"yoda": ["warn", "never"],
"comma-dangle": ["error", "always-multiline"],
"strict": ["error", "never"],
"no-process-exit": ["off"],
}
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
.vagrant
.env
*log
examples/browserify.js
Expand Down
7 changes: 2 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
node_modules
.vagrant
.env
*log
Vagrantfile
vagrant.sh
startup.sh
circle.yml
.gitignore
*docker-exec-client.js
test/browserifytest.js
test/testserver.js
Dockerfile
docker-compose.yml
100 changes: 62 additions & 38 deletions .taskcluster.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
version: 0
metadata:
name: docker-exec-websocket-server
description: 'Helpers for testing taskcluster'
owner: '{{ event.head.user.email }}'
source: '{{ event.head.repo.url }}'
version: 1
policy:
pullRequests: public
tasks:
- provisionerId: '{{ taskcluster.docker.provisionerId }}'
workerType: '{{ taskcluster.docker.workerType }}'
extra:
github:
events:
- push
branches:
- master
scopes:
- auth:aws-s3:read-write:taskcluster-raw-docs/docker-exec-websocket-server/
payload:
maxRunTime: 3600
image: taskcluster/upload-project-docs:latest
features:
taskclusterProxy:
true
command:
- /bin/bash
- '--login'
- '-cx'
- >-
git clone {{event.head.repo.url}} repo &&
cd repo &&
git config advice.detachedHead false &&
git checkout {{event.head.sha}} &&
export DOCS_PROJECT=docker-exec-websocket-server DOCS_TIER=libraries DOCS_FOLDER=docs DOCS_README=README.md &&
upload-project-docs
metadata:
name: "docker-exec-websocket-server docs upload"
description: "Upload documentation for this project"
owner: '{{ event.head.user.email }}'
source: '{{ event.head.repo.url }}'
$let:
proj_name: "docker-exec-websocket-client"
head_rev:
$if: tasks_for == "github-pull-request"
then: ${event.pull_request.head.sha}
else: ${event.after}
repository:
$if: tasks_for == "github-pull-request"
then: ${event.pull_request.head.repo.html_url}
else: ${event.repository.html_url}
environments:
- node_image_tag: 16-bullseye
description: Run tests with node v16
- node_image_tag: 14-bullseye
description: Run tests with node v14
- node_image_tag: 12-bullseye
description: Run tests with node v12
- node_image_tag: "10"
description: Run tests with node v10 (unsupported)
- node_image_tag: current-bullseye
description: Run tests with current node version
in:
$if: tasks_for == "github-pull-request" && event["action"] in ["opened","reopened","synchronize"]
then:
$map: {$eval: environments}
each(env):
taskId: {$eval: as_slugid(proj_name + ":node:" + env.node_image_tag + ":tests")}
deadline:
$fromNow: 1 day
taskQueueId: proj-taskcluster/gw-ci-ubuntu-18-04
metadata:
name: node:${env.node_image_tag} tests
description: ${env.description}
owner: ${event.sender.login}@users.noreply.github.com
source: ${event.repository.url}
payload:
maxRunTime: 3600
env:
BUILDKIT_PROGRESS: plain # auto / tty is over-verbose
REPO_DIR: ${proj_name}
mounts:
- file: bin/docker-compose
content:
url: https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64
sha256: f15a7cd54a85f760a8ece92da63fb85b93036c72ead8056391b8a3fe9dc73134
command:
-
- /bin/bash
- -vxec
- |
docker info
git --version
git clone --no-progress "${repository}" "$REPO_DIR"
cd "$REPO_DIR"
git config advice.detachedHead "false"
git checkout --no-progress "${head_rev}"
chmod a+x ../bin/docker-compose
../bin/docker-compose build --build-arg "NODE_VERSION=${env.node_image_tag}"
../bin/docker-compose run --rm --no-TTY test
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG NODE_VERSION=14-bullseye
FROM node:${NODE_VERSION}

RUN node -v
RUN npm -v
USER root
RUN mkdir /var/run/app
COPY . /var/run/app/
WORKDIR /var/run/app
RUN yarn install --ignore-engines
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# docker-exec-websocket-client

## Purpose
Client for docker-exec-websocket-server.
Client for [docker-exec-websocket-server](https://github.com/taskcluster/docker-exec-websocket-server).

## Usage
Client:
Expand Down Expand Up @@ -31,4 +31,17 @@ There are also other client events:

## Testing

Docker 1.6.1 or above must be installed with a container named `servertest` running with `cat` and `/bin/bash` capabilities to inject the exec process into. From there, `npm test` will carry out the test.
Ensure Docker is installed.

To test locally:

* Run ``yarn install`` to install the dependencies, including developer dependencies
* Run ``yarn test``
* You can pass environment variables and commands to mocha as well, such as ``DEBUG=* yarn test -f 'docker exec wc'``

To test with ``docker-compose``, similar to CI:

* Run ``docker-compose build --build-arg NODE_VERSION=16-bullseye``, or change to the desired
[Node.js image tag](https://hub.docker.com/_/node/)
* Run ``docker-compose run --rm test``
* Repeat ``docker-compose build ...`` when the code changes or you want to try a different Node.js image.
21 changes: 0 additions & 21 deletions Vagrantfile

This file was deleted.

12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "2"

services:
test:
build:
context: .
dockerfile: Dockerfile
image: local/docker-exec-websocket-server
volumes:
- ./:/home/node/app
- /var/run/docker.sock:/var/run/docker.sock
command: /var/run/app/node_modules/.bin/mocha --exit /var/run/app/test/test.js
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "docker-exec-websocket-client",
"version": "1.4.0",
"scripts": {
"test": "./test/runtests.sh"
"test": "mocha ./test/test.js"
},
"license": "MPL-2.0",
"files": [
Expand All @@ -13,23 +13,28 @@
"main": "main.js",
"dependencies": {
"debug": "^4.1.1",
"through2": "^3.0.1",
"ws": "^7.1.2"
"through2": "^4.0.2",
"ws": "^8.4.2"
},
"devDependencies": {
"assume": "^2.2.0",
"docker-exec-websocket-server": "^1.4.0",
"eslint": "^6.4.0",
"docker-exec-websocket-server": "^3.0.0",
"eslint": "^8.8.0",
"express": "^4.17.1",
"mocha": "^6.2.0",
"mocha": "^9.2.0",
"term.js": "^0.0.7"
},
"engines": {
"node": ">8.0"
"node": ">12.0"
},
"repository": {
"type": "git",
"url": "https://github.com/taskcluster/docker-exec-websocket-client.git"
},
"bugs": "https://github.com/taskcluster/docker-exec-websocket-client/issues"
"bugs": "https://github.com/taskcluster/docker-exec-websocket-client/issues",
"mocha": {
"ui": "tdd",
"timeout": "40s",
"reporter": "spec"
}
}
12 changes: 6 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var assert = require('assert');
var debug = require('debug')('docker-exec-websocket-server:lib:client');
var debugdata = require('debug')('docker-exec-websocket-server:lib:rcv');
var debug = require('debug')('docker-exec-websocket-client:lib:client');
var debugdata = require('debug')('docker-exec-websocket-client:lib:rcv');
var EventEmitter = require('events').EventEmitter;
var msgcode = require('./messagecodes.js');
var querystring = require('querystring');
Expand Down Expand Up @@ -120,7 +120,7 @@ class DockerExecWebsocketClient extends EventEmitter {
}

messageHandler(messageEvent) {
var message = new Buffer(new Uint8Array(messageEvent.data));
var message = Buffer.from(new Uint8Array(messageEvent.data));
debugdata(message);
// the first byte is the message code
switch (message[0]) {
Expand Down Expand Up @@ -177,7 +177,7 @@ class DockerExecWebsocketClient extends EventEmitter {
if (!this.options.tty) {
throw new Error('cannot resize, not a tty instance');
} else {
var buf = new Buffer(4);
var buf = Buffer.alloc(4);
buf.writeUInt16LE(h, 0);
buf.writeUInt16LE(w, 2);
debug('resized to %sx%s', h, w);
Expand All @@ -186,11 +186,11 @@ class DockerExecWebsocketClient extends EventEmitter {
}

sendCode(code) {
this.strbuf.write(new Buffer([code]));
this.strbuf.write(Buffer.from([code]));
}

sendMessage(code, data) {
this.strbuf.write(Buffer.concat([new Buffer([code]), new Buffer(data)]));
this.strbuf.write(Buffer.concat([Buffer.from([code]), Buffer.from(data)]));
}

close() {
Expand Down
2 changes: 1 addition & 1 deletion src/messagecodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ module.exports = {
// resolution related message types
stopped: 200, // Process exited, payload is single byte exit code
shutdown: 201, // Server shut down
error: 202 // Some internal error occurred, expect undefined behaviour
error: 202, // Some internal error occurred, expect undefined behaviour
//may carry utf8 payload regarding error reason
};
Loading