-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (46 loc) · 1.46 KB
/
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
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"flag"
"fmt"
"github.com/gofn/gofn"
"github.com/gofn/gofn/provision"
)
func main() {
contextDir := flag.String("contextDir", "./", "a string")
dockerfile := flag.String("dockerfile", "Dockerfile", "a string")
imageName := flag.String("imageName", "", "a string")
remoteBuildURI := flag.String("remoteBuildURI", "", "a string")
volumeSource := flag.String("volumeSource", "", "a string")
volumeDestination := flag.String("volumeDestination", "", "a string")
input := flag.String("input", "", "a string")
flag.Parse()
stdout, err := run(*contextDir, *dockerfile, *imageName, *remoteBuildURI, *volumeSource, *volumeDestination, *input)
if err != nil {
fmt.Println("Error: ", err)
return
}
fmt.Println("Stdout: ", stdout)
}
func run(contextDir, dockerfile, imageName, remoteBuildURI, volumeSource, volumeDestination string, input string) (stdout string, err error) {
buildOpts := &provision.BuildOptions{
ContextDir: contextDir,
Dockerfile: dockerfile,
ImageName: imageName,
RemoteURI: remoteBuildURI,
StdIN: input,
}
containerOpts := &provision.ContainerOptions{}
if volumeSource != "" {
if volumeDestination == "" {
volumeDestination = volumeSource
}
containerOpts.Volumes = []string{fmt.Sprintf("%s:%s", volumeSource, volumeDestination)}
}
// TODO: remote (IaaS) support
stdout, stderr, err := gofn.Run(context.Background(), buildOpts, containerOpts)
if stderr != "" {
stdout = stderr
}
return
}