Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the down method doesn't appear to work #186

Open
KenEucker opened this issue Oct 16, 2021 · 15 comments
Open

the down method doesn't appear to work #186

KenEucker opened this issue Oct 16, 2021 · 15 comments

Comments

@KenEucker
Copy link

KenEucker commented Oct 16, 2021

After having run the following command:
await compose.upAll(composeOpts)

I run the following command:

await this.compose.down(composeOpts)

and he enclosing promise simply dies. I have wrapped this code in a try and it doesn't catch any error. The execution just stops.

Is there an example of down being used somewhere? I can't find any documentation on down or stop, and I am unable to manage my containers after creating them with this package.

@Steveb-p
Copy link
Contributor

Steveb-p commented Oct 16, 2021

@KenEucker you can see it being tested here:

test('ensure container gets down', async (): Promise<void> => {
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
await compose.down({ cwd: path.join(__dirname), log: logOutput })
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
})

In most cases if your promise is not executed, it's because the calling code was not adjusted for async execution. For example:

function doSomething() {
  compose.down()
}

doSomething()

would not do anything, because there was nothing attached to the promise handlers (.then). Depending on the javascript engine and how long the process lasts after creating the promise it may or may not execute.

Make sure that the calling code handles the promise. For example:

function doSomething() {
  return compose.down()
}

doSomething().then(() => console.log('done'))

@KenEucker
Copy link
Author

KenEucker commented Oct 16, 2021

@Steveb-p I am handling the promise, in this way:

async function bringItDown() {
  try {
    console.log('container closing')
    await compose.down(composeOpts).then((result) => {
      console.log({result}) // never executes
    })
    console.log('container closed') // never executes
  } catch (e) {
    console.log('container errored', e) // never executes
  }
}
...

// from another async method:
await bringItDown()

@Steveb-p
Copy link
Contributor

@KenEucker to be honest, I have no idea. If you look into the source code all we do is wrap the process of docker-compose and wait for it to exit:

docker-compose/src/index.ts

Lines 190 to 197 in dd4fe76

childProc.on('exit', (exitCode): void => {
result.exitCode = exitCode
if (exitCode === 0) {
resolve(result)
} else {
reject(result)
}
})

I haven't worked in NodeJS for quite a while, but promises should either resolve or reject, and it's handled internally by the engine (by putting it into the loop's queue). The fact that nothing gets executed is curious.

I assume that the whole process ends and that's the only thing that it's supposed to do? There are no calls to process.exit and so on? Or is it a part of a bigger process end it simply does not do anything?

It's possible that there is some sort of confirmation prompt that docker-compose waits for. That would make the child process hang without resolving 🤔
Can you log the stdout/stderr somewhere?

@KenEucker
Copy link
Author

@Steveb-p thank you for trying to help!

I am not making any calls to process.exit, this code executes upon SIGINT. The 'exit' event code that you linked is also never reached when calling .down.

I can try to dig more into the internals of docker-compose, I guess. I downloaded the source code and tried running the tests that you referenced but they don't work for me. I get a No tests found, exiting with code 1.

@AlexZeitler
Copy link
Contributor

AlexZeitler commented Oct 17, 2021

@KenEucker Which Node.ja version do you use on which platform? I’m using docker-compose including down heavily at an internal project right now and it works (local machine macOS and GitHub CI). Which docker-compose versions do you use (this package and CLI)?

@KenEucker
Copy link
Author

@AlexZeitler running node 16.10, Mac OS 11.6, and the latest docker-compose.

@AlexZeitler
Copy link
Contributor

Tests seem to be ok on node 16.10, I'm also on macOS 11.6:

docker-compose on  master is 📦 v0.23.13 via  v16.10.0 on ☁️  (eu-central-1) took 12s
❯ yarn test
yarn run v1.22.5
$ jest test --verbose
 PASS  test/map-ports.test.ts
  ✓ map ports for empty string (2 ms)
  ✓ map ports for exposed tcp
  ✓ map ports for exposed tcp on ivp4 interface (1 ms)
  ✓ map multiple tcp ports exposed on ivp4 interfaces
  ✓ map multiple tcp ports exposed on ipv4 and ipv6 interfaces (1 ms)

compose.config.config.find: Using configuration files: ./docker-compose-42.yml
compose.cli.docker_client.get_client: docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h  22 Sep 2020
compose.cli.docker_client.get_client: Docker base_url: http+docker://localhost
compose.cli.docker_client.get_client: Docker version: Platform={'Name': 'Docker Engine - Community'}, Components=[{'Name': 'Engine', 'Version': '20.10.8', 'Details': {'ApiVersion': '1.41', 'Arch': 'amd64', 'BuildTime': '2021-07-30T19:52:10.000000000+00:00', 'Experimental': 'true', 'GitCommit': '75249d8', 'GoVersion': 'go1.16.6', 'KernelVersion': '5.10.47-linuxkit', 'MinAPIVersion': '1.12', 'Os': 'linux'}}, {'Name': 'containerd', 'Version': '1.4.9', 'Details': {'GitCommit': 'e25210fe30a0a703442421b0f60afac609f950a3'}}, {'Name': 'runc', 'Version': '1.0.1', 'Details': {'GitCommit': 'v1.0.1-0-g4144b63'}}, {'Name': 'docker-init', 'Version': '0.19.0', 'Details': {'GitCommit': 'de40ad0'}}], Version=20.10.8, ApiVersion=1.41, MinAPIVersion=1.12, GitCommit=75249d8, GoVersion=go1.16.6, Os=linux, Arch=amd64, KernelVersion=5.10.47-linuxkit, Experimental=True, BuildTime=2021-07-30T19:52:10.000000000+00:00
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- ('test_default')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume <- ('test_db-data')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume -> {'CreatedAt': '2020-04-23T23:07:21Z',
 'Driver': 'local',
 'Labels': {'com.docker.compose.project': 'test',
            'com.docker.compose.version': '1.25.4',
            'com.docker.compose.volume': 'db-data'},
 'Mountpoint': '/var/lib/docker/volumes/test_db-data/_data',
 'Name': 'test_db-data',
 'Options': None,
 'Scope': 'local'}
compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- ('test_default')
compose.network.ensure: Creating network "test_default" with the default driver
compose.cli.verbose_proxy.proxy_callable: docker create_network <- (name='test_default', driver=None, options=None, ipam=None, internal=False, enable_ipv6=False, labels={'com.docker.compose.project': 'test', 'com.docker.compose.network': 'default', 'com.docker.compose.version': '1.29.2'}, attachable=True, check_duplicate=True)
compose.cli.verbose_proxy.proxy_callable: docker create_network -> {'Id': '1373bb7f5fe583e5e2434c03da0b617609d02dc3c29d87a7cce99e70bc914992',
 'Warning': ''}
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume <- ('test_db-data')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume -> {'CreatedAt': '2020-04-23T23:07:21Z',
 'Driver': 'local',
 'Labels': {'com.docker.compose.project': 'test',
            'com.docker.compose.version': '1.25.4',
            'com.docker.compose.volume': 'db-data'},
 'Mountpoint': '/var/lib/docker/volumes/test_db-data/_data',
 'Name': 'test_db-data',
 'Options': None,
 'Scope': 'local'}
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume <- ('test_db-data')
compose.cli.verbose_proxy.proxy_callable: docker inspect_volume -> {'CreatedAt': '2020-04-23T23:07:21Z',
 'Driver': 'local',
 'Labels': {'com.docker.compose.project': 'test',
            'com.docker.compose.version': '1.25.4',
            'com.docker.compose.volume': 'db-data'},
 'Mountpoint': '/var/lib/docker/volumes/test_db-data/_data',
 'Name': 'test_db-data',
 'Options': None,
 'Scope': 'local'}
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('nginx:1.19.9-alpine')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['nginx', '-g', 'daemon off;'],
            'Domainname': '',
            'Entrypoint': ['/docker-entrypoint.sh'],
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.parallel.feed_queue: Pending: {<Service: some-service>}
compose.parallel.feed_queue: Starting producer thread for <Service: some-service>
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
Creating test_some-service_run ...
compose.parallel.feed_queue: Pending: {ServiceName(project='test', service='some-service', number=1)}
compose.parallel.feed_queue: Starting producer thread for ServiceName(project='test', service='some-service', number=1)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('nginx:1.19.9-alpine')
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['nginx', '-g', 'daemon off;'],
            'Domainname': '',
            'Entrypoint': ['/docker-entrypoint.sh'],
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=test', 'com.docker.compose.service=some-service', 'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 0 items)
compose.cli.verbose_proxy.proxy_callable: docker create_host_config <- (links=[], port_bindings={}, binds=['test_db-data:/mountedsecondvolume:rw'], volumes_from=[], privileged=False, network_mode='test_default', devices=None, device_requests=None, dns=None, dns_opt=None, dns_search=None, restart_policy=None, runtime=None, cap_add=None, cap_drop=None, mem_limit=None, mem_reservation=None, memswap_limit=None, ulimits=None, log_config={'Type': '', 'Config': {}}, extra_hosts=None, read_only=None, pid_mode=None, security_opt=None, ipc_mode=None, cgroup_parent=None, cpu_quota=None, shm_size=None, sysctls=None, pids_limit=None, tmpfs=None, oom_kill_disable=None, oom_score_adj=None, mem_swappiness=None, group_add=None, userns_mode=None, init=None, init_path=None, isolation=None, cpu_count=None, cpu_percent=None, nano_cpus=None, volume_driver=None, cpuset_cpus=None, cpu_shares=None, storage_opt=None, blkio_weight=None, blkio_weight_device=None, device_read_bps=None, device_read_iops=None, device_write_bps=None, device_write_iops=None, mounts=None, device_cgroup_rules=None, cpu_period=None, cpu_rt_period=None, cpu_rt_runtime=None)
compose.cli.verbose_proxy.proxy_callable: docker create_host_config -> {'Binds': ['test_db-data:/mountedsecondvolume:rw'],
 'Links': [],
 'LogConfig': {'Config': {}, 'Type': ''},
 'NetworkMode': 'test_default',
 'PortBindings': {},
 'VolumesFrom': []}
