-
Notifications
You must be signed in to change notification settings - Fork 1
/
compose.go
61 lines (51 loc) · 1.5 KB
/
compose.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"dagger/mikael-elkiaer/internal/dagger"
_ "embed"
)
//go:embed assets/update_images.bash
var script string
type Compose struct {
// Current state
Container *dagger.Container
}
// Submodule for Docker Compose
func (m *MikaelElkiaer) Compose(
ctx context.Context,
) *Compose {
c := m.compose(ctx)
return &Compose{Container: c}
}
// Update image tags for all services
func (m *Compose) UpdateImages(
ctx context.Context,
// Docker Compose file
file *dagger.File,
) *dagger.File {
c := m.Container.
WithNewFile("script.bash", script).
WithFile("docker-compose.yaml", file).
WithExec(inSh("bash", "script.bash"))
f := c.File("docker-compose.yaml")
return f
}
func (m *MikaelElkiaer) compose(
ctx context.Context,
) *dagger.Container {
c := dag.Container().
From("docker.io/library/alpine:3.21.0@sha256:21dc6063fd678b478f57c0e13f47560d0ea4eeba26dfc947b2a4f81f686b9f45").
WithExec(inSh("apk add bash=5.2.21-r0 npm=10.2.5-r0 skopeo=1.14.0-r2 yq=4.35.2-r3")).
WithExec(inSh("npm install --global [email protected]"))
for _, cred := range m.Creds {
c = c.WithRegistryAuth("ghcr.io", cred.UserId, cred.UserSecret).
WithEnvVariable("__URL", cred.Url).
WithEnvVariable("__USERNAME", cred.UserId).
WithSecretVariable("__PASSWORD", cred.UserSecret).
WithExec(inSh("echo $__PASSWORD | skopeo login --username $__USERNAME --password-stdin $__URL")).
WithoutSecretVariable("__PASSWORD").
WithoutEnvVariable("__USERNAME").
WithoutEnvVariable("__URL")
}
return c
}