Skip to content

Commit

Permalink
feat(1958): Publish major version. BREAKING CHANGE: hapi v19
Browse files Browse the repository at this point in the history
feat(1958): Publish major version. BREAKING CHANGE: hapi v19
  • Loading branch information
pritamstyz4ever authored Aug 26, 2020
2 parents 55db17b + 4f9f0c9 commit 7632636
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 284 deletions.
141 changes: 72 additions & 69 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }] */
const Executor = require('screwdriver-executor-base');
const hoek = require('hoek');
const hoek = require('@hapi/hoek');
const imageParser = require('docker-parse-image');
const Fusebox = require('circuit-fuses').breaker;
const Docker = require('dockerode');
Expand Down Expand Up @@ -40,12 +40,15 @@ class DockerExecutor extends Executor {
this.launchVersion = options.launchVersion || 'stable';
this.prefix = options.prefix || '';

const breakerOptions = hoek.applyToDefaults({
breaker: {
maxFailures: 10,
timeout: 5 * 60 * 1000 // Default to 5 minute timeout,
}
}, options.fusebox || {});
const breakerOptions = hoek.applyToDefaults(
{
breaker: {
maxFailures: 10,
timeout: 5 * 60 * 1000 // Default to 5 minute timeout,
}
},
options.fusebox || {}
);

this.breaker = new Fusebox((obj, cb) => obj.func(cb), breakerOptions);
}
Expand Down Expand Up @@ -107,16 +110,16 @@ class DockerExecutor extends Executor {
_findContainers(buildId) {
const listArgs = {
filters: JSON.stringify({
label: [
`sdbuild=${this.prefix}${buildId}`
]
label: [`sdbuild=${this.prefix}${buildId}`]
}),
all: true
};

return this.breaker.runCommand({
func: cb => this.docker.listContainers(listArgs, cb)
}).then(containers => containers.map(container => this.docker.getContainer(container.Id)));
return this.breaker
.runCommand({
func: cb => this.docker.listContainers(listArgs, cb)
})
.then(containers => containers.map(container => this.docker.getContainer(container.Id)));
}

/**
Expand All @@ -133,8 +136,7 @@ class DockerExecutor extends Executor {
const piecesParts = imageParser(config.container);
let buildTag = piecesParts.tag;
let buildImage = piecesParts.name;
const buildTimeout = hoek.reach(config, 'annotations>screwdriver.cd/timeout',
{ separator: '>' });
const buildTimeout = hoek.reach(config, 'annotations>screwdriver.cd/timeout', { separator: '>' });
const timeout = parseInt(buildTimeout || DEFAULT_BUILD_TIMEOUT, 10);

/**
Expand All @@ -158,54 +160,55 @@ class DockerExecutor extends Executor {
buildTag = 'latest';
}

return Promise.all(
[
this._createImage({
fromImage: 'screwdrivercd/launcher',
tag: this.launchVersion
}),
this._createImage({
fromImage: buildImage,
tag: buildTag
return Promise.all([
this._createImage({
fromImage: 'screwdrivercd/launcher',
tag: this.launchVersion
}),
this._createImage({
fromImage: buildImage,
tag: buildTag
})
])
.then(() =>
this._createContainer({
name: `${this.prefix}${config.buildId}-init`,
Image: `screwdrivercd/launcher:${this.launchVersion}`,
Entrypoint: '/bin/true',
Labels: {
sdbuild: `${this.prefix}${config.buildId}`
}
})
])
.then(() => this._createContainer({
name: `${this.prefix}${config.buildId}-init`,
Image: `screwdrivercd/launcher:${this.launchVersion}`,
Entrypoint: '/bin/true',
Labels: {
sdbuild: `${this.prefix}${config.buildId}`
}
}))
.then(launchContainer => this._createContainer({
name: `${this.prefix}${config.buildId}-build`,
Image: config.container,
Entrypoint: '/opt/sd/launcher_entrypoint.sh',
Labels: {
sdbuild: `${this.prefix}${config.buildId}`
},
Cmd: [
[
// Run the wrapper script
'/opt/sd/run.sh',
`"${config.token}"`,
this.ecosystem.api,
this.ecosystem.store,
timeout,
config.buildId,
this.ecosystem.ui
].join(' ')
],
HostConfig: {
// 2 GB of memory
Memory: 2 * 1024 * 1024 * 1024,
// 3 GB of memory + swap (aka, 1 GB of swap)
MemoryLimit: 3 * 1024 * 1024 * 1024,
VolumesFrom: [
`${launchContainer.id}:rw`
]
}
}))
)
.then(launchContainer =>
this._createContainer({
name: `${this.prefix}${config.buildId}-build`,
Image: config.container,
Entrypoint: '/opt/sd/launcher_entrypoint.sh',
Labels: {
sdbuild: `${this.prefix}${config.buildId}`
},
Cmd: [
[
// Run the wrapper script
'/opt/sd/run.sh',
`"${config.token}"`,
this.ecosystem.api,
this.ecosystem.store,
timeout,
config.buildId,
this.ecosystem.ui
].join(' ')
],
HostConfig: {
// 2 GB of memory
Memory: 2 * 1024 * 1024 * 1024,
// 3 GB of memory + swap (aka, 1 GB of swap)
MemoryLimit: 3 * 1024 * 1024 * 1024,
VolumesFrom: [`${launchContainer.id}:rw`]
}
})
)
.then(buildContainer => this._startContainer(buildContainer));
}

Expand All @@ -217,9 +220,9 @@ class DockerExecutor extends Executor {
* @return {Promise}
*/
_stop(config) {
return this._findContainers(config.buildId)
.then(containers => Promise.all(containers.map(container =>
this._removeContainer(container))));
return this._findContainers(config.buildId).then(containers =>
Promise.all(containers.map(container => this._removeContainer(container)))
);
}

/**
Expand Down Expand Up @@ -259,10 +262,10 @@ class DockerExecutor extends Executor {
}

/**
* Retreive stats for the executor/breaker
* @method stats
* @param {Response} Object Object containing stats for the executor/breaker
*/
* Retreive stats for the executor/breaker
* @method stats
* @param {Response} Object Object containing stats for the executor/breaker
*/
stats() {
return this.breaker.stats();
}
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "screwdriver-executor-docker",
"version": "2.0.0",
"version": "5.0.0",
"description": "Docker Swarm Executor for Screwdriver",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -37,18 +37,18 @@
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^4.19.1",
"eslint-config-screwdriver": "^3.0.1",
"mocha": "^7.0.1",
"eslint": "^7.7.0",
"eslint-config-screwdriver": "^5.0.4",
"mocha": "^8.1.1",
"mockery": "^2.0.0",
"nyc": "^15.0.0",
"sinon": "^7.1.0"
"sinon": "^9.0.3"
},
"dependencies": {
"@hapi/hoek": "^9.0.4",
"circuit-fuses": "^4.0.4",
"docker-parse-image": "^3.0.1",
"dockerode": "^2.5.8",
"hoek": "^5.0.4",
"screwdriver-executor-base": "^7.0.0"
"screwdriver-executor-base": "^8.0.0"
}
}
Loading

0 comments on commit 7632636

Please sign in to comment.