From faaf8d2d04c594c63917d6c75869425029d5357e Mon Sep 17 00:00:00 2001 From: frikky Date: Sat, 1 Jan 2022 23:37:13 +0100 Subject: [PATCH] Added automatic orborus network attachment to worker in swarm mode --- backend/go-app/go.mod | 4 ++-- docker-compose.yml | 4 ++-- functions/onprem/orborus/build.sh | 2 +- functions/onprem/orborus/orborus.go | 14 +++++++++++++- functions/onprem/worker/build.sh | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/backend/go-app/go.mod b/backend/go-app/go.mod index 30d5e46e..0bf89375 100644 --- a/backend/go-app/go.mod +++ b/backend/go-app/go.mod @@ -2,7 +2,7 @@ module main go 1.15 -replace github.com/shuffle/shuffle-shared => ../../../../git/shuffle-shared +//replace github.com/shuffle/shuffle-shared => ../../../../git/shuffle-shared //replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi //replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch @@ -22,7 +22,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/h2non/filetype v1.1.1 github.com/satori/go.uuid v1.2.0 - github.com/shuffle/shuffle-shared v0.1.61 + github.com/shuffle/shuffle-shared v0.1.62 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect go4.org v0.0.0-20201209231011-d4a079459e60 // indirect golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 diff --git a/docker-compose.yml b/docker-compose.yml index 063f5669..a7bd17b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: frontend: - build: ./frontend + #build: ./frontend image: ghcr.io/frikky/shuffle-frontend:nightly container_name: shuffle-frontend hostname: shuffle-frontend @@ -16,7 +16,7 @@ services: depends_on: - backend backend: - build: ./backend + #build: ./backend image: ghcr.io/frikky/shuffle-backend:nightly container_name: shuffle-backend hostname: ${BACKEND_HOSTNAME} diff --git a/functions/onprem/orborus/build.sh b/functions/onprem/orborus/build.sh index 1fbf5e93..342a14c2 100644 --- a/functions/onprem/orborus/build.sh +++ b/functions/onprem/orborus/build.sh @@ -1,5 +1,5 @@ NAME=shuffle-orborus -VERSION=0.9.44 +VERSION=0.9.45 echo "Running docker build with $NAME:$VERSION" #docker rmi frikky/shuffle:$NAME --force diff --git a/functions/onprem/orborus/orborus.go b/functions/onprem/orborus/orborus.go index 1075eb0a..9b6ce709 100644 --- a/functions/onprem/orborus/orborus.go +++ b/functions/onprem/orborus/orborus.go @@ -28,7 +28,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" - //"github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/swarm" //"github.com/docker/docker/api/types/filters" dockerclient "github.com/docker/docker/client" @@ -214,6 +214,18 @@ func deployServiceWorkers(image string) { log.Printf("[DEBUG] Failed to create network %s for workers: %s. This is not critical, and containers will still be added", networkName, err) } } + + //containerId = strings.TrimSpace(string(out)) + if containerId != "" { + log.Printf("\n\nShould connect orborus container to worker network as it's running in Docker with name %#v!\n\n", containerId) + // https://pkg.go.dev/github.com/docker/docker@v20.10.12+incompatible/api/types/network#EndpointSettings + networkConfig := &network.EndpointSettings{} + err := dockercli.NetworkConnect(ctx, networkName, containerId, networkConfig) + if err != nil { + log.Printf("[WARNING] Failed connecting to Orborus to docker network %s: %s", networkName, err) + } + } + //serviceOptions := types.ServiceCreateOptions{} //service, err := dockercli.ServiceCreate( // context.Background(), diff --git a/functions/onprem/worker/build.sh b/functions/onprem/worker/build.sh index 162794b4..3b9a9b74 100644 --- a/functions/onprem/worker/build.sh +++ b/functions/onprem/worker/build.sh @@ -1,5 +1,5 @@ NAME=shuffle-worker -VERSION=0.9.44 +VERSION=0.9.45 echo "Running docker build with $NAME:$VERSION" #CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o worker.bin .