Last active
January 31, 2017 18:10
-
-
Save baruchvlz/c450bbe928a7b1ade253499d7a8fa0dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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