diff --git a/README.md b/README.md new file mode 100644 index 0000000..c7aea14 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +sur le proxy: +``` +docker network create cicd_net +./zig-out/bin/codefirst-dockerproxy -d +``` + +sur le client web: +``` +# Ajuster la constante proxyUrl et proxyPath puis compiler. +docker run --rm -it --volume $(pwd):/app sandrokeil/typescript tsc /app/src/index.ts +mv src/index.js build/src/index.js + +# Build l'image. +docker build -t hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientweb . + +# Run le container. +docker run -p 8081:80 hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientweb +``` + +-> http://localhost:8081/dockerrunner/ + +sur le client cd: +``` +go run . -proxyhost localhost:8080 -devel -command create -imagename nginx -containername nginx1 -admins john.doe,mickey.mouse +go run . -proxyhost localhost:8080 -devel -command create -imagename nginx -containername nginx2 +go run . -proxyhost localhost:8080 -devel -command create -imagename nginx -containername nginx3 +``` \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 1c5fd0b..e2b936d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,6 +9,7 @@ Overwrite="" Private="" Env="" Command="" +Admins="" if [ ! -z "$PROXYSCHEME" ] then @@ -40,6 +41,12 @@ then Command="-command $COMMAND" fi +if [ ! -z "$ADMINS" ] +then + Admins="-admins $ADMINS" +fi + + if [ ! -z "$PRIVATE" ] then Private="-private" @@ -73,8 +80,9 @@ echo $ImageName echo $ContainerName echo $Overwrite echo $Private +echo $Admins echo $Env echo $Command #/go/bin -sh -c "/go/bin/codefirst-dockerproxy-clientdrone $ProxyScheme $ProxyHost $ProxyPath $ImageName $ContainerName $Private $Overwrite $Env $Command" +sh -c "/go/bin/codefirst-dockerproxy-clientdrone $ProxyScheme $ProxyHost $ProxyPath $ImageName $ContainerName $Private $Admins $Overwrite $Env $Command" diff --git a/main.go b/main.go index 344aa02..dc2b656 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ type CodeFirstContainer struct { ID string `json:"Id"` Image string `json:"Image"` Env []string `json:"Env,omitempty"` + Admins string `json:"Admins,omitempty"` Private bool `json:"Private,omitempty"` } @@ -33,7 +34,7 @@ var ( command string proxyScheme, proxyHost, proxyPath string - imageName, containerName string + imageName, containerName, admins string private, overwrite, devel bool @@ -53,6 +54,7 @@ func main() { flag.StringVar(&imageName, "imagename", "", "image name") flag.StringVar(&containerName, "containername", "", "container name") + flag.StringVar(&admins, "admins", "", "admins (comma separated list)") flag.BoolVar(&private, "private", false, "private container") flag.BoolVar(&overwrite, "overwrite", false, "overwrite existing container") flag.Var(&env, "env", "environment variables (separated by spaces)") @@ -63,6 +65,7 @@ func main() { fmt.Printf("-imagename: %s\n", imageName) fmt.Printf("-containername: %s\n", containerName) fmt.Printf("-private: %t\n", private) + fmt.Printf("-admins: %s\n", admins) fmt.Printf("-overwrite: %t\n", overwrite) fmt.Printf("-env: %s\n", env) @@ -77,7 +80,7 @@ func main() { } if devel { - authUser = "thbellem" + authUser = "thomas.bellembois" } else { authUser = os.Getenv("DRONE_REPO_OWNER") } @@ -115,7 +118,7 @@ func exist() bool { resp, err := client.R(). 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 { fmt.Println(err) @@ -151,7 +154,7 @@ func logs() { resp, err := client.R(). 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 { fmt.Println(err) @@ -177,7 +180,7 @@ func start() { resp, err := client.R(). SetHeader("x-forwarded-user", authUser). 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 { fmt.Println(err) @@ -198,12 +201,13 @@ func create() { Image: imageName, Env: env.value, Private: private, + Admins: admins, } resp, err := client.R(). SetHeader("x-forwarded-user", authUser). 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 { fmt.Println(err) @@ -222,7 +226,7 @@ func delete(bypassError bool) { resp, err := client.R(). 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 { fmt.Println(err)