Skip to content

Instantly share code, notes, and snippets.

@baruchvlz
Last active January 31, 2017 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baruchvlz/c450bbe928a7b1ade253499d7a8fa0dd to your computer and use it in GitHub Desktop.
Save baruchvlz/c450bbe928a7b1ade253499d7a8fa0dd to your computer and use it in GitHub Desktop.
/**
Simple automation for Docker deployment with different environment files. Essentially end result
is to pass a enviroment when calling the file so that the correct compose file is copied into
the root directory.
*/
(function() {
'use strict';
// imports
const process = require('process');
const fs = require('fs');
// list of allowed environment variables, adjust as needed
const allowedEnvs = ['dev', 'stage', 'prod'];
// node = argv[0]
// deploy-docker.js = argv[1]
let env = process.argv[2];
if(!allowedEnvs.includes(env)) {
throw TypeError(`Wrong option passed`);
}
// read correspoding file depending on environment variable
fs.readFile(`${__dirname}/docker_files/docker-compose.${env}.yml`, 'utf-8', (error, data) => {
if(error) throw Error(error);
// write `docker-compose.yml` file in parent directory
fs.writeFile(`${__dirname}/../docker-compose.yml`, data, 'utf-8', error => {
if(error) throw Error(error);
// congratulate user for being awesome
console.log(
`File 'docker-compose.${env}.yml' succesfully moved to 'docker-compse.yml' in parent directory`
);
});
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment