Merge pull request #8 from xetorthio/stack_name
Allow to specify stack name as a parameter
This commit is contained in:
@@ -27,6 +27,7 @@ func NewSession(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
reqDur := req.Form.Get("session-duration")
|
||||
stack := req.Form.Get("stack")
|
||||
stackName := req.Form.Get("stack_name")
|
||||
|
||||
if stack != "" {
|
||||
stack = formatStack(stack)
|
||||
@@ -42,7 +43,7 @@ func NewSession(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
}
|
||||
duration := services.GetDuration(reqDur)
|
||||
s, err := services.NewSession(duration, stack)
|
||||
s, err := services.NewSession(duration, stack, stackName)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
//TODO: Return some error code
|
||||
|
||||
@@ -59,6 +59,7 @@ type Session struct {
|
||||
PwdIpAddress string `json:"pwd_ip_address"`
|
||||
Ready bool `json:"ready"`
|
||||
Stack string `json:"stack"`
|
||||
StackName string `json:"stack_name"`
|
||||
}
|
||||
|
||||
type sessionBuilderWriter struct {
|
||||
@@ -113,7 +114,7 @@ func (s *Session) DeployStack() error {
|
||||
|
||||
fileName := path.Base(s.Stack)
|
||||
file := fmt.Sprintf("/var/run/pwd/uploads/%s", fileName)
|
||||
cmd := fmt.Sprintf("docker swarm init --advertise-addr eth0 && docker-compose -f %s pull && docker stack deploy -c %s pwd", file, file)
|
||||
cmd := fmt.Sprintf("docker swarm init --advertise-addr eth0 && docker-compose -f %s pull && docker stack deploy -c %s %s", file, file, s.StackName)
|
||||
|
||||
w := sessionBuilderWriter{session: s}
|
||||
code, err := ExecAttach(i.Name, []string{"sh", "-c", cmd}, &w)
|
||||
@@ -300,7 +301,7 @@ func GetDuration(reqDur string) time.Duration {
|
||||
return defaultDuration
|
||||
}
|
||||
|
||||
func NewSession(duration time.Duration, stack string) (*Session, error) {
|
||||
func NewSession(duration time.Duration, stack, stackName string) (*Session, error) {
|
||||
s := &Session{}
|
||||
s.Id = uuid.NewV4().String()
|
||||
s.Instances = map[string]*Instance{}
|
||||
@@ -310,6 +311,10 @@ func NewSession(duration time.Duration, stack string) (*Session, error) {
|
||||
s.Ready = true
|
||||
}
|
||||
s.Stack = stack
|
||||
if stackName == "" {
|
||||
stackName = "pwd"
|
||||
}
|
||||
s.StackName = stackName
|
||||
log.Printf("NewSession id=[%s]\n", s.Id)
|
||||
|
||||
// Schedule cleanup of the session
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<form id="welcomeFormBypass" method="POST" action="/">
|
||||
<button id="start" type="submit">Start Session</button>
|
||||
<input id="stack" type="hidden" name="stack" value=""/>
|
||||
<input id="stack_name" type="hidden" name="stack_name" value=""/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
@@ -37,5 +38,9 @@
|
||||
if (stack) {
|
||||
document.getElementById('stack').value = stack;
|
||||
}
|
||||
var stackName = getParameterByName('stack_name');
|
||||
if (stack) {
|
||||
document.getElementById('stack_name').value = stackName;
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<div id="recaptcha" class="g-recaptcha" data-callback="iAmHuman" data-sitekey="{{.}}"></div>
|
||||
<input type="hidden" name="session-duration" value="4h"/>
|
||||
<input id="stack" type="hidden" name="stack" value=""/>
|
||||
<input id="stack_name" type="hidden" name="stack_name" value=""/>
|
||||
<button id="create" style="display:none;">Create session</button>
|
||||
</form>
|
||||
<img src="/assets/large_h.png" />
|
||||
@@ -38,6 +39,10 @@
|
||||
if (stack) {
|
||||
document.getElementById('stack').value = stack;
|
||||
}
|
||||
var stackName = getParameterByName('stack_name');
|
||||
if (stackName) {
|
||||
document.getElementById('stack_name').value = stackName;
|
||||
}
|
||||
if (document.cookie.indexOf('session_id') > -1) {
|
||||
document.getElementById('create').style = "";
|
||||
document.getElementById('recaptcha').style = "display:none;";
|
||||
|
||||
Reference in New Issue
Block a user