Skip to content

Commit

Permalink
chore: Migrate runtime-image to gts (GoogleCloudPlatform#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicKramer authored Nov 14, 2017
1 parent 836d174 commit a0e4dbb
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 255 deletions.
113 changes: 0 additions & 113 deletions runtime-image/gulpfile.js

This file was deleted.

21 changes: 10 additions & 11 deletions runtime-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@
"name": "nodejs-docker",
"description": "This repository contains the Dockerfile used to build the Node.js runtime image used by Google App Engine",
"scripts": {
"test": "gulp test"
"test": "mocha -r source-map-support/register build/test/**/*.js --reporter spec --timeout 25000",
"check": "gts check",
"clean": "gts clean",
"compile": "tsc -p .",
"fix": "gts fix",
"prepare": "npm run compile",
"pretest": "npm run compile",
"posttest": "npm run check"
},
"devDependencies": {
"@types/dockerode": "^2.5.1",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.18",
"@types/request": "0.0.45",
"clang-format": "^1.0.50",
"del": "^2.2.2",
"dockerode": "^2.5.3",
"gulp": "^3.9.1",
"gulp-clang-format": "^1.0.23",
"gulp-mocha": "^4.3.1",
"gulp-sourcemaps": "^2.6.0",
"gulp-tslint": "^8.0.0",
"gulp-typescript": "^3.1.6",
"merge2": "^1.0.3",
"gts": "latest",
"mocha": "^2.4.5",
"request": "^2.69.0",
"source-map-support": "^0.4.15",
"tar-fs": "^1.16.0",
"tslint": "^5.2.0",
"typescript": "^2.3.2"
"typescript": "~2.6.1"
}
}
146 changes: 72 additions & 74 deletions runtime-image/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import * as Docker from 'dockerode';
import * as path from 'path';
import * as request from 'request';

const tar: {pack: (dir: string) => any} = require('tar-fs');
const tar: {pack: (dir: string) => NodeJS.ReadableStream} = require('tar-fs');

const RUN_TIMEOUT_MS = 3000;
const BUILD_TIMEOUT_MS = 5 * 60 * 1000;
const PORT = 8080;

const host = process.env.DOCKER_HOST
? process.env.DOCKER_HOST.split('//')[1].split(':')[0]
: 'localhost';
const host = process.env.DOCKER_HOST ?
process.env.DOCKER_HOST.split('//')[1].split(':')[0] :
'localhost';

const DOCKER = new Docker(
{socketPath : process.env.DOCKER_SOCKET || '/var/run/docker.sock'});
{socketPath: process.env.DOCKER_SOCKET || '/var/run/docker.sock'});

const ROOT = path.join(__dirname, '..', '..');

Expand Down Expand Up @@ -96,56 +96,53 @@ interface TestConfig {

const CONFIGURATIONS: TestConfig[] = [
{
description : `serves traffic on port ${PORT}`,
tag : 'test/definitions/express',
expectedOutput : 'Hello World!'
description: `serves traffic on port ${PORT}`,
tag: 'test/definitions/express',
expectedOutput: 'Hello World!'
},
{
description : 'can install yarn locally',
tag : 'test/definitions/yarn-local',
expectedOutput : '0.18.0\n'
description: 'can install yarn locally',
tag: 'test/definitions/yarn-local',
expectedOutput: '0.18.0\n'
},
{
description : 'can install yarn globally',
tag : 'test/definitions/yarn-global',
expectedOutput : '0.18.0\n'
description: 'can install yarn globally',
tag: 'test/definitions/yarn-global',
expectedOutput: '0.18.0\n'
},
{
description : 'install_node installs and verifies verifiable Node versions',
tag : 'test/definitions/verifiable-node',
expectedOutput : 'v6.0.0'
description: 'install_node installs and verifies verifiable Node versions',
tag: 'test/definitions/verifiable-node',
expectedOutput: 'v6.0.0'
},
{
description :
'install_node still installs Node even if it cannot ' +
'be verified if --ingore-verification-failure is specified',
tag : 'test/definitions/unverifiable-node',
expectedOutput : 'v0.10.7'
description: 'install_node still installs Node even if it cannot ' +
'be verified if --ingore-verification-failure is specified',
tag: 'test/definitions/unverifiable-node',
expectedOutput: 'v0.10.7'
},
{
description :
'install_node aborts the installation if verification fails ' +
'and --ingore-verification-failure is not specified',
tag : 'test/definitions/verify-fail-aborts-install',
expectedOutput : 'v6.10.3'
description: 'install_node aborts the installation if verification fails ' +
'and --ingore-verification-failure is not specified',
tag: 'test/definitions/verify-fail-aborts-install',
expectedOutput: 'v6.10.3'
},
{
description :
'verify_node has a non-zero exit code if it is not supplied ' +
'the files it need for verification',
tag : 'test/definitions/verify-fail-without-files',
expectedOutput : 'Correctly failed verification'
description: 'verify_node has a non-zero exit code if it is not supplied ' +
'the files it need for verification',
tag: 'test/definitions/verify-fail-without-files',
expectedOutput: 'Correctly failed verification'
},
{
description : 'verify_node has a non-zero exit code if the checksum ' +
'check fails',
tag : 'test/definitions/verify-fail-on-invalid-data',
expectedOutput : 'Correctly failed verification'
description: 'verify_node has a non-zero exit code if the checksum ' +
'check fails',
tag: 'test/definitions/verify-fail-on-invalid-data',
expectedOutput: 'Correctly failed verification'
},
{
description : 'verify the set of keys in the keyring',
tag : 'test/definitions/verify-gpg-keyring',
expectedOutput : GPG_KEYS
description: 'verify the set of keys in the keyring',
tag: 'test/definitions/verify-gpg-keyring',
expectedOutput: GPG_KEYS
}
];

Expand Down Expand Up @@ -190,45 +187,46 @@ describe('runtime image', () => {
});
});

function buildDocker(dir: string, tag: string): Promise<any> {
async function buildDocker(dir: string, tag: string): Promise<{}> {
const tarStream = tar.pack(dir);
return new Promise<any>((resolve, reject) => {
DOCKER.buildImage(tarStream, {t : tag}, (err1, stream) => {
if (err1) {
return reject(err1);
}

function onFinished(err2: Error, output: any) {
if (err2) {
return reject(err2);
}
const stream = await DOCKER.buildImage(tarStream, {t: tag});

resolve(output);
}
let resolve: (output: {}) => void;
let reject: (err: Error) => void;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});

function onProgress(event: any) {
log(event.stream);
log(event.status);
log(event.progress);
}
function onFinished(err: Error, output: {}) {
if (err) {
return reject(err);
}

DOCKER.modem.followProgress(stream, onFinished, onProgress);
});
});
resolve(output);
}

function onProgress(
event: {stream?: string; status?: string; progress?: string;}) {
log(event.stream);
log(event.status);
log(event.progress);
}

DOCKER.modem.followProgress(stream, onFinished, onProgress);
return promise;
}

function runDocker(tag: string, port: number): Promise<Docker.Container> {
return DOCKER
.createContainer({
Image : tag,
AttachStdin : false,
AttachStdout : true,
AttachStderr : true,
Tty : true,
ExposedPorts : {[`${port}/tcp`] : {}},
HostConfig :
{PortBindings : {[`${port}/tcp`] : [ {HostPort : `${port}`} ]}}
})
.then((container) => { return container.start(); })
.catch((err) => { assert.ifError(err); });
async function runDocker(tag: string, port: number): Promise<Docker.Container> {
const container = await DOCKER.createContainer({
Image: tag,
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Tty: true,
ExposedPorts: {[`${port}/tcp`]: {}},
HostConfig: {PortBindings: {[`${port}/tcp`]: [{HostPort: `${port}`}]}}
});
await container.start();
return container;
}
34 changes: 13 additions & 21 deletions runtime-image/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"allowSyntheticDefaultImports": false,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": true,
"declaration": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es6"],
"noFallthroughCasesInSwitch": true,
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"strictNullChecks": true,
"module": "commonjs",
"target": "es5",
"sourceMap": true
}
"rootDir": ".",
"outDir": "build"
},
"include": [
"src/*.ts",
"src/**/*.ts",
"test/*.ts",
"test/**/*.ts"
],
"exclude": [
"node_modules"
]
}

Loading

0 comments on commit a0e4dbb

Please sign in to comment.