Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. const Docker = require('dockerode');
  2.  
  3. const names = ['redis', 'nats', 'postgres'];
  4.  
  5. const name = process.argv[2];
  6.  
  7. if (!names.includes(name)) process.exit(1);
  8.  
  9. (async () => {
  10. const host = process.env.DOCKER_HOST;
  11.  
  12. let dockerOptions;
  13. if (host) dockerOptions = { host };
  14. const docker = new Docker(dockerOptions || { socketPath: '/var/run/docker.sock' });
  15.  
  16. const stage = process.argv[3];
  17. if (!stage) throw new Error('Env stage does not specified as argument.');
  18.  
  19. const containerName = `fixpoint.${stage}.${name}`;
  20. const containersList = await docker.listContainers({ all: true });
  21. let containerRef = containersList.find(container => container.Names.includes(`/${containerName}`));
  22. try {
  23. if (containerRef) {
  24. const container = docker.getContainer(containerRef.Id);
  25. await container.stop();
  26. }
  27. } catch (err) {
  28. process.exit(1);
  29. }
  30. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement