|
|
@ -12,6 +12,7 @@ type CodeFirstContainer struct {
|
|
|
|
ID string `json:"Id"`
|
|
|
|
ID string `json:"Id"`
|
|
|
|
Image string `json:"Image"`
|
|
|
|
Image string `json:"Image"`
|
|
|
|
Env []string `json:"Env,omitempty"`
|
|
|
|
Env []string `json:"Env,omitempty"`
|
|
|
|
|
|
|
|
Admins string `json:"Admins,omitempty"`
|
|
|
|
Private bool `json:"Private,omitempty"`
|
|
|
|
Private bool `json:"Private,omitempty"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -33,7 +34,7 @@ var (
|
|
|
|
|
|
|
|
|
|
|
|
command string
|
|
|
|
command string
|
|
|
|
proxyScheme, proxyHost, proxyPath string
|
|
|
|
proxyScheme, proxyHost, proxyPath string
|
|
|
|
imageName, containerName string
|
|
|
|
imageName, containerName, admins string
|
|
|
|
|
|
|
|
|
|
|
|
private, overwrite, devel bool
|
|
|
|
private, overwrite, devel bool
|
|
|
|
|
|
|
|
|
|
|
@ -53,6 +54,7 @@ func main() {
|
|
|
|
|
|
|
|
|
|
|
|
flag.StringVar(&imageName, "imagename", "", "image name")
|
|
|
|
flag.StringVar(&imageName, "imagename", "", "image name")
|
|
|
|
flag.StringVar(&containerName, "containername", "", "container name")
|
|
|
|
flag.StringVar(&containerName, "containername", "", "container name")
|
|
|
|
|
|
|
|
flag.StringVar(&admins, "admins", "", "admins (comma separated list)")
|
|
|
|
flag.BoolVar(&private, "private", false, "private container")
|
|
|
|
flag.BoolVar(&private, "private", false, "private container")
|
|
|
|
flag.BoolVar(&overwrite, "overwrite", false, "overwrite existing container")
|
|
|
|
flag.BoolVar(&overwrite, "overwrite", false, "overwrite existing container")
|
|
|
|
flag.Var(&env, "env", "environment variables (separated by spaces)")
|
|
|
|
flag.Var(&env, "env", "environment variables (separated by spaces)")
|
|
|
@ -63,6 +65,7 @@ func main() {
|
|
|
|
fmt.Printf("-imagename: %s\n", imageName)
|
|
|
|
fmt.Printf("-imagename: %s\n", imageName)
|
|
|
|
fmt.Printf("-containername: %s\n", containerName)
|
|
|
|
fmt.Printf("-containername: %s\n", containerName)
|
|
|
|
fmt.Printf("-private: %t\n", private)
|
|
|
|
fmt.Printf("-private: %t\n", private)
|
|
|
|
|
|
|
|
fmt.Printf("-admins: %s\n", admins)
|
|
|
|
fmt.Printf("-overwrite: %t\n", overwrite)
|
|
|
|
fmt.Printf("-overwrite: %t\n", overwrite)
|
|
|
|
fmt.Printf("-env: %s\n", env)
|
|
|
|
fmt.Printf("-env: %s\n", env)
|
|
|
|
|
|
|
|
|
|
|
@ -77,7 +80,7 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if devel {
|
|
|
|
if devel {
|
|
|
|
authUser = "thbellem"
|
|
|
|
authUser = "thomas.bellembois"
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
authUser = os.Getenv("DRONE_REPO_OWNER")
|
|
|
|
authUser = os.Getenv("DRONE_REPO_OWNER")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,7 +118,7 @@ func exist() bool {
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := client.R().
|
|
|
|
resp, err := client.R().
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
Get(fmt.Sprintf("%s://%s/containers/%s/json", proxyScheme, proxyHost, containerName))
|
|
|
|
Get(fmt.Sprintf("%s://%s/containers/%s/json", proxyScheme, proxyHost, authUser+"-"+containerName))
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
@ -151,7 +154,7 @@ func logs() {
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := client.R().
|
|
|
|
resp, err := client.R().
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
Get(fmt.Sprintf("%s://%s/containers/%s/logs", proxyScheme, proxyHost, containerName))
|
|
|
|
Get(fmt.Sprintf("%s://%s/containers/%s/logs", proxyScheme, proxyHost, authUser+"-"+containerName))
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
@ -177,7 +180,7 @@ func start() {
|
|
|
|
resp, err := client.R().
|
|
|
|
resp, err := client.R().
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
SetBody(container).
|
|
|
|
SetBody(container).
|
|
|
|
Post(fmt.Sprintf("%s://%s/containers/%s/start", proxyScheme, proxyHost, containerName))
|
|
|
|
Post(fmt.Sprintf("%s://%s/containers/%s/start", proxyScheme, proxyHost, authUser+"-"+containerName))
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
@ -198,12 +201,13 @@ func create() {
|
|
|
|
Image: imageName,
|
|
|
|
Image: imageName,
|
|
|
|
Env: env.value,
|
|
|
|
Env: env.value,
|
|
|
|
Private: private,
|
|
|
|
Private: private,
|
|
|
|
|
|
|
|
Admins: admins,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := client.R().
|
|
|
|
resp, err := client.R().
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
SetBody(container).
|
|
|
|
SetBody(container).
|
|
|
|
Post(fmt.Sprintf("%s://%s/containers/create/%s", proxyScheme, proxyHost, containerName))
|
|
|
|
Post(fmt.Sprintf("%s://%s/containers/create/%s", proxyScheme, proxyHost, authUser+"-"+containerName))
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
@ -222,7 +226,7 @@ func delete(bypassError bool) {
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := client.R().
|
|
|
|
resp, err := client.R().
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
SetHeader("x-forwarded-user", authUser).
|
|
|
|
Delete(fmt.Sprintf("%s://%s/containers/%s", proxyScheme, proxyHost, containerName))
|
|
|
|
Delete(fmt.Sprintf("%s://%s/containers/%s", proxyScheme, proxyHost, authUser+"-"+containerName))
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(err)
|
|
|
|