Skip to content

Commit f49ea63

Browse files
aledbfMatthew Fisher
authored andcommitted
ref(builder): remove python and jq from the builder script. replaced by small go apps.
1 parent 0261f04 commit f49ea63

11 files changed

Lines changed: 472 additions & 51 deletions

builder/Dockerfile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,11 @@ RUN apt-get update && apt-get install -yq \
2323
aufs-tools iptables lxc \
2424
lxc-docker-1.3.2
2525

26-
# install jq for parsing json
27-
RUN curl http://stedolan.github.io/jq/download/linux64/jq > /usr/bin/jq && chmod 755 /usr/bin/jq
28-
2926
# configure ssh server
3027
RUN rm /etc/ssh/ssh_host_*
3128
RUN dpkg-reconfigure openssh-server
3229
RUN mkdir -p /var/run/sshd
3330

34-
# install pip
35-
RUN curl -sSL https://raw.githubusercontent.com/pypa/pip/1.5.6/contrib/get-pip.py | python -
36-
37-
# install hook dependencies
38-
RUN pip install pyyaml==3.11 requests==2.4.3
39-
4031
# configure locale
4132
RUN echo LANG="en_US.UTF-8" > /etc/default/locale && dpkg-reconfigure locales
4233

builder/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ include ../includes.mk
33
COMPONENT = builder
44
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
55
DEV_IMAGE = $(DEV_REGISTRY)/$(IMAGE)
6+
BUILD_IMAGE := $(COMPONENT)-build
67

78
build: check-docker
8-
docker build -t $(IMAGE) .
9+
docker build -t $(BUILD_IMAGE) image
10+
@$(eval CID := $(shell docker run -d $(BUILD_IMAGE)))
11+
docker cp $(CID):/go/bin/extract-domain bin/
12+
docker cp $(CID):/go/bin/extract-types bin/
13+
docker cp $(CID):/go/bin/extract-version bin/
14+
docker cp $(CID):/go/bin/get-app-config bin/
15+
docker cp $(CID):/go/bin/get-app-values bin/
16+
docker cp $(CID):/go/bin/publish-release-controller bin/
17+
docker cp $(CID):/go/bin/yaml2json-procfile bin/
18+
docker build -t $(IMAGE) .
19+
-docker kill $(CID)
920

1021
clean: check-docker check-registry
1122
rm -f deisctl

builder/image/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.3
2+
3+
ADD . /go/src/github.com/deis/deis/builder
4+
5+
WORKDIR /go/src/github.com/deis/deis/builder
6+
7+
RUN go get github.com/franela/goreq
8+
RUN go get github.com/moraes/config
9+
10+
RUN CGO_ENABLED=0 go build -a -ldflags '-s' extract-domain.go
11+
RUN CGO_ENABLED=0 go build -a -ldflags '-s' extract-types.go
12+
RUN CGO_ENABLED=0 go build -a -ldflags '-s' extract-version.go
13+
RUN CGO_ENABLED=0 go build -a -ldflags '-s' get-app-config.go
14+
RUN CGO_ENABLED=0 go build -a -ldflags '-s' get-app-values.go
15+
RUN CGO_ENABLED=0 go build -a -ldflags '-s' yaml2json-procfile.go
16+
RUN CGO_ENABLED=0 go build -a -ldflags '-s' publish-release-controller.go
17+
18+
RUN mkdir -p /go/bin && cp * /go/bin

builder/image/extract-domain.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"os"
8+
)
9+
10+
func main() {
11+
fi, _ := os.Stdin.Stat()
12+
if fi.Mode()&os.ModeNamedPipe == 0 {
13+
fmt.Println("this app only works using the stdout of another process")
14+
os.Exit(1)
15+
}
16+
17+
bytes, err := ioutil.ReadAll(os.Stdin)
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
var release map[string]interface{}
23+
err = json.Unmarshal(bytes, &release)
24+
25+
if err != nil {
26+
fmt.Println("invalid application json configuration")
27+
os.Exit(1)
28+
}
29+
30+
if release["domains"] == nil {
31+
fmt.Println("invalid application domain")
32+
os.Exit(1)
33+
}
34+
35+
values := release["domains"].([]interface{})
36+
37+
if len(values) < 1 {
38+
fmt.Println("invalid application domain")
39+
os.Exit(1)
40+
}
41+
42+
fmt.Println(values[0])
43+
}

builder/image/extract-types.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
8+
"github.com/moraes/config"
9+
)
10+
11+
func main() {
12+
fi, _ := os.Stdin.Stat()
13+
if fi.Mode()&os.ModeNamedPipe == 0 {
14+
fmt.Println("this app only works using the stdout of another process")
15+
os.Exit(1)
16+
}
17+
18+
bytes, err := ioutil.ReadAll(os.Stdin)
19+
// this should not happen but just in case return an empty type
20+
if err != nil {
21+
fmt.Println("{}")
22+
os.Exit(0)
23+
}
24+
25+
cfg, err := config.ParseYaml(string(bytes))
26+
27+
if err != nil {
28+
fmt.Println("the procfile does not contains a valid yaml structure")
29+
os.Exit(1)
30+
}
31+
32+
defaultType, err := cfg.Get("default_process_types")
33+
34+
fmt.Println(defaultType)
35+
}

builder/image/extract-version.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"os"
8+
)
9+
10+
func main() {
11+
fi, _ := os.Stdin.Stat()
12+
if fi.Mode()&os.ModeNamedPipe == 0 {
13+
fmt.Println("this app only works using the stdout of another process")
14+
os.Exit(1)
15+
}
16+
17+
bytes, err := ioutil.ReadAll(os.Stdin)
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
var input map[string]interface{}
23+
err = json.Unmarshal(bytes, &input)
24+
25+
if err != nil {
26+
fmt.Println("invalid application json configuration")
27+
os.Exit(1)
28+
}
29+
30+
if input["release"] == nil {
31+
fmt.Println("invalid application version")
32+
os.Exit(1)
33+
}
34+
35+
release := input["release"].(map[string]interface{})
36+
fmt.Println(release["version"])
37+
}

builder/image/get-app-config.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"flag"
6+
"fmt"
7+
"os"
8+
"time"
9+
10+
"github.com/franela/goreq"
11+
)
12+
13+
// Config repo from which extract the configuration and user to use
14+
type Config struct {
15+
ReceiveUser string `json:"receive_user"`
16+
ReceiveRepo string `json:"receive_repo"`
17+
}
18+
19+
// Release application configuration
20+
type Release struct {
21+
Owner string `json:"owner"`
22+
App string `json:"app"`
23+
Values map[string]interface{} `json:"values"`
24+
Memory map[string]interface{} `json:"memory"`
25+
CPU map[string]interface{} `json:"cpu"`
26+
Tags map[string]interface{} `json:"tags"`
27+
UUID string `json:"uuid"`
28+
Created time.Time `json:"created"`
29+
Updated time.Time `json:"updated"`
30+
}
31+
32+
const (
33+
contentType string = "application/json"
34+
userAgent string = "deis-builder"
35+
)
36+
37+
func init() {
38+
flag.Usage = func() {
39+
fmt.Fprintf(os.Stderr, "Usage: [options]\n\n")
40+
flag.PrintDefaults()
41+
}
42+
}
43+
44+
func main() {
45+
url := flag.String("url", "", "Controller hook URL")
46+
builderKey := flag.String("key", "", "Builder Key")
47+
user := flag.String("user", "", "Controller username")
48+
app := flag.String("app", "", "Controller application name")
49+
50+
flag.Parse()
51+
52+
if flag.NFlag() < 4 {
53+
flag.Usage()
54+
os.Exit(1)
55+
}
56+
57+
if *url == "" {
58+
fmt.Println("invalid url")
59+
os.Exit(64)
60+
}
61+
62+
if *builderKey == "" {
63+
fmt.Println("invalid builder key")
64+
os.Exit(64)
65+
}
66+
67+
if *user == "" {
68+
fmt.Println("invalid user")
69+
os.Exit(64)
70+
}
71+
72+
if *app == "" {
73+
fmt.Println("invalid app")
74+
os.Exit(64)
75+
}
76+
77+
data := Config{ReceiveUser: *user, ReceiveRepo: *app}
78+
79+
req := goreq.Request{
80+
Method: "POST",
81+
Uri: *url,
82+
Body: data,
83+
ContentType: contentType,
84+
Accept: contentType,
85+
UserAgent: userAgent,
86+
}
87+
88+
req.AddHeader("X-Deis-Builder-Auth", *builderKey)
89+
90+
res, err := req.Do()
91+
92+
if res.StatusCode == 404 {
93+
fmt.Println("check the deis-controller. Is not running")
94+
os.Exit(2)
95+
}
96+
97+
if err != nil || res.StatusCode != 200 {
98+
fmt.Println("failed retrieving config from controller")
99+
body, _ := res.Body.ToString()
100+
fmt.Println(body)
101+
os.Exit(1)
102+
}
103+
104+
var release Release
105+
res.Body.FromJsonTo(&release)
106+
toSring, _ := json.Marshal(release)
107+
fmt.Println(string(toSring))
108+
}

builder/image/get-app-values.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"os"
8+
)
9+
10+
func main() {
11+
fi, _ := os.Stdin.Stat()
12+
if fi.Mode()&os.ModeNamedPipe == 0 {
13+
fmt.Println("this app only works using the stdout of another process")
14+
os.Exit(1)
15+
}
16+
17+
bytes, err := ioutil.ReadAll(os.Stdin)
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
var release map[string]interface{}
23+
err = json.Unmarshal(bytes, &release)
24+
25+
if err != nil {
26+
fmt.Println("invalid application json configuration")
27+
os.Exit(1)
28+
}
29+
30+
if release["values"] == nil {
31+
fmt.Println()
32+
os.Exit(0)
33+
}
34+
35+
values := release["values"].(map[string]interface{})
36+
37+
for k, v := range values {
38+
fmt.Print(" -e " + k + "=\"" + v.(string) + "\"")
39+
}
40+
}

0 commit comments

Comments
 (0)