Files
play-with-docker/api.go
Jonathan Leibiusky 3f5b3882dd Multiple playgrounds support (#215)
* Add Playground struct and basic support for creating it and retrieving
it

* Add missing functions in pwd mock

* Get playground from request domain and validate it exists. If valid set
it on the newly created session.

* Move playground specific configurations to the playground struct and use
it everytime we need that conf.

* Don't allow to specify a duration bigger that the allowed in the
playground
2017-11-14 15:50:04 -03:00

75 lines
2.2 KiB
Go

package main
import (
"log"
"os"
"time"
"github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/handlers"
"github.com/play-with-docker/play-with-docker/id"
"github.com/play-with-docker/play-with-docker/provisioner"
"github.com/play-with-docker/play-with-docker/pwd"
"github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/play-with-docker/play-with-docker/scheduler"
"github.com/play-with-docker/play-with-docker/scheduler/task"
"github.com/play-with-docker/play-with-docker/storage"
)
func main() {
config.ParseFlags()
e := initEvent()
s := initStorage()
f := initFactory(s)
ipf := provisioner.NewInstanceProvisionerFactory(provisioner.NewWindowsASG(f, s), provisioner.NewDinD(id.XIDGenerator{}, f, s))
sp := provisioner.NewOverlaySessionProvisioner(f)
core := pwd.NewPWD(f, e, s, sp, ipf)
tasks := []scheduler.Task{
task.NewCheckPorts(e, f),
task.NewCheckSwarmPorts(e, f),
task.NewCheckSwarmStatus(e, f),
task.NewCollectStats(e, f, s),
}
sch, err := scheduler.NewScheduler(tasks, s, e, core)
if err != nil {
log.Fatal("Error initializing the scheduler: ", err)
}
sch.Start()
d, err := time.ParseDuration(config.DefaultSessionDuration)
if err != nil {
log.Fatalf("Cannot parse duration %s. Got: %v", config.DefaultSessionDuration, err)
}
playground := types.Playground{Domain: config.PlaygroundDomain, DefaultDinDInstanceImage: config.DefaultDinDImage, AllowWindowsInstances: config.NoWindows, DefaultSessionDuration: d, AvailableDinDInstanceImages: []string{config.DefaultDinDImage}}
if _, err := core.PlaygroundNew(playground); err != nil {
log.Fatalf("Cannot create default playground. Got: %v", err)
}
handlers.Bootstrap(core, e)
handlers.Register(nil)
}
func initStorage() storage.StorageApi {
s, err := storage.NewFileStorage(config.SessionsFile)
if err != nil && !os.IsNotExist(err) {
log.Fatal("Error initializing StorageAPI: ", err)
}
return s
}
func initEvent() event.EventApi {
return event.NewLocalBroker()
}
func initFactory(s storage.StorageApi) docker.FactoryApi {
return docker.NewLocalCachedFactory(s)
}