Created
May 3, 2024 22:46
-
-
Save elee/03b4c4a9d4351e26ed9be5c4e69e55a4 to your computer and use it in GitHub Desktop.
Dagger With Socket Sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"context" | |
"errors" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"path/filepath" | |
"strings" | |
"time" | |
"dagger.io/dagger" | |
) | |
func main() { | |
ctx := context.Background() | |
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout)) | |
if err != nil { | |
panic(err) | |
} | |
defer client.Close() | |
directory := client.Directory() | |
// create socket | |
//socket := client.Host().UnixSocket("/tmp/my_socket") | |
// create consumer container | |
consumer := client.Container().From("alpine:latest"). | |
WithExec(strings.Split("apk add netcat-openbsd socat", " ")). | |
WithDirectory("/tmp", directory). | |
WithExec(strings.Split("nc -lU /tmp/my_socket", " ")) | |
// create producer container | |
stdout, err := client.Container().From("alpine:latest"). | |
WithServiceBinding("consumer", consumer.AsService()). | |
WithDirectory("/tmp", directory). | |
WithExec(strings.Split("apk add netcat-openbsd socat", " ")). | |
WithExec(strings.Split(`printf Yee | nc -U /tmp/my_socket`, " ")). | |
Stdout(ctx) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(stdout) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But switching the path to
/my_socket
and extracting just thatFile
and re-mounting usingWithFile
hangs