Created
April 14, 2023 13:37
-
-
Save rjferguson21/e623db934d25663cb659a101d6a620a4 to your computer and use it in GitHub Desktop.
main.go
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 ( | |
"context" | |
"fmt" | |
"os" | |
"time" | |
"dagger.io/dagger" | |
) | |
func main() { | |
if err := build(context.Background()); err != nil { | |
fmt.Println(err) | |
} | |
} | |
func build(ctx context.Context) error { | |
fmt.Println("Building with Dagger") | |
// initialize Dagger client | |
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout)) | |
if err != nil { | |
return err | |
} | |
defer client.Close() | |
bbci := client.Container(). | |
From("rjferguson21/bb-ci"). | |
WithUnixSocket("/var/run/docker.sock", client.Host().UnixSocket("/var/run/docker.sock")). | |
WithEnvVariable("BUST", time.Now().String()). | |
WithExposedPort(6443, dagger.ContainerWithExposedPortOpts{Protocol: "TCP"}). | |
WithExec([]string{"k3d", "cluster", "create", "dagger-cluster", "--kubeconfig-update-default", "--api-port=6443"}). | |
WithExec([]string{"sleep", "180"}) | |
_, err = client.Container(). | |
From("rjferguson21/bb-ci"). | |
WithEnvVariable("BUST", time.Now().String()). | |
WithServiceBinding("k3d", bbci). | |
WithExec([]string{"sed", "-i", fmt.Sprintf(`s/0\.0\.0\.0/%s/g`, "k3d"), "/root/.kube/config"}). | |
WithExec([]string{"kubectl", "get", "pods"}). | |
Stdout(ctx) | |
if err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment