Last active
November 16, 2016 17:41
-
-
Save eschwartz/ad4be7d7d0da845a5c6651abc81d8b3b to your computer and use it in GitHub Desktop.
Generate a Kubernetes ReplicationController
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
// See https://gist.github.com/eschwartz/4f16fcb963954d433753ffe32ce5d5ca | |
const ReplicationController = require('./ReplicationController'); | |
const fs = require('fs-extra'); | |
// See https://gist.github.com/eschwartz/310a7d9938b60eaf49c8d56c1ccfb759 | |
const loadS3Env = require('./loadS3Env'); | |
const path = require('path'); | |
const Cli = require('admiral-cli'); | |
const co = require('co'); | |
function main() { | |
return co(function*() { | |
const cliParams = parseCliParams(); | |
const params = require(cliParams.paramsFile); | |
// Load .env file from S3 | |
const env = yield loadS3Env(params.envFile); | |
// Create the ReplicationController | |
const rc = ReplicationController(Object.assign({ env }, params)); | |
// Write files | |
fs.outputJsonSync(path.join(cliParams.outDir, 'ReplicationController.json'), rc); | |
}); | |
} | |
main() | |
.then(() => { | |
console.log('Done.'); | |
process.exit(0); | |
}) | |
.catch(err => { | |
console.error(err); | |
process.exit(1); | |
}); | |
function parseCliParams() { | |
const cli = new Cli() | |
.option({ | |
name: 'paramsFile', | |
description: 'Location of params.json file', | |
type: 'path', | |
shortFlag: '-c', | |
longFlag: '--config', | |
length: 1, | |
required: true | |
}) | |
.option({ | |
name: 'outDir', | |
description: 'Where to output generated k8s config file', | |
type: 'path', | |
shortFlag: '-o', | |
longFlag: '--output', | |
length: 1, | |
required: false | |
}); | |
return cli.parse(); | |
} |
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
// See https://gist.github.com/eschwartz/4f16fcb963954d433753ffe32ce5d5ca | |
import {IOptions as IRcOptions, default as ReplicationController} from './ReplicationController'; | |
import * as fs from 'fs-extra'; | |
// See https://gist.github.com/eschwartz/310a7d9938b60eaf49c8d56c1ccfb759 | |
import loadS3Env from './loadS3Env'; | |
import * as path from 'path'; | |
const Cli = <any>require('admiral-cli'); | |
async function main() { | |
const cliParams = parseCliParams(); | |
const params = <IDeployParams>require(cliParams.paramsFile); | |
// Load .env file from S3 | |
const env = await loadS3Env(params.envFile); | |
// Create the ReplicationController | |
const rc = ReplicationController(Object.assign({ env }, params)); | |
// Write files | |
fs.outputJsonSync(path.join(cliParams.outDir, 'ReplicationController.json'), rc); | |
} | |
main() | |
.then(() => { | |
console.log('Done.'); | |
process.exit(0); | |
}) | |
.catch(err => { | |
console.error(err); | |
process.exit(1); | |
}); | |
interface IDeployParams extends IRcOptions { | |
envFile: string; | |
} | |
interface ICliParams { | |
paramsFile: string; | |
outDir: string; | |
} | |
function parseCliParams():ICliParams { | |
const cli = new Cli() | |
.option({ | |
name: 'paramsFile', | |
description: 'Location of params.json file', | |
type: 'path', | |
shortFlag: '-c', | |
longFlag: '--config', | |
length: 1, | |
required: true | |
}) | |
.option({ | |
name: 'outDir', | |
description: 'Where to output generated k8s config file', | |
type: 'path', | |
shortFlag: '-o', | |
longFlag: '--output', | |
length: 1, | |
required: false | |
}); | |
return <ICliParams>cli.parse(); | |
} |
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
{ | |
"name": "my-app", | |
"version": "v1.0.0", | |
"image": "myorg/my-app:1.0.0", | |
"replicas": 1, | |
"envFile": "s3://path/to/env/file", | |
"imagePullPolicy": "IfNotPresent", | |
"volumes": [{ | |
"name": "data-mount", | |
"server": "us-east-1a.XXXX.efs.us-east-1.amazonaws.com", | |
"path": "/", | |
"mountPath": "/mnt/data" | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment