-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghost.go
61 lines (51 loc) · 1.17 KB
/
ghost.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 (
"flag"
"fmt"
"strings"
"bytes"
"archive/tar"
"io"
)
type Archive io.Reader
func PackageFile(content string) (Archive, error) {
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
hdr := &tar.Header{
Name: "Dockerfile",
Size: int64(len(content)),
Typeflag: tar.TypeReg,
}
if err := tw.WriteHeader(hdr); err != nil {
return nil, err
}
if _, err := tw.Write([]byte(content)); err != nil {
return nil, err
}
if err := tw.Close(); err != nil {
return nil, err
}
return buf, nil
}
func main() {
flag.Parse()
args := flag.Args()
packages := strings.Split(args[0], ",")
formatted := FmtName(args[0])
dockerfile := new(Dockerfile)
fmt.Println("SHA: %s", formatted)
MakeDockerfile(packages, dockerfile)
archive, err := PackageFile(dockerfile.Contents())
if err != nil {
fmt.Println("Error compressing file: ", err);
}
fmt.Println("writing Dockerfile to S3 bucket...")
url, err := WriteDockerfile(archive, formatted)
if url != "" {
fmt.Println(url)
} else {
fmt.Println("Error writing Dockerfile: ", err)
}
client := Client{"172.17.42.1:4243", "1.6"}
client.BuildImage(archive)
}