Skip to content

Commit

Permalink
Merge branch 'v1.0-dev' into feat/use-all-identities-in-strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldelucia authored May 7, 2024
2 parents a50f98a + 8073c3f commit 91399c8
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 24 deletions.
86 changes: 78 additions & 8 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed .yarn/cache/ejs-npm-3.1.8-30583753fc-879f84c8ee.zip
Binary file not shown.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"resolutions": {
"elliptic": "^6.5.4",
"bn.js": "4.12.0",
"ejs": "^3.1.7",
"fast-json-patch": "^3.1.1",
"node-tar": "^6.2.1",
"[email protected]": "patch:oclif@npm:3.4.2#.yarn/patches/oclif-npm-3.4.2-a655d32eed.patch",
Expand Down
8 changes: 7 additions & 1 deletion packages/dashmate/src/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default class UpdateCommand extends ConfigBaseCommand {
) {
const updateInfo = await updateNode(config);

const colors = {
updated: chalk.yellow,
'up to date': chalk.green,
error: chalk.red,
};

// Draw table or show json
printArrayOfObjects(updateInfo
.reduce(
Expand All @@ -43,7 +49,7 @@ export default class UpdateCommand extends ConfigBaseCommand {
}) => ([
...acc,
format === OUTPUT_FORMATS.PLAIN
? { Service: title, Image: image, Updated: updated ? chalk.yellow('updated') : chalk.green('up to date') }
? { Service: title, Image: image, Updated: colors[updated](updated) }
: {
name, title, updated, image,
},
Expand Down
43 changes: 35 additions & 8 deletions packages/dashmate/src/update/updateNodeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ export default function updateNodeFactory(getServiceList, docker) {

return Promise.all(
lodash.uniqBy(services, 'image')
.map(async ({ name, image, title }) => new Promise((resolve, reject) => {
.map(async ({ name, image, title }) => new Promise((resolve) => {
docker.pull(image, (err, stream) => {
if (err) {
reject(err);
if (process.env.DEBUG) {
// eslint-disable-next-line no-console
console.error(`Failed to update ${name} service, image ${image}, error: ${err}`);
}

resolve({
name, title, image, updated: 'error',
});
} else {
let updated = null;

Expand All @@ -33,15 +40,35 @@ export default function updateNodeFactory(getServiceList, docker) {
.trim()
.split('\r\n')
.map((str) => JSON.parse(str))
.filter((obj) => obj.status.startsWith('Status: '));
.filter((obj) => obj?.status?.startsWith('Status: '));

if (status) {
if (status.status.includes('Image is up to date for')) {
updated = 'up to date';
} else if (status.status.includes('Downloaded newer image for')) {
updated = 'updated';
}
} else {
if (process.env.DEBUG) {
// eslint-disable-next-line no-console
console.error('Failed to read docker json data, status not found');
}

if (status?.status.includes('Image is up to date for')) {
updated = false;
} else if (status?.status.includes('Downloaded newer image for')) {
updated = true;
resolve({
name, title, image, updated: 'error',
});
}
});
stream.on('error', reject);
stream.on('error', () => {
if (process.env.DEBUG) {
// eslint-disable-next-line no-console
console.error(`Failed to update ${name} service, image ${image}, error: ${err}`);
}

resolve({
name, title, image, updated: 'error',
});
});
stream.on('end', () => resolve({
name, title, image, updated,
}));
Expand Down
40 changes: 40 additions & 0 deletions packages/dashmate/test/unit/commands/update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,44 @@ describe('Update command', () => {
expect(mockGetServicesList).to.have.been.calledOnceWithExactly(config);
expect(mockDocker.pull).to.have.been.calledOnceWith(mockServicesList[0].image);
});

it('should update other services if one of them fails', async function it() {
const command = new UpdateCommand();
mockDockerResponse = { status: 'Status: Image is up to date for' };
mockServicesList = [{ name: 'fake', image: 'fake', title: 'FAKE' },
{ name: 'fake_docker_pull_error', image: 'fake_err_image', title: 'FAKE_ERROR' }];

// test docker.pull returns error
mockDocker = {
pull: this.sinon.stub()
.callsFake((image, cb) => (image === mockServicesList[1].image ? cb(new Error(), null)
: cb(false, mockDockerStream))),
};

let updateNode = updateNodeFactory(mockGetServicesList, mockDocker);

await command.runWithDependencies({}, { format: 'json' }, mockDocker, config, updateNode);

expect(mockGetServicesList).to.have.been.calledOnceWithExactly(config);
expect(mockDocker.pull.firstCall.firstArg).to.equal(mockServicesList[0].image);
expect(mockDocker.pull.secondCall.firstArg).to.equal(mockServicesList[1].image);

// test docker.pull stream returns error
mockDocker = { pull: this.sinon.stub().callsFake((image, cb) => cb(false, mockDockerStream)) };
mockDockerStream = {
on: this.sinon.stub().callsFake((channel, cb) => (channel === 'error' ? cb(new Error()) : null)),
};

// reset
mockGetServicesList = this.sinon.stub().callsFake(() => mockServicesList);
mockDocker = { pull: this.sinon.stub().callsFake((image, cb) => cb(false, mockDockerStream)) };

updateNode = updateNodeFactory(mockGetServicesList, mockDocker);

await command.runWithDependencies({}, { format: 'json' }, mockDocker, config, updateNode);

expect(mockGetServicesList).to.have.been.calledOnceWithExactly(config);
expect(mockDocker.pull.firstCall.firstArg).to.equal(mockServicesList[0].image);
expect(mockDocker.pull.secondCall.firstArg).to.equal(mockServicesList[1].image);
});
});
Loading

0 comments on commit 91399c8

Please sign in to comment.