First commit.

master
Thomas BELLEMBOIS 2 years ago
commit 10824fd4bb

@ -0,0 +1,20 @@
kind: pipeline
type: docker
name: build
trigger:
event:
- push
steps:
- name: docker-build
image: plugins/docker
settings:
dockerfile: Dockerfile
context: .
registry: hub.codefirst.iut.uca.fr
repo: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerrunner-client-cd
username:
from_secret: SECRET_REGISTRY_USERNAME
password:
from_secret: SECRET_REGISTRY_PASSWORD

23
.gitignore vendored

@ -0,0 +1,23 @@
# ---> Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work

@ -0,0 +1,102 @@
# options for analysis running
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 1m
# exit code when at least one issue was found, default is 1
issues-exit-code: 0
# include test files or not, default is true
tests: false
# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- wasm
- static
- node_modules
- documents
- docker
- bind-*
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: mod
# Allow multiple parallel golangci-lint instances running.
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: true
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
# default is "colored-line-number"
format: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
print-linter-name: true
# make issues output unique by line, default is true
uniq-by-line: true
# add a prefix to the output file references; default is no prefix
path-prefix: ""
# sorts results by: filepath, line and column
sort-results: false
# all available settings of specific linters
linters-settings:
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
staticcheck:
# Select the Go version to target. The default is '1.13'.
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: ["all"]
stylecheck:
# Select the Go version to target. The default is '1.13'.
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: ["all"]
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
linters:
enable:
# go install github.com/kisielk/errcheck@latest
# go install github.com/gordonklaus/ineffassign@latest
# go install honnef.co/go/tools/cmd/staticcheck@latest
# go install gitlab.com/opennota/check/cmd/varcheck@latest
# go install github.com/go-critic/go-critic/cmd/gocritic@latest
- errcheck
- staticcheck
- stylecheck
- ineffassign
- varcheck
- gofmt
- gocritic
- wsl
fast: false

@ -0,0 +1,18 @@
FROM golang:1.19-bullseye
LABEL author="Thomas Bellembois"
# Copying sources.
WORKDIR /go/src/codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-client-cd/v2/
COPY . .
# Installing.
RUN go install -v ./...
RUN chmod +x /go/bin/codefirst-dockerrunner-client-cd
# Copying entrypoint.
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
USER root
EXPOSE 8081
ENTRYPOINT [ "/entrypoint.sh" ]

@ -0,0 +1,11 @@
# codefirst-dockerrunner-client-cd
run server with:
```
go run . -test
```
run with:
```
./codefirst-dockerrunner-client-cd -wshost localhost:8081 -imagename nginx -containername nginx -username tbellembois -password mypassword -createcontainer
```

@ -0,0 +1,61 @@
package main
import (
"context"
"os"
"time"
clientfactory "codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2"
"codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2/messagesender"
"nhooyr.io/websocket"
)
type MessageSenderCD struct {
*messagesender.AbstractMessageSender
context context.Context
cancelFunc context.CancelFunc
}
func NewMessageSenderCD() *MessageSenderCD {
context, cancelFunc := context.WithTimeout(context.Background(), 60*time.Minute)
a := &messagesender.AbstractMessageSender{}
c := &MessageSenderCD{
a,
context,
cancelFunc,
}
a.IMessageSender = c
return c
}
func (m *MessageSenderCD) GetContext() context.Context {
return m.context
}
func (m *MessageSenderCD) GetCancelFunc() context.CancelFunc {
return m.cancelFunc
}
func (m *MessageSenderCD) GetDialOptions() *websocket.DialOptions {
return &websocket.DialOptions{
HTTPHeader: map[string][]string{"X-Forwarded-User": {os.Getenv("DRONE_REPO_OWNER")}},
}
}
type ClientCD struct {
*clientfactory.AbstractClient
}
func NewClientCD() *ClientCD {
a := &clientfactory.AbstractClient{}
c := &ClientCD{
a,
}
a.IClient = c
return c
}

@ -0,0 +1,127 @@
package main
import (
"fmt"
"os"
"codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2/messages"
)
func (c *ClientCD) Log(message string) {
fmt.Println(message)
}
func (c *ClientCD) ErrorCallback(m messages.WSMessage) {
fmt.Printf("%+v (%s)\n", m.Error, m.Error.SourceErrorMessage)
os.Exit(1)
}
func (c *ClientCD) BeforeCreateContainerCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Creating container %s from image %s.", m.Container.Name, m.Container.ImageURL))
c.Log(fmt.Sprintf("-> container: %+v", m.Container))
}
func (c *ClientCD) AfterCreateContainerCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Container %s created with ID %s.", m.Container.Name, m.Container.ID))
}
func (c *ClientCD) BeforeExecContainerCallback(m messages.WSMessage) {
}
func (c *ClientCD) AfterExecContainerCallback(m messages.WSMessage) {
fmt.Println(m.Message)
nbExecCommand--
if nbExecCommand == 0 {
os.Exit(0)
}
}
func (c *ClientCD) BeforeStartContainerCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Starting container %s.", m.Container.Name))
}
func (c *ClientCD) AfterStartContainerCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Container %s started.", m.Container.Name))
c.Log("Bye !")
os.Exit(0)
}
func (c *ClientCD) BeforeRemoveContainerCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Removing container %s (ID %s).", m.Container.Name, m.Container.ID))
}
func (c *ClientCD) AfterRemoveContainerCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Container %s removed.", m.Container.Name))
if action != "create" {
c.Log("Bye !")
os.Exit(0)
}
}
func (c *ClientCD) BeforeGetContainersCallback(m messages.WSMessage) {
c.Log("Getting the running containers.")
}
func (c *ClientCD) AfterGetContainersCallback(m messages.WSMessage) {
for _, container := range m.Containers {
c.Log(fmt.Sprintf("name: %s - id: %s", container.Name, container.ID))
}
}
func (c *ClientCD) BeforeGetContainerWithSameNameCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Getting containers with name %s.", m.Container.Name))
}
func (c *ClientCD) AfterGetContainerWithSameNameCallback(m messages.WSMessage) {}
func (c *ClientCD) BeforeGetContainerLogCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Getting log for container %s.", m.Container.Name))
}
func (c *ClientCD) AfterGetContainerLogCallback(m messages.WSMessage) {
c.Log(m.Message)
}
func (c *ClientCD) BeforePullImageCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Pulling image %s.", m.Container.ImageURL))
}
func (c *ClientCD) AfterPullImageCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Image pulled %s.", m.Container.ImageURL))
}
func (c *ClientCD) BeforeGetConfigCallback(m messages.WSMessage) {
c.Log("Getting server configuration.")
}
func (c *ClientCD) AfterGetConfigCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("maximum allowed containers: %d", m.Config.MaxAllowedContainers))
}
func (c *ClientCD) BeforePingCallback(m messages.WSMessage) {
c.Log("Pinging server websocket.")
}
func (c *ClientCD) AfterPingCallback(m messages.WSMessage) {
c.Log("Received pong from server websocket.")
}
func (c *ClientCD) BeforeTestCallback(m messages.WSMessage) {
c.Log("Sending test message")
}
func (c *ClientCD) AfterTestCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Received test message answer: %s", m.Message))
}
func (c *ClientCD) BeforeTestErrorCallback(m messages.WSMessage) {
c.Log("Sending error test message")
}
func (c *ClientCD) AfterTestErrorCallback(m messages.WSMessage) {
c.Log(fmt.Sprintf("Received error test message answer: %s", m.Message))
}

@ -0,0 +1,109 @@
#!/usr/bin/env bash
WSScheme=""
WSHost=""
WSPath=""
ImageName=""
ContainerName=""
UserName=""
Password=""
Private=""
Overwrite=""
Env=""
Command=""
Action=""
if [ ! -z "$WSSCHEME" ]
then
WSScheme="-wsscheme $WSSCHEME"
fi
if [ ! -z "$WSHOST" ]
then
WSHost="-wshost $WSHOST"
fi
if [ ! -z "$WSPATH" ]
then
WSPath="-wspath $WSPATH"
fi
if [ ! -z "$IMAGENAME" ]
then
ImageName="-imagename $IMAGENAME"
fi
if [ ! -z "$CONTAINERNAME" ]
then
ContainerName="-containername $CONTAINERNAME"
fi
if [ ! -z "$USERNAME" ]
then
UserName="-username $USERNAME"
fi
if [ ! -z "$PASSWORD" ]
then
Password="-password $PASSWORD"
fi
if [ ! -z "$PRIVATE" ]
then
Private="-private"
fi
if [ ! -z "$OVERWRITE" ]
then
Overwrite="-overwrite"
fi
if [ ! -z "$ACTION" ]
then
Action="-action $ACTION"
fi
prefix="CODEFIRST_CLIENTCD_ENV_"
ENVS=$(env | awk -F "=" '{print $1}' | grep ".*$prefix.*")
if [ ! -z "$ENVS" ]
then
Env=""
arrayEnv=($ENVS)
for i in "${arrayEnv[@]}"
do
envVarName=${i#"$prefix"}
Env=$Env" -env $envVarName=${!i}"
done
fi
prefix="CODEFIRST_CLIENTCD_COMMAND_"
COMMANDS=$(env | awk -F "=" '{print $1}' | grep ".*$prefix.*")
if [ ! -z "$COMMANDS" ]
then
Command=""
arrayCommand=($COMMANDS)
for i in "${arrayCommand[@]}"
do
Command=$Command" -command '${!i}'"
done
fi
echo $WSScheme
echo $WSHost
echo $WSPath
echo $Action
echo $ImageName
echo $ContainerName
echo $Private
echo $Overwrite
echo $Env
echo $Command
echo $UserName
#/go/bin
sh -c "/go/bin/codefirst-dockerrunner-client-cd $WSScheme $WSHost $WSPath $ImageName $ContainerName $UserName $Password $Private $Overwrite $Env $Action $Command"

@ -0,0 +1,20 @@
module codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-client-cd/v2
go 1.19
require nhooyr.io/websocket v1.8.7
require (
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220905135931-270d2cb5b1f8 // indirect
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 v2.0.0-20220905134948-382dd0bb6a40 // indirect
github.com/docker/docker v20.10.17+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
)
// replace codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 => /home/thbellem/workspace/workspace_go/src/codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory
// replace codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 => /home/thbellem/workspace/workspace_go/src/codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common

124
go.sum

@ -0,0 +1,124 @@
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220518150725-924546f39f21 h1:lMEipufmhbKywTyonu7wHkEEwjDAKK2y4/3OyEpU3mw=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220518150725-924546f39f21/go.mod h1:51XIesezqw5nZXlvrpxIyF5frQX4Ldhi3BNDg5mX9UI=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220613121144-8e92045b8087 h1:3V97dLk71gGG9yNFfrtxtDp/MCRZwfSxdKAMRCwBq6o=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220613121144-8e92045b8087/go.mod h1:f7U6sRvOEqEwslnSUHSLEcZ2S28CXyuyTCvuz/YRaC8=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220705094016-df436862166c h1:Zr47zI2Pkw3jCvoG+OjejL3uFIUdPIWfixiRbe7J/io=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220705094016-df436862166c/go.mod h1:10UQ9XVDTntZdaZEdPAoIxG5x1FWx7VfsFlXWipMoL0=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220705122551-aee982eeab95 h1:85FLJK3NWklNbCWkl5K4bjDTyY+1oO3muZjoaM42EpA=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220705122551-aee982eeab95/go.mod h1:10UQ9XVDTntZdaZEdPAoIxG5x1FWx7VfsFlXWipMoL0=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220905135931-270d2cb5b1f8 h1:/ux+k1mpoImdgHczIqUWvJmmf0py9qQwXhpWQ1oTtPY=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-clientfactory/v2 v2.0.0-20220905135931-270d2cb5b1f8/go.mod h1:ik5yhkzastrPuoJUqBukWj2izASCctnuoYfar2p9glo=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 v2.0.0-20220518150401-ba5cd613b3ed h1:NjYlFI4M76YkEAFrmEH67czp+keOqP4o4aXBlZHf/hc=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 v2.0.0-20220518150401-ba5cd613b3ed/go.mod h1:+WAHZHR8U1lAxbBTcIVteE0l4NOtVPBBX23g/JH5s04=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 v2.0.0-20220705085106-ea5914d79d2a h1:fhSeZG8qYqFkfkidSJKPA9H6w1Q6snNtj2WAKoCvTDU=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 v2.0.0-20220705085106-ea5914d79d2a/go.mod h1:V0N5z2WX2KuygdIcnIUJQhuLG4rA2I59hsTSaV8lV/0=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 v2.0.0-20220905134948-382dd0bb6a40 h1:ou1weZVETrbacumoahqQKL/hpZeBvhqOsSWJyfrK328=
codefirst.iut.uca.fr/git/thomas.bellembois/codefirst-dockerrunner-common/v2 v2.0.0-20220905134948-382dd0bb6a40/go.mod h1:MSH3IGekA6C4WhkkYoVYzTkmPoERMLJHjudjaMDjSwQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/docker v20.10.17+incompatible h1:JYCuMrWaVNophQTOrMMoSwudOVEfcegoZZrleKc1xwE=
github.com/docker/docker v20.10.17+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.15.4 h1:1kn4/7MepF/CHmYub99/nNX8az0IJjfSOU/jbnTVfqQ=
github.com/klauspost/compress v1.15.4/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.15.6 h1:6D9PcO8QWu0JyaQ2zUMmu16T1T+zjjEpP91guRsvDfY=
github.com/klauspost/compress v1.15.6/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.15.7 h1:7cgTQxJCU/vy+oP/E3B9RGbQTgbiVzIJWIKOLoAsPok=
github.com/klauspost/compress v1.15.7/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=

@ -0,0 +1,135 @@
package main
import (
"flag"
"fmt"
"os"
)
type StringSliceFlag struct {
value []string
}
func (s *StringSliceFlag) String() string {
return fmt.Sprintf("%s", *s)
}
func (s *StringSliceFlag) Set(v string) error {
s.value = append(s.value, v)
return nil
}
var (
imageName, containerName, username, password, action string
wsScheme, wsHost, wsPath string
private, overwrite bool
env, command StringSliceFlag
nbExecCommand int
splittedCommand []string
)
func init() {
env = StringSliceFlag{}
flag.StringVar(&wsScheme, "wsscheme", "ws", "websocket scheme")
flag.StringVar(&wsHost, "wshost", "dockerrunner:8081", "websocket host")
flag.StringVar(&wsPath, "wspath", "/", "websocket path")
flag.StringVar(&action, "action", "create", "action to perform (create, exec)")
flag.StringVar(&imageName, "imagename", "", "registry image name")
flag.StringVar(&containerName, "containername", "", "container name")
flag.StringVar(&username, "username", "", "registry username")
flag.StringVar(&password, "password", "", "registry password")
flag.BoolVar(&private, "private", false, "private container")
flag.BoolVar(&overwrite, "overwrite", false, "overwrite existing container")
flag.Var(&env, "env", "environment variables (separated by spaces)")
flag.Var(&command, "command", "command to execute (separated by spaces)")
flag.Parse()
fmt.Println("flags:")
fmt.Printf("-action: %s\n", action)
fmt.Printf("-imagename: %s\n", imageName)
fmt.Printf("-containername: %s\n", containerName)
fmt.Printf("-username: %s\n", username)
fmt.Printf("-private: %t\n", private)
fmt.Printf("-overwrite: %t\n", overwrite)
fmt.Printf("-env: %s\n", env)
fmt.Printf("-command: %s\n", command)
if containerName == "" {
fmt.Println("Missing parameter.")
os.Exit(1)
}
if action == "create" && imageName == "" {
fmt.Println("Missing parameter for create.")
os.Exit(1)
}
if action == "exec" && len(command.String()) == 0 {
fmt.Println("Missing parameter for exec.")
os.Exit(1)
}
}
// test with:
// docker network create cicd_net
// docker run --name dockerrunner -p80:8081 -v /var/run/docker.sock:/var/run/docker.sock --env TEST=test hub.codefirst.iut.uca.fr/thbellem/codefirst-dockerrunner:latest
// go run . -wshost localhost -imagename mariadb -containername mariadb -env MARIADB_ROOT_PASSWORD=rootpass -env MARIADB_DATABASE=acteur -env MARIADB_USER=user -env MARIADB_PASSWORD=user
// go run . -wshost localhost -imagename nginx -containername nginx
func main() {
messageSenderCD := NewMessageSenderCD()
clientCD := NewClientCD()
clientCD.MessageSender = messageSenderCD.AbstractMessageSender
clientCD.WSScheme = wsScheme
clientCD.WSHost = wsHost
clientCD.WSPath = wsPath
clientCD.ConnectServer()
clientCD.Run()
switch action {
case "create":
clientCD.MessageSender.StartContainer(imageName, containerName, username, password, private, overwrite, env.value)
case "exec":
nbExecCommand = len(command.value)
for _, currentCommand := range command.value {
currentCharIndex := 0
currentCommandIndex := 0
isCommandBlock := false
splittedCommand = []string{""}
runeCurrentCommand := []rune(currentCommand)
for currentCharIndex < len(runeCurrentCommand) {
currentChar := runeCurrentCommand[currentCharIndex]
switch currentChar {
case '"', '\'', '`':
isCommandBlock = !isCommandBlock
splittedCommand[currentCommandIndex] += string(currentChar)
case ' ':
if !isCommandBlock {
splittedCommand = append(splittedCommand, "")
currentCommandIndex++
} else {
splittedCommand[currentCommandIndex] += string(currentChar)
}
default:
splittedCommand[currentCommandIndex] += string(currentChar)
}
currentCharIndex++
}
fmt.Printf("executing command: %+v - len: %d\n", splittedCommand, len(splittedCommand))
clientCD.MessageSender.ExecContainer(containerName, username, splittedCommand, env.value)
}
}
forever := make(chan bool)
<-forever
}
Loading…
Cancel
Save