Skip to content
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM yolean/node@sha256:e591eac6f5d1f07876bd63bba2bbd1c1218521c5ed5312692851597b47089775
FROM yolean/node@sha256:9f4a2b32e4ba065ea5471d4d83084d4ba1f860a8bde614518b386999bf0cf9b2

ENV docker_version=17.09.1~ce-0~debian
ENV compose_version=1.21.0 compose_sha256=af639f5e9ca229442c8738135b5015450d56e2c1ae07c0aaa93b7da9fe09c2b0
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Defines a successful build and test run for a microservice, from source to docke
Invoke build-contract in current folder, use host's docker:
```
docker build --tag yolean/build-contract .
docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/:/source --rm --name mybuild yolean/build-contract test
docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/:/source --rm --name mybuild -e PUSH_TAG=testing yolean/build-contract test
```

Or for monorepo:
```
docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/../:/source -w /source/$(basename $(pwd)) --rm --name mybuild yolean/build-contract test
docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/../:/source -w /source/$(basename $(pwd)) --rm --name mybuild -e PUSH_TAG=testing yolean/build-contract test
```

Add `-t` for colors and Ctrl+C support.
Expand Down
9 changes: 1 addition & 8 deletions build-contract
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ function wait_for_contract {
fi
}

# Perform tests
BUILD_FLAGS='';
if [[ $DO_PUSH == true ]]; then
BUILD_FLAGS="$BUILD_FLAGS --pull";
fi

MONOREPO_PRE=$(cat package.json | grep '"build-contract-predockerbuild"' | awk -F '"' '{ print $4 }')
if [[ "$MONOREPO_PRE" == "#" ]]; then $DIR/nodejs/build-contract-predockerbuild
elif [[ ! -z "$MONOREPO_PRE" ]]; then npm run build-contract-predockerbuild; fi
Expand All @@ -74,8 +68,7 @@ for compose_file in $(ls $CONTRACTS_DIR | grep .yml); do
# and volumes (including named volumes declared in the docker-compose.yml file)
$docker_compose down -v

$docker_compose build $BUILD_FLAGS
$docker_compose up --force-recreate -d
$docker_compose up --build --force-recreate -d
$docker_compose logs -f &
bar=$(wait_for_contract $compose_name)
echo " --- build-contract: Build Contract finished with $bar"
Expand Down
2 changes: 1 addition & 1 deletion nodejs/mnpm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const tar = require('tar-stream');
const zlib = require('zlib');
const zlib = require('./zlib-choice');

const tarContentMtime = new Date(946684800000);

Expand Down
41 changes: 27 additions & 14 deletions nodejs/mnpm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const os = require('os');
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const zlib = require('zlib');
const zlib = require('./zlib-choice');
const stream = require('stream');
const tar = require('tar-stream');

