Skip to content

Commit c721e19

Browse files
author
smothiki
committed
feat(builder) : working version of decoupled builder
1 parent a62527e commit c721e19

55 files changed

Lines changed: 225 additions & 255 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,37 @@
22
# Some uses for short name:
33
# - Docker image name
44
# - Kubernetes service, rc, pod, secret, volume names
5-
SHORT_NAME := example
5+
SHORT_NAME := builder
66

77
# Enable vendor/ directory support.
88
export GO15VENDOREXPERIMENT=1
99

1010
# SemVer with build information is defined in the SemVer 2 spec, but Docker
1111
# doesn't allow +, so we use -.
12-
VERSION := 0.0.1-$(shell date "+%Y%m%d%H%M%S")
12+
# VERSION := 0.0.1-$(shell date "+%Y%m%d%H%M%S")
1313

14+
VERSION := 2.0.0
15+
BINARY_DEST_DIR := rootfs/usr/bin
1416
# Common flags passed into Go's linker.
1517
LDFLAGS := "-s -X main.version=${VERSION}"
16-
18+
BINARIES := extract-domain extract-types extract-version generate-buildhook get-app-config get-app-values publish-release-controller yaml2json-procfile
19+
STANDALONE := extract-types generate-buildhook yaml2json-procfile
1720
# Docker Root FS
1821
BINDIR := ./rootfs
1922

2023
# Legacy support for DEV_REGISTRY, plus new support for DEIS_REGISTRY.
21-
DEV_REGISTRY ?= $(eval docker-machine ip deis):5000
24+
DEV_REGISTRY ?= $$DEV_REGISTRY
2225
DEIS_REGISTY ?= ${DEV_REGISTRY}
2326

2427
# Kubernetes-specific information for RC, Service, and Image.
25-
RC := manifests/deis-${SHORT_NAME}-rc.yaml
26-
SVC := manifests/deis-${SHORT_NAME}-service.yaml
27-
IMAGE := ${DEIS_REGISTRY}/deis/${SHORT_NAME}:${VERSION}
28+
RCBP := manifests/deis-bp${SHORT_NAME}-rc.yaml
29+
SVCBP := manifests/deis-bp${SHORT_NAME}-service.yaml
30+
# IMAGEBP := ${DEV_REGISTRY}/deis/bp${SHORT_NAME}:${VERSION}
31+
IMAGEBP := deis/bp${SHORT_NAME}:${VERSION}
32+
33+
RCDF := manifests/deis-df${SHORT_NAME}-rc.yaml
34+
SVCDF := manifests/deis-df${SHORT_NAME}-service.yaml
35+
IMAGEDF := ${DEV_REGISTRY}/deis/df${SHORT_NAME}:${VERSION}
2836

2937
all:
3038
@echo "Use a Makefile to control top-level building of the project."
@@ -33,34 +41,52 @@ all:
3341
# the Docker environment. Other alternatives are cross-compiling, doing
3442
# the build as a `docker build`.
3543
build:
44+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/builder cli/builder.go || exit 1
3645
mkdir -p ${BINDIR}/bin
3746
docker run --rm -v ${PWD}:/app -w /app golang:1.5.1 make docker-compile
3847

39-
build-bpb:
40-
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/builder cli/builder.go || exit 1
41-
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/fetcher fetcher/fetcher.go || exit 1
42-
@$(call check-static-binary,$(BINARY_DEST_DIR)/builder)
48+
docker-build-bpb:
49+
cp -r bpbuilder/etcd pkg/
50+
cp bpbuilder/kubectl rootfs/bin/
51+
cp bpbuilder/entrypoint.sh rootfs/
52+
cp bpbuilder/deis-slugbuilder.yaml rootfs/etc/
53+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/bpbuilder boot.go || exit 1
54+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/fetcher bpbuilder/fetcher/fetcher.go || exit 1
55+
@$(call check-static-binary,$(BINARY_DEST_DIR)/bpbuilder)
4356
@$(call check-static-binary,$(BINARY_DEST_DIR)/fetcher)
4457
for i in $(BINARIES); do \
45-
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/$$i src/$$i.go || exit 1; \
58+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/$$i pkg/src/$$i.go || exit 1; \
4659
done
60+
@echo "Past go compiling"
4761
@for i in $(BINARIES); do \
4862
$(call check-static-binary,$(BINARY_DEST_DIR)/$$i); \
4963
done
50-
docker build -t $(IMAGE) rootfs
64+
docker build -t $(IMAGEBP) rootfs
65+
perl -pi -e "s|image: [a-z0-9.:]+\/deis\/bp${SHORT_NAME}:[0-9a-z-.]+|image: ${IMAGEBP}|g" ${RCBP}
66+
rm -rf pkg/etcd
67+
rm rootfs/entrypoint.sh
5168
# For cases where build is run inside of a container.
52-
docker-compile:
53-
go build -o ${BINDIR}/bin/boot -a -installsuffix cgo -ldflags ${LDFLAGS} boot.go
5469

55-
# For cases where we're building from local
56-
# We also alter the RC file to set the image name.
57-
docker-build:
58-
docker build --rm -t ${IMAGE} rootfs
59-
perl -pi -e "s|[a-z0-9.:]+\/deis\/${SHORT_NAME}:[0-9a-z-.]+|${IMAGE}|g" ${RC}
70+
docker-build-dfb:
71+
cp -r dfbuilder/etcd pkg/
72+
cp bpbuilder/entrypoint.sh rootfs/
73+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/dfbuilder boot.go || exit 1
74+
@$(call check-static-binary,$(BINARY_DEST_DIR)/dfbuilder)
75+
for i in $(BINARIES); do \
76+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/$$i pkg/src/$$i.go || exit 1; \
77+
done
78+
@for i in $(BINARIES); do \
79+
$(call check-static-binary,$(BINARY_DEST_DIR)/$$i); \
80+
done
81+
docker build -t $(IMAGEDF) rootfs
82+
perl -pi -e "s|image: [a-z0-9.:]+\/deis\/df${SHORT_NAME}:[0-9a-z-.]+|image: ${IMAGEDF}|g" ${RCDF}
83+
rm -rf pkg/etcd
84+
rm rootfs/entrypoint.sh
85+
6086

6187
# Push to a registry that Kubernetes can access.
62-
docker-push:
63-
docker push ${IMAGE}
88+
docker-push-bp:
89+
docker push ${IMAGEBP}
6490

6591
# Deploy is a Kubernetes-oriented target
6692
deploy: kube-service kube-rc
@@ -78,3 +104,12 @@ kube-clean:
78104
kubectl delete rc deis-example
79105

80106
.PHONY: all build docker-compile kube-up kube-down deploy
107+
108+
define check-static-binary
109+
if file $(1) | egrep -q "(statically linked|Mach-O)"; then \
110+
echo ""; \
111+
else \
112+
echo "The binary file $(1) is not statically linked. Build canceled"; \
113+
exit 1; \
114+
fi
115+
endef

_docs/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# Project Docs
1+
# Deis builder
22

3-
Documentation for the project should be stored in the `_docs` directory.
4-
Since the directory is protected from Go, undecorated code samples can
5-
also be dropped inside of this directory.
6-
7-
We need to decide on whether we'll continue using RST or switch to
8-
Markdown.
3+
Deis builder is decoupled into two builder components.
4+
deis buildpack builder need deis/slugrunner and deis/slugbuilder on every host
5+
deis docker file builder needs deis registry running.
96

107
I believe we are leaning toward MkDocs: http://www.mkdocs.org/

api/cli/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

api/cli/builder.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

boot.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"os"
5+
"runtime"
46

5-
const usage = `
6-
All services should provide a top-level Go program named "boot.go", compiled
7-
to "boot". This should go in rootfs/bin/boot, and should be the entry point
8-
for all Deis components.
9-
10-
An exception to this is components that may be started without a boot, or which
11-
may be started with a simple (<20 line) shell script.
12-
`
7+
"github.com/deis/builder/pkg"
8+
)
139

1410
func main() {
15-
fmt.Println(usage)
11+
runtime.GOMAXPROCS(runtime.NumCPU())
12+
os.Exit(pkg.Run("boot"))
1613
}

bpbuilder/Makefile

Lines changed: 0 additions & 83 deletions
This file was deleted.

bpbuilder/builder

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,18 @@ TMP_DIR=$(mktemp -d -p $BUILD_DIR)
6464
cd $REPO_DIR
6565
# use Procfile if provided, otherwise try default process types from ./release
6666

67-
6867
git archive --format=tar.gz ${GIT_SHA} > ${APP_NAME}.tar.gz
6968
TAR_URL=http://${HOST}:3000/git/home/${SLUG_NAME}/tar
7069
PUSH_URL=http://${HOST}:3000/git/home/${SLUG_NAME}/push
70+
if [ "$nosecret" == true ]; then
71+
head -n 21 /etc/slugbuilder.yaml > /etc/tmp.yaml
72+
mv /etc/tmp.yaml /etc/slugbuilder.yaml
73+
fi
74+
sed -i -- 's/puturl/${PUSH_URL}/g' /etc/deis-slugbuilder.yaml
75+
sed -i -- 's/tar-url/${TAR_URL}/g' /etc/deis-slugbuilder.yaml
76+
77+
kubectl create -f /etc/deis-slugbuilder.yaml
7178

72-
docker -H ${HOST}:2375 run -e TAR_URL=${TAR_URL} smothiki/slugbuilder ${PUSH_URL}
73-
74-
# pull config from controller to be used during build
75-
# if [ -f Procfile ]; then
76-
# echo "here1"
77-
# PROCFILE=$(cat Procfile | yaml2json-procfile)
78-
# elif [ -f ${APP_NAME}.tgz ]; then
79-
# echo "here2"
80-
# # Sometimes, the buildpack will generate a Procfile instead of populating /bin/release
81-
# # /bin/release was unofficially deprecated for declaring default process types
82-
# if tar -xzf ${APP_NAME}.tar.gz ./Procfile &> /dev/null;
83-
# then
84-
# PROCFILE="$(tar --to-stdout -xzf ${APP_NAME}.tar.gz ./Procfile | yaml2json-procfile)"
85-
# else
86-
# PROCFILE=$(tar --to-stdout -xzf ${APP_NAME}.tar.gz ./.release | extract-types)
87-
# fi
88-
# else
89-
# echo "here3"
90-
# PROCFILE={"web":"example-go"}
91-
# fi
9279
PROCFILE='{"web":"example-go"}'
9380
URL="{{ getv "/deis/controller/protocol" }}://{{ getv "/deis/controller/host" }}:{{ getv "/deis/controller/port" }}/v1/hooks/config"
9481
RESPONSE=$(get-app-config -url="$URL" -key="{{ getv "/deis/controller/builderKey" }}" -user=$USER -app=$APP_NAME)

bpbuilder/deis-slugbuilder.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# A debugging utility for testing Minio from within k8s.
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: deis-slugbuilder
6+
labels:
7+
heritage: deis
8+
version: 2015-sept
9+
spec:
10+
restartPolicy: Never
11+
containers:
12+
- name: deis-slugbuilder
13+
imagePullPolicy: Always
14+
image: smothiki/slugbuilder:5.3
15+
env:
16+
- name: DEBUG
17+
value: "1"
18+
- name: TAR_URL
19+
value: tar-url
20+
- name : put-url
21+
value: puturl
22+
volumeMounts:
23+
- name: object-store
24+
mountPath: /var/run/secrets/object/store
25+
readOnly: true
26+
volumes:
27+
- name: object-store
28+
secret:
29+
secretName: object-store

bpbuilder/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
set -e
33

4-
builder &
4+
bpbuilder &
55
exec fetcher

0 commit comments

Comments
 (0)