Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
98 lines (90 loc) · 2.23 KB
/
Copy pathmain.go
File metadata and controls
98 lines (90 loc) · 2.23 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"context"
"log"
pkg "github.com/benjaminstrasser/buildvault/pkg"
"github.com/docker/docker/client"
)
func main() {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
log.Fatalf("Error creating Docker client: %v", err)
}
defer cli.Close()
// First task: create a text file
task1 := pkg.Task{
Name: "generate-file",
BaseImage: "alpine:latest",
Commands: []string{
"mkdir data",
"echo 'hello world' > /data/test.txt",
"echo 'additional content' >> /data/test.txt",
"mkdir -p /output",
"cat /data/test.txt > /output/test.txt",
"cat /output/test.txt",
},
}
// Second task: use the file from the first task
task2 := pkg.Task{
Name: "use-file",
BaseImage: "alpine:latest",
Dependencies: []pkg.Dependency{
{
Task: &task1,
Artifacts: []pkg.Artifact{
{
From: "/output/test.txt",
To: "/output/test.txt",
},
},
},
},
Commands: []string{
"cat /output/test.txt",
"echo 'modified by second task' >> /output/test.txt",
"mkdir -p /final",
"cat /output/test.txt > /final/modified.txt",
"cat /final/modified.txt",
},
}
// Third task: use files from both previous tasks
task3 := pkg.Task{
Name: "combine-files",
BaseImage: "alpine:latest",
Dependencies: []pkg.Dependency{
{
Task: &task2,
Artifacts: []pkg.Artifact{
{
From: "/final/modified.txt",
To: "/final/modified.txt",
},
},
},
{
Task: &task1,
Artifacts: []pkg.Artifact{
{
From: "/output/test.txt",
To: "/output/test.txt",
},
},
},
},
Commands: []string{
"mkdir -p /combined",
"echo '--- Original file ---' > /combined/combined.txt",
"cat /output/test.txt >> /combined/combined.txt",
"echo '\n--- Modified file ---' >> /combined/combined.txt",
"cat /final/modified.txt >> /combined/combined.txt",
"cat /combined/combined.txt",
},
}
log.Println("Executing third task...")
if err := task3.Execute(ctx, cli); err != nil {
log.Fatalf("Error executing third task: %v", err)
}
log.Println("All tasks completed successfully")
log.Println("Containers are preserved with their artifacts")
}