Example #1
0
func PgSQLConsole(app string) error {

	postgreSQLURL, user, password, err := dbURL(app, "SCALINGO_POSTGRESQL", []string{"postgres://"})
	if err != nil {
		return errgo.Mask(err)
	}

	host, port, err := net.SplitHostPort(postgreSQLURL.Host)
	if err != nil {
		return errgo.Newf("%v has an invalid host", postgreSQLURL)
	}

	opts := apps.RunOpts{
		App: app,
		Cmd: []string{"psql"},
		CmdEnv: []string{
			"PGHOST=" + host,
			"PGPORT=" + port,
			"PGUSER="******"PGPASSWORD="******"PGDATABASE=" + user,
		},
	}

	err = apps.Run(opts)
	if err != nil {
		return errgo.Newf("Fail to run PostgreSQL console: %v", err)
	}

	return nil
}
Example #2
0
func MongoConsole(app string) error {

	mongoURL, user, password, err := dbURL(app, "SCALINGO_MONGO", []string{"mongodb://"})
	if err != nil {
		return errgo.Mask(err)
	}

	opts := apps.RunOpts{
		App: app,
		Cmd: []string{"mongo", "-u", user, "-p", password, mongoURL.Host + "/" + user},
	}

	err = apps.Run(opts)
	if err != nil {
		return errgo.Newf("Fail to run MongoDB console: %v", err)
	}

	return nil
}
Example #3
0
func RedisConsole(app string) error {
	redisURL, _, password, err := dbURL(app, "SCALINGO_REDIS", []string{"redis://"})
	if err != nil {
		return errgo.Mask(err)
	}

	host, port, err := net.SplitHostPort(redisURL.Host)
	if err != nil {
		return errgo.Newf("%v has an invalid host", redisURL)
	}

	opts := apps.RunOpts{
		App:           app,
		Cmd:           []string{"redis-cli", "-h", host, "-p", port, "-a", password},
		StdinCopyFunc: redisStdinCopy,
	}

	err = apps.Run(opts)
	if err != nil {
		return errgo.Newf("Fail to run redis console: %v", err)
	}

	return nil
}
Example #4
0
func MySQLConsole(app string) error {

	mySQLURL, user, password, err := dbURL(app, "SCALINGO_MYSQL", []string{"mysql://", "mysql2://"})
	if err != nil {
		return errgo.Mask(err)
	}

	host, port, err := net.SplitHostPort(mySQLURL.Host)
	if err != nil {
		return errgo.Newf("%v has an invalid host", mySQLURL)
	}

	opts := apps.RunOpts{
		App: app,
		Cmd: []string{"mysql", "-h", host, "-P", port, fmt.Sprintf("--password=%v", password), "-u", user, user},
	}

	err = apps.Run(opts)
	if err != nil {
		return errgo.Newf("Fail to run MySQL console: %v", err)
	}

	return nil
}
Example #5
0
File: run.go Project: yannski/cli
   Example
     scalingo run -e VARIABLE=VALUE -e VARIABLE2=OTHER_VALUE rails console

   Furthermore, you may want to upload a file, like a database dump or anything
   useful to you. The option '-f' has been built for this purpose, you can even
   upload multiple files if you wish. You will be able to find these files in the
   '/tmp/uploads' directory of the one-off container.

   Example
     scalingo run -f mysqldump.sql rails dbconsole < /tmp/uploads/mysqldump.sql`,
		Action: func(c *cli.Context) {
			currentApp := appdetect.CurrentApp(c)
			opts := apps.RunOpts{
				App:    currentApp,
				Cmd:    c.Args(),
				CmdEnv: c.StringSlice("e"),
				Files:  c.StringSlice("f"),
			}
			if len(c.Args()) == 0 {
				cli.ShowCommandHelp(c, "run")
			} else if err := apps.Run(opts); err != nil {
				errorQuit(err)
			}
		},
		BashComplete: func(c *cli.Context) {
			autocomplete.CmdFlagsAutoComplete(c, "run")
		},
	}
)