Esempio n. 1
0
func StartGC() error {
	for {
		client, err := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
		if err != nil {
			return err
		}

		RunGC(client, append(config.Conf.ImagesToNotGC, config.Conf.ImagesToPull...)...)

		time.Sleep(time.Duration(config.Conf.GCIntervalMinutes) * time.Minute)
		config.LoadGlobalConfig()
	}
}
Esempio n. 2
0
func (u DockerResource) postConfig(request *restful.Request, response *restful.Response) {
	var cfg config.Config
	err := request.ReadEntity(&cfg)

	if err != nil {
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
	}

	fmt.Println("Saving config")
	err = config.SaveConfig(&cfg, "")
	if err != nil {
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}

	err = config.LoadGlobalConfig()
	if err != nil {
		response.WriteErrorString(http.StatusInternalServerError, err.Error())
		return
	}
}
Esempio n. 3
0
func main() {
	err := config.LoadGlobalConfig()
	if err != nil {
		log.Fatalf("Failed to load config: %v", err)
	}

	go images.StartGC()
	go images.StartImageUpdate()
	// to see what happens in the package, uncomment the following
	//restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))

	wsContainer := restful.NewContainer()
	u := DockerResource{url: "unix:///var/run/docker.sock"}
	u.Register(wsContainer)

	wsContainer.Filter(func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
		resp.AddHeader("Access-Control-Allow-Origin", "*")
		chain.ProcessFilter(req, resp)
	})

	wsContainer.Handle("/", http.FileServer(assetFS()))

	// Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API
	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
	// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.
	config := swagger.Config{
		WebServices:    wsContainer.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: "http://localhost:8080",
		ApiPath:        "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "/Users/emicklei/xProjects/swagger-ui/dist"}
	swagger.RegisterSwaggerService(config, wsContainer)

	log.Printf("start listening on localhost:8080")
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}