Skip to content

Instantly share code, notes, and snippets.

@pjmagee
Created August 27, 2024 17:22
Show Gist options
  • Save pjmagee/66bff2ccb9df24f2b3d5c9379c0d0784 to your computer and use it in GitHub Desktop.
Save pjmagee/66bff2ccb9df24f2b3d5c9379c0d0784 to your computer and use it in GitHub Desktop.
type Fakedeploy struct {
Approved bool
}
func (m *Fakedeploy) WithApproval() (*Fakedeploy, error) {
response, _ := dag.Container().
From("alpine").
WithMountedCache("/tmp/replies", dag.CacheVolume(fmt.Sprintf("reply-%d", time.Now()))).
Terminal(dagger.ContainerTerminalOpts{
Cmd: []string{
"sh",
"-c",
"read -p 'Deploy: ' && echo $REPLY > /tmp/replies/reply"},
}).
WithExec([]string{"echo", fmt.Sprintf("'cache buster %s'", time.Now())}).
WithExec([]string{"cat", "/tmp/replies/reply"}).
Stdout(context.Background())
m.Approved = strings.Contains(response, "yes")
return m, nil
}
func (m *Fakedeploy) Deploy() (string, error) {
if m.Approved == true {
return dag.Container().
From("ubuntu:latest").
WithExec([]string{"echo", "Deploying..."}).
WithExec([]string{"sleep", "5"}).
WithExec([]string{"echo", "Deployed"}).Stdout(context.Background())
} else {
return "deployment not approved", nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment