Skip to content

Commit 7a4fada

Browse files
Initial commit
0 parents  commit 7a4fada

File tree

4,742 files changed

+1597718
-0
lines changed

Some content is hidden

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

4,742 files changed

+1597718
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/image-build-daemon

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
build:
3+
go build ./cmd/image-build-daemon
4+
.PHONY: build
5+
6+
check:
7+
go test ./...
8+
.PHONY: check
9+
10+
deps:
11+
glide update -v --skip-test
12+
.PHONY: deps
13+
14+
fake:
15+
docker run --name daemon-test -d -v /var/run/docker \
16+
-l io.kubernetes.pod.uid=123 \
17+
-l io.kubernetes.pod.namespace=test \
18+
-l io.kubernetes.pod.name=daemon \
19+
-l io.kubernetes.container.name=sleep \
20+
--cgroup-parent system.slice \
21+
centos:7 /bin/bash -c 'exec sleep 10000'
22+
.PHONY: fake

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
image-build-daemon
2+
==================
3+
4+
This project is in early `alpha` and may change significantly in the
5+
future.
6+
7+
The image-build-daemon acts as a Kubernetes-aware Docker build endpoint
8+
that limits what operations clients can perform to a safe subset and
9+
ensures the resources those clients consume are charged back to their
10+
pod. It automatically injects a Docker-API compatible unix domain socket
11+
into any pod that mounts a read-write emptydir to `/var/run/docker/`,
12+
and then accepts the following Docker API calls:
13+
14+
* `build`: Perform Docker builds that are placed into the calling pod's
15+
cgroup
16+
* `tag`: Tag an image that was created by a build with a different name
17+
* `list-images`: List any images built by this pod
18+
* `remove-image`: Remove an image created by this pod
19+
* `push`: Push an image created by this pod
20+
21+
The daemon performs cleanup, quota, and scoping to the calling pod,
22+
ensuring that resources consumed by a build pod are fairly used. The
23+
normal Docker CLI or API client can create operations, although not all
24+
parameters are supported.
25+
26+
The daemon also supports multiple backends with the future goal of
27+
removing the need for a Docker daemon on the host, specified with
28+
`--mode`:
29+
30+
* `passthrough` - Use the host's Docker socket to perform operations
31+
* `imagebuilder` - Use the
32+
[imagebuilder](https://github.com/openshift/imagebuilder) library to
33+
perform more efficient builds
34+
* FUTURE: `buildah` - Avoid using a shared daemon and instead execute
35+
builds under the calling pod's context.
36+
37+
## Trying it out
38+
39+
Clone the source into your GOPATH and build with:
40+
41+
make
42+
43+
To test locally without a running Kubernetes server, start your Docker
44+
daemon and then run:
45+
46+
./image-build-daemon -v=5 --bind-local=/tmp &
47+
48+
To start the daemon running in the background. Then launch a fake
49+
Kubernetes container with
50+
51+
make fake
52+
53+
The container named `daemon-test` will be started, and
54+
`image-build-daemon` will create `/tmp/docker.sock` (due to
55+
`--bind-local` being passed).
56+
57+
To test against the daemon, run
58+
59+
export DOCKER_HOST=unix:///tmp/docker.sock
60+
docker build vendor/github.com/openshift/imagebuilder/dockerclient/testdata/volume/
61+
62+
And you should see a build created.

cmd/image-build-daemon/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"math/rand"
7+
"os"
8+
"time"
9+
10+
"github.com/openshift/image-build-daemon/pkg/cmd"
11+
"github.com/openshift/image-build-daemon/pkg/logs"
12+
)
13+
14+
func main() {
15+
logs.InitLogs()
16+
defer logs.FlushLogs()
17+
18+
rand.Seed(time.Now().UTC().UnixNano())
19+
20+
command := cmd.New("")
21+
command.PersistentFlags().AddGoFlag(flag.Lookup("v"))
22+
if err := command.Execute(); err != nil {
23+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
24+
os.Exit(1)
25+
}
26+
}

contrib/docker-daemon.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
kind: DaemonSet
2+
apiVersion: apps/v1
3+
metadata:
4+
name: build-daemon
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: build-daemon
9+
template:
10+
metadata:
11+
labels:
12+
app: build-daemon
13+
spec:
14+
containers:
15+
- name: docker
16+
image: openshift/origin-custom-docker-builder:latest
17+
imagePullPolicy: IfNotPresent
18+
command:
19+
- /bin/bash
20+
- -c
21+
- |
22+
#!/bin/bash
23+
set -o errexit
24+
rm -rf /usr/libexec/oci/hooks.d/*
25+
exec dockerd-current --iptables=false --storage-driver=overlay2 --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --exec-opt native.cgroupdriver=systemd
26+
securityContext:
27+
runAsUser: 0
28+
privileged: true
29+
volumeMounts:
30+
- mountPath: /run/systemd
31+
name: host-run-systemd
32+
- mountPath: /var/run/dbus
33+
name: host-var-run-dbus
34+
- mountPath: /sys/fs/cgroup
35+
name: host-sys-fs-cgroup
36+
- mountPath: /var/lib/docker
37+
name: storage
38+
volumes:
39+
- name: host-run-systemd
40+
hostPath:
41+
path: /run/systemd
42+
- name: host-var-run-dbus
43+
hostPath:
44+
path: /var/run/dbus
45+
- name: host-sys-fs-cgroup
46+
hostPath:
47+
path: /sys/fs/cgroup
48+
- name: storage
49+
emptyDir: {}

doc.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// package daemon implements a Docker build daemon that can answer requests
2+
// via the Docker engine build, push, commit, and tag API for containerized
3+
// callers to use safely.
4+
//
5+
// Clients request a domain socket be placed into their container at a
6+
// pre-arranged location by creating an appropriate volume mount. A socket
7+
// emulating the Docker engine API for a limited set of operations and
8+
// imposing additional restrictions will respond to that container.
9+
package daemon

glide.lock

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package: github.com/openshift/image-build-daemon
2+
import:
3+
- package: github.com/MakeNowJust/heredoc
4+
- package: github.com/davecgh/go-spew
5+
subpackages:
6+
- spew
7+
- package: github.com/docker/docker
8+
version: b68221c37ee597950364788204546f9c9d0e46a1
9+
subpackages:
10+
- api
11+
- builder/dockerfile/parser
12+
- pkg/archive
13+
- pkg/homedir
14+
- package: github.com/fsouza/go-dockerclient
15+
repo: [email protected]:openshift/go-dockerclient
16+
version: openshift-3.9
17+
- package: github.com/golang/glog
18+
- package: github.com/gorilla/context
19+
- package: github.com/openshift/imagebuilder
20+
version: master
21+
subpackages:
22+
- dockerclient
23+
- package: github.com/spf13/cobra
24+
- package: github.com/spf13/pflag
25+
testImport:
26+
- package: github.com/stretchr/testify
27+
subpackages:
28+
- assert

0 commit comments

Comments
 (0)