Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Docker = require('dockerode');
- const names = ['redis', 'nats', 'postgres'];
- const name = process.argv[2];
- if (!names.includes(name)) process.exit(1);
- (async () => {
- const host = process.env.DOCKER_HOST;
- let dockerOptions;
- if (host) dockerOptions = { host };
- const docker = new Docker(dockerOptions || { socketPath: '/var/run/docker.sock' });
- const stage = process.argv[3];
- if (!stage) throw new Error('Env stage does not specified as argument.');
- const containerName = `fixpoint.${stage}.${name}`;
- const containersList = await docker.listContainers({ all: true });
- let containerRef = containersList.find(container => container.Names.includes(`/${containerName}`));
- try {
- if (containerRef) {
- const container = docker.getContainer(containerRef.Id);
- await container.stop();
- }
- } catch (err) {
- process.exit(1);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement