-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
41 lines (37 loc) · 812 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"context"
"fmt"
"os"
"time"
"dagger.io/dagger"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
ctx := context.Background()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
return err
}
defer client.Close()
projectName := "test"
database := client.Container().From("mysql:8.0").
WithEnvVariable("MYSQL_DATABASE", projectName).
WithEnvVariable("MYSQL_USER", projectName).
WithEnvVariable("MYSQL_PASSWORD", projectName).
WithEnvVariable("MYSQL_ALLOW_EMPTY_PASSWORD", "true").
WithExposedPort(3306).
AsService()
database, err = database.Start(ctx)
if err != nil {
return err
}
time.Sleep(30 * time.Second)
database, err = database.Stop(ctx)
return err
}