-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (64 loc) · 1.2 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
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
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/exec"
"github.com/gorilla/mux"
)
type container struct {
registry string
image string
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/{registry}/{image}", RocketHandler)
http.Handle("/", r)
http.ListenAndServe(":8080", r)
}
func RocketHandler(res http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
reg, ok := vars["registry"]
if !ok {
res.WriteHeader(http.StatusBadRequest)
return
}
img, ok := vars["image"]
if !ok {
res.WriteHeader(http.StatusBadRequest)
}
c := container{
registry: repo,
image: img,
}
err := pullImage(c)
if err != nil {
res.WriteHeader(http.StatusNotFound)
return
}
return
}
func pullImage(c container) error {
cmd := exec.Command("docker", "pull", nameFromC(c))
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
log.Println("ERROR:", err)
return err
}
return nil
}
func runImage() {}
func inspectImage() {}
func exportImage() {}
func rmImage() {}
func createManifest() {}
func packageAci() {}
func nameFromC(c container) string {
if c.registry != nil {
return fmt.Sprintf("%s/%s", c.registry, c.image)
}
return fmt.Sprintf("%s", c.image)
}