Permalink
Browse files

ci: Run npm registry in Docker

  • Loading branch information...
pvdlg committed Nov 25, 2017
1 parent 0c67ba5 commit 40c58c9b42e56b289078334012ebc624e98bcaf0
View
@@ -129,7 +129,3 @@ $RECYCLE.BIN/
package-lock.json
yarn.lock
# Registry tests
test/helpers/registry/couch
test/helpers/registry/data
View
@@ -1,11 +1,13 @@
language: node_js
services:
- couchdb
- docker
notifications:
email: false
node_js:
- 9
- 8
os:
- linux
# Trigger a push build on caribou and greenkeeper branches + PRs build on every branches
# Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147)
View
@@ -46,11 +46,12 @@
"eslint-plugin-prettier": "^2.3.0",
"file-url": "^2.0.2",
"fs-extra": "^4.0.2",
"got": "^8.0.0",
"js-yaml": "^3.10.0",
"mockserver-client": "^2.0.0",
"nock": "^9.0.2",
"npm-registry-couchapp": "^2.6.12",
"nyc": "^11.2.1",
"p-retry": "^1.0.0",
"prettier": "~1.8.0",
"proxyquire": "^1.8.0",
"sinon": "^4.0.0",
View
@@ -1,12 +1,22 @@
import Docker from 'dockerode';
import getStream from 'get-stream';
import got from 'got';
import pRetry from 'p-retry';
import {mockServerClient} from 'mockserver-client';
const MOCK_SERVER_PORT = 1080;
const MOCK_SERVER_HOST = 'localhost';
const docker = new Docker();
let container;
async function checkStatus() {
const response = await got.put(`http://${MOCK_SERVER_HOST}:${MOCK_SERVER_PORT}/status`, {cache: false});
if (response.status === 200) {
// If the registry returns a 200 status, it's ready. Abort the retry.
throw new pRetry.AbortError();
}
}
/**
* Download the `mockserver` Docker image, create a new container and start it.
*
@@ -19,7 +29,14 @@ async function start() {
Image: 'jamesdbloom/mockserver',
PortBindings: {[`${MOCK_SERVER_PORT}/tcp`]: [{HostPort: `${MOCK_SERVER_PORT}`}]},
});
return container.start();
await container.start();
try {
// Wait for the mock server to be ready
await pRetry(checkStatus, {retries: 5, minTimeout: 1000, factor: 2});
} catch (err) {
throw new Error(`Couldn't start mock-server after 30s`);
}
}
/**
@@ -0,0 +1,69 @@
import Docker from 'dockerode';
import getStream from 'get-stream';
import got from 'got';
import pRetry from 'p-retry';
const SERVER_PORT = 15986;
const COUCHDB_PORT = 5984;
const SERVER_HOST = 'localhost';
const NPM_USERNAME = 'integration';
const NPM_PASSWORD = 'suchsecure';
const NPM_EMAIL = 'integration@test.com';
const docker = new Docker();
let container;
async function checkStatus() {
const response = await got(`http://${SERVER_HOST}:${SERVER_PORT}/registry/_design/app`, {cache: false});
if (response.status === 200) {
// If the registry returns a 200 status, it's ready. Abort the retry.
throw new pRetry.AbortError();
}
}
async function start() {
await getStream(await docker.pull('npmjs/npm-docker-couchdb:1.6.1'));
container = await docker.createContainer({
Image: 'npmjs/npm-docker-couchdb:1.6.1',
PortBindings: {[`${COUCHDB_PORT}/tcp`]: [{HostPort: `${SERVER_PORT}`}]},
});
await container.start();
try {
// Wait for the registry to be ready
await pRetry(checkStatus, {retries: 5, minTimeout: 1000, factor: 2});
} catch (err) {
throw new Error(`Couldn't start npm-docker-couchdb after 30s`);
}
// Create user
await got(`http://${SERVER_HOST}:${SERVER_PORT}/_users/org.couchdb.user:${NPM_USERNAME}`, {
json: true,
auth: 'admin:admin',
method: 'PUT',
body: {
_id: `org.couchdb.user:${NPM_USERNAME}`,
name: NPM_USERNAME,
roles: [],
type: 'user',
password: NPM_PASSWORD,
email: NPM_EMAIL,
},
});
}
const url = `http://${SERVER_HOST}:${SERVER_PORT}/registry/_design/app/_rewrite/`;
const authEnv = {
npm_config_registry: url, // eslint-disable-line camelcase
NPM_USERNAME,
NPM_PASSWORD,
NPM_EMAIL,
};
async function stop() {
return container.stop();
}
export default {start, stop, authEnv, url};

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
View
@@ -3,15 +3,15 @@ import {writeJson, readJson} from 'fs-extra';
import {stub} from 'sinon';
import execa from 'execa';
import {gitRepo, gitCommits, gitHead, gitTagVersion, gitPackRefs, gitAmmendCommit} from './helpers/git-utils';
import registry from './helpers/registry';
import mockServer from './helpers/mockserver';
import npmRegistry from './helpers/npm-registry';
import semanticRelease from '..';
/* eslint camelcase: ["error", {properties: "never"}] */
// Environment variables used with cli
const env = {
npm_config_registry: registry.uri,
npm_config_registry: npmRegistry.url,
GH_TOKEN: 'github_token',
GITHUB_URL: mockServer.url,
NPM_EMAIL: 'integration@test.com',
@@ -23,10 +23,10 @@ const pluginError = require.resolve('./fixtures/plugin-error');
const pluginInheritedError = require.resolve('./fixtures/plugin-error-inherited');
test.before(async () => {
// Start the local NPM registry
await npmRegistry.start();
// Start Mock Server
await mockServer.start();
// Start the local NPM registry
await registry.start();
});
test.beforeEach(t => {
@@ -54,9 +54,10 @@ test.afterEach.always(t => {
});
test.after.always(async () => {
await mockServer.stop();
// Stop the local NPM registry
await registry.stop();
await npmRegistry.stop();
// Stop Mock Server
await mockServer.stop();
});
test.serial('Release patch, minor and major versions', async t => {
@@ -71,7 +72,7 @@ test.serial('Release patch, minor and major versions', async t => {
version: '0.0.0-dev',
repository: {url: `git+https://github.com/${owner}/${packageName}`},
release: {verifyConditions: ['@semantic-release/github', '@semantic-release/npm']},
publishConfig: {registry: registry.uri},
publishConfig: {registry: npmRegistry.url},
});
// Create a npm-shrinkwrap.json file
await execa('npm', ['shrinkwrap'], {env});
@@ -284,7 +285,7 @@ test.serial('Release versions from a packed git repository, using tags to determ
version: '0.0.0-dev',
repository: {url: `git@github.com:${owner}/${packageName}.git`},
release: {verifyConditions: ['@semantic-release/github', '@semantic-release/npm']},
publishConfig: {registry: registry.uri},
publishConfig: {registry: npmRegistry.url},
});
/* Initial release */
@@ -399,7 +400,7 @@ test.serial('Create a tag as a recovery solution for "ENOTINHISTORY" error', asy
version: '0.0.0-dev',
repository: {url: `git+https://github.com/${owner}/${packageName}`},
release: {verifyConditions: ['@semantic-release/github', '@semantic-release/npm']},
publishConfig: {registry: registry.uri},
publishConfig: {registry: npmRegistry.url},
});
/* Initial release */
@@ -528,7 +529,7 @@ test.serial('Dry-run', async t => {
name: packageName,
version: '0.0.0-dev',
repository: {url: `git+https://github.com/${owner}/${packageName}`},
publishConfig: {registry: registry.uri},
publishConfig: {registry: npmRegistry.url},
});
/* Initial release */
@@ -557,7 +558,7 @@ test.serial('Pass options via CLI arguments', async t => {
name: packageName,
version: '0.0.0-dev',
repository: {url: `git+https://github.com/${owner}/${packageName}`},
publishConfig: {registry: registry.uri},
publishConfig: {registry: npmRegistry.url},
});
/* Initial release */
@@ -597,7 +598,7 @@ test.serial('Run via JS API', async t => {
name: packageName,
version: '0.0.0-dev',
repository: {url: `git+https://github.com/${owner}/${packageName}`},
publishConfig: {registry: registry.uri},
publishConfig: {registry: npmRegistry.url},
});
/* Initial release */

0 comments on commit 40c58c9

Please sign in to comment.