Esempio n. 1
0
func RegistryCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	ac := docker.AuthConfiguration{
		Username:      GetForm(r, "username"),
		Password:      GetForm(r, "password"),
		Email:         GetForm(r, "email"),
		ServerAddress: GetForm(r, "serveraddress"),
	}

	_, err := models.DockerLogin(ac)

	if err != nil {
		return httperr.Errorf(400, "Could not login to server with provided credentials")
	}

	env, acs, err := models.GetPrivateRegistriesAuth()

	if err != nil {
		return httperr.Server(err)
	}

	acs[ac.ServerAddress] = ac

	dat, err := json.Marshal(acs)

	if err != nil {
		return httperr.Server(err)
	}

	env["DOCKER_AUTH_DATA"] = string(dat)

	err = models.PutRackSettings(env)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, ac)
}
Esempio n. 2
0
// Set up rack instance Docker environment for builds
// Log into all configured private registries
// Pull down latest images for all apps
func StartImages() {
	var log = logger.New("ns=app_images")

	if os.Getenv("DEVELOPMENT") == "true" {
		return
	}

	// doing this in development updates a ~/.docker file and causes a rerun loop
	models.LoginRegistries()

	maxRetries := 5
	var err error

	for i := 0; i < maxRetries; i++ {
		err = models.DockerLogin(docker.AuthConfiguration{
			Email:         "*****@*****.**",
			Username:      "******",
			Password:      os.Getenv("PASSWORD"),
			ServerAddress: os.Getenv("REGISTRY_HOST"),
		})

		if err == nil {
			break
		}

		time.Sleep(30 * time.Second)
	}

	if err != nil {
		return
	}

	apps, err := models.ListApps()

	if err != nil {
		log.Error(err)
		return
	}

	for _, app := range apps {
		a, err := models.GetApp(app.Name)

		if err != nil {
			log.Error(err)
			continue
		}

		for key, value := range a.Parameters {
			if strings.HasSuffix(key, "Image") {

				log.Log("cmd=%q", fmt.Sprintf("docker pull %s", value))
				data, err := exec.Command("docker", "pull", value).CombinedOutput()

				if err != nil {
					fmt.Printf("%+v\n", string(data))
					log.Error(err)
					continue
				}
			}
		}
	}
}