siemonster :: implementation of parent's network
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
#from golang as builder
|
||||
#
|
||||
#RUN mkdir /app
|
||||
#WORKDIR /app
|
||||
#COPY worker.go /app/worker.go
|
||||
#
|
||||
#RUN go get github.com/docker/docker/api/types
|
||||
#RUN go get github.com/docker/docker/api/types/container
|
||||
#RUN go get -u github.com/docker/docker/client
|
||||
#
|
||||
#RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o worker .
|
||||
#
|
||||
from golang as builder
|
||||
|
||||
# THis is a workaround until I get docker/docker to build in a dockerfile
|
||||
# PS: This is tricky to google.
|
||||
# Might not work on some machines.
|
||||
from scratch
|
||||
#COPY --from=builder /app/ /
|
||||
COPY worker.bin /worker.bin
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["./worker.bin"]
|
||||
RUN go get github.com/docker/docker/api/types && \
|
||||
go get github.com/docker/docker/api/types/container && \
|
||||
go get -u github.com/docker/docker/client
|
||||
|
||||
COPY worker.go /app/worker.go
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o worker .
|
||||
|
||||
|
||||
FROM alpine:3.12
|
||||
RUN apk add --no-cache bash
|
||||
COPY --from=builder /app/ /
|
||||
|
||||
CMD ["./worker"]
|
||||
|
||||
@@ -11,12 +11,12 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
network "github.com/docker/docker/api/types/network"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
)
|
||||
|
||||
@@ -412,9 +412,26 @@ func shutdown(executionId, workflowId string) {
|
||||
os.Exit(3)
|
||||
}
|
||||
|
||||
// form container id of current running container
|
||||
func getThisContainerId() string {
|
||||
containerId := ""
|
||||
cmd := fmt.Sprintf("head -1 /proc/self/cgroup | cut -d/ -f3")
|
||||
out, err := exec.Command("bash","-c",cmd).Output()
|
||||
if err == nil {
|
||||
containerId = strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
return containerId
|
||||
}
|
||||
|
||||
// Deploys the internal worker whenever something happens
|
||||
func deployApp(cli *dockerclient.Client, image string, identifier string, env []string) error {
|
||||
// figure out current container id
|
||||
containerId := getThisContainerId()
|
||||
|
||||
hostConfig := &container.HostConfig{
|
||||
NetworkMode: container.NetworkMode(fmt.Sprintf("container:%s", containerId)),
|
||||
IpcMode: container.IpcMode(fmt.Sprintf("container:%s", containerId)),
|
||||
LogConfig: container.LogConfig{
|
||||
Type: "json-file",
|
||||
Config: map[string]string{},
|
||||
@@ -426,23 +443,11 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
|
||||
Env: env,
|
||||
}
|
||||
|
||||
networkConfig := &network.NetworkingConfig{}
|
||||
shuffleNetwork := os.Getenv("DOCKER_NETWORK")
|
||||
if len(shuffleNetwork) > 0 {
|
||||
networkConfig = &network.NetworkingConfig{
|
||||
EndpointsConfig: map[string]*network.EndpointSettings{
|
||||
shuffleNetwork: {
|
||||
NetworkID: shuffleNetwork,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
cont, err := cli.ContainerCreate(
|
||||
context.Background(),
|
||||
config,
|
||||
hostConfig,
|
||||
networkConfig,
|
||||
nil,
|
||||
nil,
|
||||
identifier,
|
||||
)
|
||||
@@ -1107,13 +1112,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
shuffleNetwork := os.Getenv("DOCKER_NETWORK")
|
||||
if len(shuffleNetwork) > 0 {
|
||||
log.Printf("Running with Docker network %s", shuffleNetwork)
|
||||
} else {
|
||||
log.Printf("No docker network specified for Worker.")
|
||||
}
|
||||
|
||||
// WORKER_TESTING_WORKFLOW should be a workflow ID
|
||||
authorization := ""
|
||||
executionId := ""
|
||||
|
||||
Reference in New Issue
Block a user