compose.cli.verbose_proxy.proxy_callable: docker create_container <- (command=['pwd'], image='nginx:1.19.9-alpine', volumes={'/mountedsecondvolume': {}}, tty=False, stdin_open=True, detach=False, ports=[], working_dir='/home/root', name='test_some-service_run_efdaa320adac', environment=[], labels={'com.docker.compose.project': 'test', 'com.docker.compose.service': 'some-service', 'com.docker.compose.oneoff': 'True', 'com.docker.compose.project.working_dir': '/Users/alexzeitler/src/pdmlab-oss/docker-compose/test', 'com.docker.compose.project.config_files': 'docker-compose-42.yml', 'com.docker.compose.slug': 'efdaa320adaca4bd6ee192659cfe369dac0c02c804afa31e39d7cfb37ffaf12', 'com.docker.compose.version': '1.29.2'}, host_config={'NetworkMode': 'test_default', 'VolumesFrom': [], 'Binds': ['test_db-data:/mountedsecondvolume:rw'], 'PortBindings': {}, 'Links': [], 'LogConfig': {'Type': '', 'Config': {}}}, networking_config={'EndpointsConfig': {'test_default': {'Aliases': ['some-service'], 'IPAMConfig': {}}}})
compose.cli.verbose_proxy.proxy_callable: docker create_container -> {'Id': '0c739d9e405ef9992caa8228d48bc486bd0d0956400a2d6b428129e1bd910c01',
 'Warnings': []}
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('0c739d9e405ef9992caa8228d48bc486bd0d0956400a2d6b428129e1bd910c01')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': '',
 'Args': ['pwd'],
 'Config': {'AttachStderr': True,
            'AttachStdin': True,
            'AttachStdout': True,
            'Cmd': ['pwd'],
            'Domainname': '',
            'Entrypoint': ['/docker-entrypoint.sh'],
            'Env': ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
                    'NGINX_VERSION=1.19.9',
...
compose.parallel.parallel_execute_iter: Finished processing: ServiceName(project='test', service='some-service', number=1)
Creating test_some-service_run ... done
compose.parallel.feed_queue: Pending: set()
compose.parallel.parallel_execute_iter: Finished processing: <Service: some-service>
compose.parallel.feed_queue: Pending: set()
compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network <- ('0c739d9e405ef9992caa8228d48bc486bd0d0956400a2d6b428129e1bd910c01', 'test_default')
compose.cli.verbose_proxy.proxy_callable: docker disconnect_container_from_network -> None
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network <- ('0c739d9e405ef9992caa8228d48bc486bd0d0956400a2d6b428129e1bd910c01', 'test_default', aliases=[], ipv4_address=None, ipv6_address=None, links=[], link_local_ips=None)
compose.cli.verbose_proxy.proxy_callable: docker connect_container_to_network -> None
compose.cli.main.call_docker: /usr/local/bin/docker start --attach --interactive 0c739d9e405ef9992caa8228d48bc486bd0d0956400a2d6b428129e1bd910c01
/home/root
 PASS  test/index.test.ts (144.365 s)
  ✓ ensure container gets started (13424 ms)
  ✓ ensure exit code is returned correctly (3155 ms)
  ✓ ensure container command executed with --workdir command option (2412 ms)
  ✓ ensure only single container gets started (2245 ms)
  ✓ ensure only multiple containers get started (2574 ms)
  ✓ ensure container gets down (2278 ms)
  ✓ ensure container gets stopped (2907 ms)
  ✓ ensure only single container gets stopped (2738 ms)
  ✓ ensure only single container gets paused then resumed (4939 ms)
  ✓ ensure container gets started with --abort-on-container-exit option (2587 ms)
  ✓ ensure container gets started with --abort-on-container-exit option correctly aborts all services when a container exits (2352 ms)
  ✓ ensure container gets killed (2745 ms)
  ✓ ensure custom ymls are working (2154 ms)
  ✓ ensure run and exec are working (4341 ms)
  ✓ ensure run and exec with command defined as array are working (4536 ms)
  ✓ build accepts config as string (2190 ms)
  ✓ build single service (1654 ms)
  ✓ build multiple services (2015 ms)
  ✓ build all services (3515 ms)
  ✓ pull single service (6827 ms)
  ✓ pull multiple services (10596 ms)
  ✓ pull all services (12526 ms)
  ✓ teardown (22 ms)
  ✓ config show data for docker-compose files (486 ms)
  ✓ config show data for docker-compose files (services) (422 ms)
  ✓ config show data for docker-compose files (volumes) (428 ms)
  ✓ ps shows status data for started containers (3563 ms)
  ✓ ps does not show status data for stopped containers (3593 ms)
  ✓ restartAll does restart all containers (4214 ms)
  ✓ restartMany does restart selected containers (4246 ms)
  ✓ restartOne does restart container (3565 ms)
  ✓ logs does follow service logs (2930 ms)
  ✓ returns the port for a started service (2307 ms)
  ✓ removes container (2990 ms)
  ✓ returns version information (408 ms)
  ✓ parse ps output (2 ms)
  starts containers properly with --build and --timeout options
    ✓ ensure container gets started with --build option (6327 ms)
    ✓ ensure container gets started with --build and --timeout option (5699 ms)
    ✓ ensure container gets started with --build and --timeout option with different command style (5612 ms)

Test Suites: 2 passed, 2 total
Tests:       44 passed, 44 total
Snapshots:   0 total
Time:        144.754 s
Ran all test suites matching /test/i.
✨  Done in 146.01s.

@Steveb-p
Copy link
Contributor

I am not making any calls to process.exit, this code executes upon SIGINT. The 'exit' event code that you linked is also never reached when calling .down.

Does the process "hang" until interrupted, or does it simply exit after calling .down?

@KenEucker
Copy link
Author

KenEucker commented Oct 17, 2021

@Steveb-p the process doesn't hang, it just "exits" that async method, almost as if the promise resolved, and continues executing the lines after "bringItDown" is called.

@AlexZeitler I cloned anew, yarn install and yarn test, and now the tests are being found and completed successfully. I will try to use the tests here to narrow down the cause of my issue.

@Steveb-p
Copy link
Contributor

Steveb-p commented Oct 17, 2021

@Steveb-p the process doesn't hang, it just "exits" that async method, almost as if the promise resolved, and continues executing the lines after "bringItDown" is called.

This for me means that it's almost certain that the subprocess was created and it never exited. It fits your description. That's the only situation where this particular promise would be left without resolution, because the promise is resolved only when the subprocess exits. I'd suggest attaching an output stream and seeing exactly what it says. My guess would be that it's waiting for a confirmation.

console.log calls from your example are never executed, because the promise never resolves.

Code after bringItDown function is executed, because it's asynchronous. I can only assume that you actually do not wait for the promise to be resolved.

@KenEucker
Copy link
Author

KenEucker commented Oct 18, 2021

@Steveb-p I will share my exact code, in hopes that it isn't too confusing. Here's the code I am using for two separate docker environments, being loaded separately, and calling upAll (not shown below, as that part does work). I know that my WordPress container starts but my Redis does not (simple port collision). I can access the WordPress installation (pictured below) when the application is running.

The close methods are called upon exit, or SIGINT, and is the code I have been discussing here.
redis
Screen Shot 2021-10-17 at 4 52 07 PM

wordpress
Screen Shot 2021-10-17 at 4 52 15 PM

You can see from my logs, that WordPress starts, Redis does not. You can also see that upon close, the issue I am experiencing through the logs.
Screen Shot 2021-10-17 at 4 51 22 PM

Accessing the WordPress installation:
Screen Shot 2021-10-17 at 4 51 07 PM

The 🤖 Stopped 🤖 message comes from the main application which is calling each of the close methods, demonstrating that the application continues sequentially as expected (because of async/await) before ending as expected.
Screen Shot 2021-10-17 at 4 51 44 PM

After resolving the port issue with Redis, you can see from the change in logs the same experience as the WordPress container.
Screen Shot 2021-10-17 at 5 00 13 PM

The docker containers have been started and remain up after closing my application:
Screen Shot 2021-10-17 at 5 03 32 PM

I am unsure how to add more logging to this situation, or how to attach an output stream to this specific code. I won't ask for your assistance in this area, but I do feel comfortable trying to follow an example of such being done with the source code for this project as I can now get the tests to run.

Again, I appreciate the help and suggestions.

@AlexZeitler
Copy link
Contributor

Not sure if this is an issue (never tried this) but you're using await and then together.

@Steveb-p
Copy link
Contributor

Not sure if this is an issue (never tried this) but you're using await and then together.

Technically this should not change much, await is basically a Generator wrapper around .then and .catch calls. Since .then returns a Promise, it should work exactly as we expect here.

I am unsure how to add more logging to this situation, or how to attach an output stream to this specific code. I won't ask for your assistance in this area, but I do feel comfortable trying to follow an example of such being done with the source code for this project as I can now get the tests to run.

I've looked it up and apparently you can't do that (attach the streams) atm. That's because

docker-compose/src/index.ts

Lines 167 to 170 in dd4fe76

const childProc = childProcess.spawn(executablePath, composeArgs, {
cwd,
env
})

doesn't allow passing other options to the spawned process 😕 I kinda assumed it was possible.

See child_process.spawn reference: https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

We're looking for stdio option.

I'll have a look if we can patch this after work.

@rubengmurray
Copy link

rubengmurray commented Sep 26, 2022

@Steveb-p did you find a solution to this? I'm also seeing issues with .down(). I run mine at the end of an entire mocha test suite, on Node 14.18.2. My experience is that the process hangs; if I put a log before the await, and after the await, only the log before the await prints... and then nothing even after minutes of waiting...

console.log('stopping docker');
await dockerCompose.down();
console.log('stopping docker2');

docker-compose: 0.23.17

I just went through the process of upgrading the service in question to 16.10.0 as mentioned above, and I get the same experience.

To sanity check I ran docker compose down via the cli in the folder in question and it tore down the containers immediately.

@rubengmurray
Copy link

rubengmurray commented Sep 26, 2022

For additional context:

During the mocha test suite, at the beginning I run upAll; two global hooks, one to setup, and the other to teardown at the end.

The upAll works every time, the down never works. One thing I have noticed is that the child process spawned by the down command has a pid: undefined if you log out the child_process. I can't see that this is a good thing, and I wonder therefore if this process even starts?

For the time being, I've just gone with this as a workaround as my teardown:

execSync('docker compose down', {
  cwd: `${process.cwd()}/tests/integration`,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants