Skip to content

Commit

Permalink
fix(#38): switch from docker-compose to docker compose (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuester authored Apr 18, 2024
1 parent 0fe1db9 commit 0c5c8e8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:16-alpine3.15

RUN apk --no-cache add docker docker-compose
RUN apk --no-cache add docker docker-cli-compose
COPY . /app
RUN cd app && npm ci --omit=dev
ENTRYPOINT ["node", "/app/src/index.js"]
6 changes: 4 additions & 2 deletions src/docker-compose-cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const childProcess = require('child_process');

const DOCKER_COMPOSE_CLI = 'docker-compose';
const DOCKER_CLI = 'docker';
const COMPOSE_ARG = 'compose';
const RATE_EXCEEDED = 'Rate exceeded';

const isRateExceededError = (err) => err && err.message && err.message.includes(RATE_EXCEEDED);
Expand All @@ -10,13 +11,14 @@ const composeCommand = (filePaths, ...params) => {
filePaths = Array.isArray(filePaths) ? filePaths : [filePaths];

const args = [
COMPOSE_ARG,
...['-p', CHT_COMPOSE_PROJECT_NAME],
...filePaths.map(filePath => (['-f', filePath])),
...params.filter(param => param).map(param => param.split(' ')),
].flat();

return new Promise((resolve, reject) => {
const proc = childProcess.spawn(DOCKER_COMPOSE_CLI, args, { stdio: ['ignore', 'pipe', 'pipe'] });
const proc = childProcess.spawn(DOCKER_CLI, args, { stdio: ['ignore', 'pipe', 'pipe'] });
proc.on('error', (err) => reject(err));

let err = '';
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/install.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ describe('install', () => {
'one-two.yml': await utils.setVersion('one-two.yml', '13.0.0', false),
})).to.be.rejected;
expect(response.error).to.equal(true);
expect(response.reason).to.include(
'manifest for localhost:5000/upgrade/one:13.0.0 not found: manifest unknown: manifest unknown'
);
expect(response.reason).to.include(
'manifest for localhost:5000/upgrade/two:13.0.0 not found: manifest unknown: manifest unknown'
expect(response.reason).to.match(
/manifest for localhost:5000\/upgrade\/(one|two):13.0.0 not found: manifest unknown: manifest unknown/
);

await expect(utils.getServiceVersion('one-two.yml', 'one')).to.be.rejected;
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/startup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ describe('start up', () => {

const result = await expect(utils.startContainers()).to.be.rejected;
expect(result.error).to.equal(true);
expect(result.reason).to.include(
'manifest for localhost:5000/upgrade/one:10.0.0 not found: manifest unknown: manifest unknown'
expect(result.reason).to.match(
/manifest for localhost:5000\/upgrade\/(one|two):10.0.0 not found: manifest unknown: manifest unknown/
);

await utils.setVersion('one-two.yml', '2.0.0');
Expand Down
14 changes: 4 additions & 10 deletions test/e2e/upgrade.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ describe('upgrade', () => {
'one-two.yml': await utils.setVersion('one-two.yml', '13.0.0', false),
})).to.be.rejected;
expect(response.error).to.equal(true);
expect(response.reason).to.include(
'manifest for localhost:5000/upgrade/one:13.0.0 not found: manifest unknown: manifest unknown'
);
expect(response.reason).to.include(
'manifest for localhost:5000/upgrade/two:13.0.0 not found: manifest unknown: manifest unknown'
expect(response.reason).to.match(
/manifest for localhost:5000\/upgrade\/(one|two):13.0.0 not found: manifest unknown: manifest unknown/
);

expect(await utils.getServiceVersion('one-two.yml', 'one')).to.equal('1.0.0');
Expand All @@ -173,11 +170,8 @@ describe('upgrade', () => {
'one-two.yml': await utils.setVersion('one-two.yml', '13.0.0', false),
})).to.be.rejected;
expect(response.error).to.equal(true);
expect(response.reason).to.include(
'manifest for localhost:5000/upgrade/one:13.0.0 not found: manifest unknown: manifest unknown'
);
expect(response.reason).to.include(
'manifest for localhost:5000/upgrade/two:13.0.0 not found: manifest unknown: manifest unknown'
expect(response.reason).to.match(
/manifest for localhost:5000\/upgrade\/(one|two):13.0.0 not found: manifest unknown: manifest unknown/
);

expect(await utils.getServiceVersion('one-two.yml', 'one')).to.equal('2.0.0');
Expand Down
43 changes: 22 additions & 21 deletions test/unit/docker-compose-cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht', '-f', filename, 'config' ],
'docker',
[ 'compose', '-p', 'cht', '-f', filename, 'config' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand All @@ -50,8 +50,8 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht','-f', filename, 'config' ],
'docker',
[ 'compose', '-p', 'cht','-f', filename, 'config' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand All @@ -67,8 +67,8 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht','-f', filename, 'config' ],
'docker',
[ 'compose', '-p', 'cht','-f', filename, 'config' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand All @@ -79,16 +79,16 @@ describe('docker-compose cli', () => {
});

describe('up', () => {
it('should call docker-compose cli with correct params', async () => {
it('should call docker compose cli with correct params', async () => {
const filename = 'path/to/filename.yml';
sinon.spy(console, 'log');

const result = dockerComposeCli.up(filename);

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
'docker',
[ 'compose', '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand All @@ -110,8 +110,9 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
'docker',
[
'compose',
'-p', 'somerandomname',
'-f', 'path/to/file1.yml',
'-f', 'path/to/file2.yml',
Expand All @@ -137,8 +138,8 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
'docker',
[ 'compose', '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand All @@ -152,8 +153,8 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
'docker',
[ 'compose', '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand All @@ -166,16 +167,16 @@ describe('docker-compose cli', () => {
});

describe('pull', () => {
it('should call docker-compose cli with correct params', async () => {
it('should call docker compose cli with correct params', async () => {
const filename = 'path/to/file.yml';
sinon.spy(console, 'log');

const result = dockerComposeCli.pull(filename);

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht', '-f', filename, 'pull' ],
'docker',
[ 'compose', '-p', 'cht', '-f', filename, 'pull' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand Down Expand Up @@ -245,8 +246,8 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht', '-f', filename, 'pull' ],
'docker',
[ 'compose', '-p', 'cht', '-f', filename, 'pull' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand All @@ -260,8 +261,8 @@ describe('docker-compose cli', () => {

expect(childProcess.spawn.callCount).to.equal(1);
expect(childProcess.spawn.args[0]).to.deep.equal([
'docker-compose',
[ '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
'docker',
[ 'compose', '-p', 'cht', '-f', filename, 'up', '-d', '--remove-orphans' ],
{ stdio: ['ignore', 'pipe', 'pipe'] },
]);
expect(spawnedProcess.events).to.have.keys(['error', 'exit']);
Expand Down

0 comments on commit 0c5c8e8

Please sign in to comment.