Skip to content

Commit

Permalink
parameterize environment via config files
Browse files Browse the repository at this point in the history
when enviornment variable PRODUCTION is set,
then the configs/prod.json file is used for both
gotty and ui
  • Loading branch information
tahmmee committed May 9, 2017
1 parent 12c88d7 commit 22018b6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import OrangeMuiTheme from './OrangeMuiTheme';
import FullScreen from 'react-fullscreen';
import CopyToClipboard from 'react-copy-to-clipboard';

var Config = require('Config')

const muiTheme = OrangeMuiTheme;
// Needed for onTouchTap
// http://stackoverflow.com/a/34015469/988941
Expand Down Expand Up @@ -329,7 +331,6 @@ class Container extends React.Component {
var ttySession = this.state.ttySessions[tabIndex]
var refreshId = this.getNewSession()
var url = ttySession.url+"&refresh="+refreshId
console.log(url)
var newFrame = <ReusableIframe url={url} id={ttySession.session} />
this.setState(state => {
state.ttySessions[tabIndex].frame = newFrame;
Expand All @@ -343,7 +344,7 @@ class Container extends React.Component {

startSession(servers, build, toyBuild, platform){
var session = this.getNewSession()
var url = "http://localhost:7021?arg=servers:"+servers+"&arg=build:"+build+"&arg=platform:"+platform
var url = "http://"+Config.gottyHost+"?arg=servers:"+servers+"&arg=build:"+build+"&arg=platform:"+platform
if (toyBuild != ""){
url = url+"&arg=build_override:"+toyBuild
}
Expand Down
4 changes: 4 additions & 0 deletions configs/dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dockerHost": "127.0.0.1:2375",
"gottyHost": "127.0.0.1:7021"
}
4 changes: 4 additions & 0 deletions configs/prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dockerHost": "172.23.98.197:2375",
"gottyHost": "172.23.98.197:7021"
}
13 changes: 11 additions & 2 deletions gotty.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CLIENT=$1

if [ -z $CLIENT ]; then
echo "usage: ./gotty.sh <docker_host:port>"
exit -1

# fall back to json file
CONFIG="prod.json"
if [ -z $PRODUCTION ]; then
CONFIG="dev.json"
fi
CLIENT=$(cat "configs/$CONFIG" | grep dockerHost | awk '{print $2}' | sed -e 's/,//' -e 's/"//g')
fi

echo "Starting with docker host: $CLIENT"
echo "=========================="
gotty -w -p 7021 --timeout 0 --permit-arguments --title-format "ToastTY - {{ .Command }} ({{ .Hostname }})" ./scripts/session.sh $CLIENT 2>&1 | tee /tmp/gotty.log
7 changes: 5 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ module.exports = {
presets: ['react', 'es2015']
}
}]
}
};
},
externals: {
'Config': JSON.stringify(process.env.ENV === 'PRODUCTION' ? require('./configs/prod.json') : require('./configs/dev.json'))
}
};

0 comments on commit 22018b6

Please sign in to comment.