Expand All @@ -19,13 +19,14 @@ describe("stringifyPackageJson", () => {

describe("Our choice of gzip function", () => {

it("Is platform independent wrt result checksum", () => {
it("Is platform independent wrt result checksum", done => {
const blob = new stream.PassThrough();
const sha256 = crypto.createHash('sha256');
const result = new stream.PassThrough();
result.on('data', d => sha256.update(d));
result.on('end', () => expect(sha256.digest('hex')).toBe(
'c5f9a2352dadba9488900ba6ede0133270e12350ffa6d6ebbdefef9ee6aa2238'));
'b13627bbeee31ae666d6696cf11e411ee6b0e40d4b235cb2a02da32693ba2d3c'));
result.on('end', done);
// Note that this differs from `echo 'x' | gzip - | shasum -a 256 -`
blob.pipe(zlib.createGzip()).pipe(result);
blob.end('x\n');
Expand All @@ -36,7 +37,7 @@ describe("Our choice of gzip function", () => {
expect(process.versions.zlib).toBe('1.2.11');
});

it("Results may depend on zlib options", () => {
it("Results may depend on zlib options", done => {
const options = {
windowBits: 14, memLevel: 7,
level: zlib.constants.Z_BEST_SPEED,
Expand All @@ -47,13 +48,13 @@ describe("Our choice of gzip function", () => {
const result = new stream.PassThrough();
result.on('data', d => sha256.update(d));
result.on('end', () => expect(sha256.digest('hex')).toBe(
'270b40b49af0dcc1de9631f231d022c93c07f29d2940e14d22ffdd797165e24f'));
// Note that this differs from `echo 'x' | gzip - | shasum -a 256 -`
'dd8dbe0ba323ab288d9e9272efc1f2bf52f495a812122c6ee9f9c5e7d765fda5'));
result.on('end', done);
blob.pipe(zlib.createGzip(options)).pipe(result);
blob.end('x\n');
});

it("Results may depend on zlib compression level", () => {
it("Results may depend on zlib compression level", done => {
const options = {
level: zlib.constants.Z_BEST_COMPRESSION
};
Expand All @@ -62,13 +63,13 @@ describe("Our choice of gzip function", () => {
const result = new stream.PassThrough();
result.on('data', d => sha256.update(d));
result.on('end', () => expect(sha256.digest('hex')).toBe(
'1437e4b499b5063c9530244d1655dba6986bcbd1258f81f122bdc4c983058ef4'));
// Note that this differs from `echo 'x' | gzip - | shasum -a 256 -`
'6cda46810118792ed89f1e1662549186b5c851e4ce240be861780bc646e850c6'));
result.on('end', done);
blob.pipe(zlib.createGzip(options)).pipe(result);
blob.end('x\n');
});

it("Results may be more platform independent with no compression", () => {
it("Results may be more platform independent with no compression", done => {
const options = {
level: zlib.constants.Z_NO_COMPRESSION
};
Expand All @@ -77,12 +78,24 @@ describe("Our choice of gzip function", () => {
const result = new stream.PassThrough();
result.on('data', d => sha256.update(d));
result.on('end', () => expect(sha256.digest('hex')).toBe(
'35932a249baf5fe47b9fecaa3482309e447ed8d9b01e207a6ce2846724006784'));
// Note that this differs from `echo 'x' | gzip - | shasum -a 256 -`
'f2b18200cd38c0d2c3dff4d3e2be9fd83069acd6b73cbc835c708fc3693c45d9'));
result.on('end', done);
blob.pipe(zlib.createGzip(options)).pipe(result);
blob.end('x\n');
});

xit("Results may be better with inflate instead of gzip", done => {
const blob = new stream.PassThrough();
const sha256 = crypto.createHash('sha256');
const result = new stream.PassThrough();
result.on('data', d => sha256.update(d));
result.on('end', () => expect(sha256.digest('hex')).toBe(
'c5f9a2352dadba9488900ba6ede0133270e12350ffa6d6ebbdefef9ee6aa2238'));
result.on('end', done);
blob.pipe(zlib.createInflate()).pipe(result);
blob.end('x\n');
});

});

describe("writeProdPackageTgzWithDeterministicHash", () => {
Expand All @@ -104,10 +117,10 @@ describe("writeProdPackageTgzWithDeterministicHash", () => {
const tgz = await fs.promises.readFile(filePath);
const sha256 = crypto.createHash('sha256');
sha256.update(tgz);
expect(sha256.digest('hex')).toBe('3be69fccaf4716df00adee93c219cfe44f1425aa968d33b6a3a4e725192586be');
expect(sha256.digest('hex')).toBe('ebfa2ce786383196d29b927d3f0a51539655ebe56d4bac52b96f7e13749ba79c');
const sha512 = crypto.createHash('sha512');
sha512.update(tgz);
expect(sha512.digest('base64')).toBe('M24fZ1mSsZYX8dSCGSd54842GgAKd80xInWqNUhSZH1/hx7syKOOx05qMhD8avcFdXNnDMG/N2i/YZJFJNW6rQ==');
expect(sha512.digest('base64')).toBe('4aKJrQoeaGZuY8IDk/LmKX9drIVPoeQG00phQ7kZoR+SXHtrgeA19uUnBrclpm4Sm6xIv8/50V5u/dPxWg62Iw==');
await fs.promises.unlink(filePath);
});

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-contract",
"version": "1.5.0",
"version": "1.6.0",
"description": "Defines a successful build and test run for a microservice, from source to docker push",
"repository": {
"type": "git",
Expand All @@ -23,14 +23,16 @@
"build-contract-predockerbuild": "./nodejs/build-contract-predockerbuild"
},
"engines": {
"node": ">=10.1.0"
"node": ">=10.2.1"
},
"dependencies": {
"browserify-zlib": "0.2.0",
"pako": "1.0.6",
"tar-stream": "1.6.1",
"yamljs": "0.2.8"
},
"peerDependencies": {
"npm": "6.0.1"
"npm": "6.1.0"
},
"devDependencies": {
"jest": "22.4.4"
Expand Down