Add container admins.
This commit is contained in:
27
README.md
Normal file
27
README.md
Normal file
@@ -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
|
||||||
|
```
|
@@ -9,6 +9,7 @@ Overwrite=""
|
|||||||
Private=""
|
Private=""
|
||||||
Env=""
|
Env=""
|
||||||
Command=""
|
Command=""
|
||||||
|
Admins=""
|
||||||
|
|
||||||
if [ ! -z "$PROXYSCHEME" ]
|
if [ ! -z "$PROXYSCHEME" ]
|
||||||
then
|
then
|
||||||
@@ -40,6 +41,12 @@ then
|
|||||||
Command="-command $COMMAND"
|
Command="-command $COMMAND"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -z "$ADMINS" ]
|
||||||
|
then
|
||||||
|
Admins="-admins $ADMINS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ ! -z "$PRIVATE" ]
|
if [ ! -z "$PRIVATE" ]
|
||||||
then
|
then
|
||||||
Private="-private"
|
Private="-private"
|
||||||
@@ -73,8 +80,9 @@ echo $ImageName
|
|||||||
echo $ContainerName
|
echo $ContainerName
|
||||||
echo $Overwrite
|
echo $Overwrite
|
||||||
echo $Private
|
echo $Private
|
||||||
|
echo $Admins
|
||||||
echo $Env
|
echo $Env
|
||||||
echo $Command
|
echo $Command
|
||||||
|
|
||||||
#/go/bin
|
#/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"
|
||||||
|
18
main.go
18
main.go
@@ -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)
|
||||||
|
Reference in New Issue
Block a user