aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Dodrill <xena@yolo-swag.com>2015-02-11 22:55:45 -0800
committerSam Dodrill <xena@yolo-swag.com>2015-02-11 22:55:45 -0800
commitd689dbbfcf12e7c2e538d2e2347ab1a84f4972db (patch)
tree81ce660985ec8482937c4c4920b9a358368f7150
parenta2b30628aaa4edfd4b0a58d5205e174b4f08f019 (diff)
downloadx-d689dbbfcf12e7c2e538d2e2347ab1a84f4972db.tar.xz
x-d689dbbfcf12e7c2e538d2e2347ab1a84f4972db.zip
Add first draft of the Dokku tool
-rw-r--r--dokku/.gitignore1
-rw-r--r--dokku/config.go11
-rw-r--r--dokku/dokku.cfg.sample2
-rw-r--r--dokku/main.go61
4 files changed, 75 insertions, 0 deletions
diff --git a/dokku/.gitignore b/dokku/.gitignore
new file mode 100644
index 0000000..ae9366d
--- /dev/null
+++ b/dokku/.gitignore
@@ -0,0 +1 @@
+dokku
diff --git a/dokku/config.go b/dokku/config.go
new file mode 100644
index 0000000..74c5e0b
--- /dev/null
+++ b/dokku/config.go
@@ -0,0 +1,11 @@
+package main
+
+type Config struct {
+ Server map[string]*Server
+}
+
+type Server struct {
+ SSHKey string // if blank default key will be used.
+ Host string // hostname of the dokku server
+ User string // if blank username will be dokku
+}
diff --git a/dokku/dokku.cfg.sample b/dokku/dokku.cfg.sample
new file mode 100644
index 0000000..b914ebe
--- /dev/null
+++ b/dokku/dokku.cfg.sample
@@ -0,0 +1,2 @@
+[server "default"]
+host = panel.apps.xeserv.us
diff --git a/dokku/main.go b/dokku/main.go
new file mode 100644
index 0000000..67bb3bc
--- /dev/null
+++ b/dokku/main.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "strings"
+
+ "code.google.com/p/gcfg"
+ "github.com/hypersleep/easyssh"
+)
+
+var (
+ cfgPath = flag.String("cfg", "", "configuration path, default is ~/.dokku.cfg")
+ serverName = flag.String("server", "default", "server to use out of dokku config")
+)
+
+func main() {
+ flag.Parse()
+
+ if *cfgPath == "" {
+ *cfgPath = os.Getenv("HOME") + "/.dokku.cfg"
+ }
+
+ var cfg Config
+ err := gcfg.ReadFileInto(&cfg, *cfgPath)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ var server *Server
+ var ok bool
+
+ if server, ok = cfg.Server[*serverName]; !ok {
+ log.Fatalf("server %s not defined in configuration file %s", *serverName, *cfgPath)
+ }
+
+ if server.User == "" {
+ server.User = "dokku"
+ }
+
+ if server.SSHKey == "" {
+ server.SSHKey = "/.ssh/id_rsa"
+ }
+
+ ssh := &easyssh.MakeConfig{
+ User: server.User,
+ Server: server.Host,
+ Key: server.SSHKey,
+ }
+
+ command := strings.Join(flag.Args(), " ")
+
+ res, err := ssh.Run(command)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Print(res)
+}