Last active
August 22, 2023 14:33
-
-
Save stobias123/46c7b9dce0506349ddeb6597674f19cd to your computer and use it in GitHub Desktop.
The touch command fails after I copy in a file. -- • Engine: 34af08e4c1b7 (version v0.8.4)
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" | |
"dagger.io/dagger" | |
) | |
func main() { | |
ctx := context.Background() | |
// create a Dagger client | |
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout)) | |
if err != nil { | |
panic(err) | |
} | |
// Write "foo" to a file using standard Golang | |
file, err := os.Create("foo.txt") | |
if err != nil { | |
panic(err) | |
} | |
defer file.Close() | |
_, err = file.WriteString("foo") | |
if err != nil { | |
panic(err) | |
} | |
file.Sync() | |
test_perms_success(client.Pipeline("Test Perms"), ctx) | |
test_perms_fail(client.Pipeline("Fail Perms"), ctx) | |
defer client.Close() | |
} | |
func test_perms_success(client *dagger.Client, ctx context.Context) { | |
dependabotImage := "ghcr.io/dependabot/dependabot-updater-terraform" | |
out, err := client.Container().From(dependabotImage). | |
WithExec( | |
[]string{ | |
"touch", | |
"/home/dependabot/.gitconfig", | |
}).Stdout(ctx) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(out) | |
} | |
func test_perms_fail(client *dagger.Client, ctx context.Context) { | |
dependabotImage := "ghcr.io/dependabot/dependabot-updater-terraform" | |
job := client.Host().File("foo.txt") | |
out, err := client.Container().From(dependabotImage). | |
WithExec( | |
[]string{ | |
"pwd", | |
}). | |
WithExec( | |
[]string{ | |
"whoami", | |
}). | |
WithFile("/home/dependabot/dependabot-updater/job.json", job). | |
WithExec( | |
[]string{ | |
"touch", | |
"/home/dependabot/.gitconfig", | |
}).Stdout(ctx) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment