Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 46 additions & 126 deletions docs/builds.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions examples/builds/docker-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "Build",
"apiVersion": "v1beta1",
"input": {
"type": "docker",
"sourceURI": "https://raw.githubusercontent.com/openshift/origin/master/examples/builds/images/docker-build/Dockerfile",
"imageTag": "openshift/docker-build-example"
}
}
2 changes: 2 additions & 0 deletions examples/builds/images/docker-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM busybox:latest
CMD echo "success"
10 changes: 10 additions & 0 deletions examples/builds/sti-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"kind": "Build",
"apiVersion": "v1beta1",
"input": {
"type": "sti",
"sourceURI": "https://raw.githubusercontent.com/openshift/origin/master/examples/builds/images/docker-build/Dockerfile",
"imageTag": "openshift/sti-build-example",
"builderImage": "ncdc/sti-busybox"
}
}
1 change: 0 additions & 1 deletion hack/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ cd "${OS_REPO_ROOT}"
version=$(gitcommit)
kube_version=$(go run ${hackdir}/version.go ${hackdir}/../Godeps/Godeps.json github.com/GoogleCloudPlatform/kubernetes/pkg/api)

docker build -t openshift/kubernetes-fedora-dind images/builder/docker/kubernetes-fedora-dind
docker build -t openshift/docker-builder images/builder/docker/docker-builder
docker build -t openshift/sti-builder images/builder/docker/sti-builder
docker build -t openshift/hello-openshift examples/hello-openshift
4 changes: 2 additions & 2 deletions images/builder/docker/docker-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openshift/kubernetes-fedora-dind
RUN yum -y install git
FROM fedora:20
RUN yum -y install docker-io git
ADD ./build.sh /tmp/build.sh
CMD ["/tmp/build.sh"]
33 changes: 4 additions & 29 deletions images/builder/docker/docker-builder/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,11 @@
set -uo pipefail
IFS=$'\n\t'

NEED_DIND=false
if [ ! -e /var/run/docker.sock ]; then
NEED_DIND=true
fi

if $NEED_DIND; then
DOCKER_READY=false
dind &

# wait for docker to be available
ATTEMPTS=0
while [ $ATTEMPTS -lt 10 ]; do
docker version &> /dev/null
if [ $? -eq 0 ]; then
DOCKER_READY=true
break
fi
DOCKER_SOCKET=/var/run/docker.sock

let ATTEMPTS=ATTEMPTS+1
sleep 1
done

if ! $DOCKER_READY; then
echo 'Docker-in-Docker daemon not accessible'
exit 1
fi
if [ ! -e $DOCKER_SOCKET ]; then
echo "Docker socket missing at $DOCKER_SOCKET"
exit 1
fi

TAG=$BUILD_TAG
Expand All @@ -40,7 +19,3 @@ docker build --rm -t $TAG $DOCKER_CONTEXT_URL
if [ -n "$DOCKER_REGISTRY" ]; then
docker push $TAG
fi

if $NEED_DIND; then
kill -15 $(cat /var/run/docker.pid)
fi
9 changes: 0 additions & 9 deletions images/builder/docker/kubernetes-fedora-dind/Dockerfile

This file was deleted.

109 changes: 0 additions & 109 deletions images/builder/docker/kubernetes-fedora-dind/dind

This file was deleted.

4 changes: 2 additions & 2 deletions images/builder/docker/sti-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM openshift/kubernetes-fedora-dind
RUN yum -y install golang golang-src golang-pkg-bin-linux-amd64 golang-pkg-linux-amd64 git && \
FROM fedora:20
RUN yum -y install docker-io golang golang-src golang-pkg-bin-linux-amd64 golang-pkg-linux-amd64 git && \
yum clean all

RUN mkdir -p /tmp/go/src/github.com/openshift
Expand Down
35 changes: 4 additions & 31 deletions images/builder/docker/sti-builder/build.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
#!/bin/bash -ex

NEED_DIND=false
if [ ! -e /var/run/docker.sock ]; then
NEED_DIND=true
fi

if [ $NEED_DIND == "true" ]; then
DOCKER_READY=false
dind &

# wait for docker to be available
ATTEMPTS=0
while [ $ATTEMPTS -lt 10 ]; do
set +e
docker version &> /dev/null
if [ $? -eq 0 ]; then
DOCKER_READY=true
break
fi
set -e
DOCKER_SOCKET=/var/run/docker.sock

let ATTEMPTS=ATTEMPTS+1
sleep 1
done

if [ $DOCKER_READY != "true" ]; then
echo 'Docker-in-Docker daemon not accessible'
exit 1
fi
if [ ! -e $DOCKER_SOCKET ]; then
echo "Docker socket missing at $DOCKER_SOCKET"
exit 1
fi

TAG=$BUILD_TAG
Expand All @@ -46,7 +23,3 @@ TMPDIR=$BUILD_TEMP_DIR sti build $SOURCE_URI $BUILDER_IMAGE $TAG $REF_OPTION
if [ -n "$DOCKER_REGISTRY" ]; then
docker push $TAG
fi

if [ $NEED_DIND == "true" ]; then
kill -15 $(cat /var/run/docker.pid)
fi
31 changes: 28 additions & 3 deletions pkg/build/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
// Package build contains a build system defined on top of Kubernetes.
// It consists of two resource types: Build and BuildConfig, along with
// associated storage, as well as a controller that manages states of existing builds
/*
Package build contains the OpenShift build system.

It defines a Build resource type, along with associated storage and a controller
that executes builds and manages states of existing builds.

For newly created builds, the BuildController will assign a pod ID to the build
and set the build’s state to pending. This way, the assignment of the pod ID and
pending status is idempotent and won’t result in two BuildControllers
potentially scheduling two different pods for the same build.

For pending builds, the BuildController will attempt to create a pod to perform
the build. If the creation succeeds, it sets the build’s status to pending. If
the pod already exists, that means another BuildController already processed
this build in a pending state, resulting in a no-op. Any other pod creation
error would result in the build’s status being set to failed.

For running builds, the BuildController will monitor the status of the pod. If
the pod is still running and the build has exceeded its allotted execution time,
the BuildController will consider it failed. If the pod is terminated, the
BuildController will examine the exit codes for each of the pod’s containers. If
any exit code is non-zero, the build is marked as failed. Otherwise, it is
considered complete (successful).

Once the build has reached a terminal state (complete or failed), the
BuildController will delete the pod associated with the build. In the future, it
will be desirable to keep a record of the pod’s containers’ logs.
*/
package build
10 changes: 3 additions & 7 deletions pkg/build/strategy/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import (
)

// DockerBuildStrategy creates Docker build using a docker builder image
// useHostDocker determines whether the minion Docker daemon is used for the build
// or a separate Docker daemon is run inside the container
type DockerBuildStrategy struct {
dockerBuilderImage string
useHostDocker bool
}

// NewDockerBuildStrategy creates a new DockerBuildStrategy
func NewDockerBuildStrategy(dockerBuilderImage string, useHostDocker bool) *DockerBuildStrategy {
return &DockerBuildStrategy{dockerBuilderImage, useHostDocker}
func NewDockerBuildStrategy(dockerBuilderImage string) *DockerBuildStrategy {
return &DockerBuildStrategy{dockerBuilderImage}
}

// CreateBuildPod creates the pod to be used for the Docker build
Expand All @@ -38,13 +35,12 @@ func (bs *DockerBuildStrategy) CreateBuildPod(build *buildapi.Build, dockerRegis
{Name: "DOCKER_CONTEXT_URL", Value: build.Input.SourceURI},
{Name: "DOCKER_REGISTRY", Value: dockerRegistry},
},
Privileged: true,
},
},
},
},
}

setupDockerSocket(bs.useHostDocker, pod)
setupDockerSocket(pod)
return pod, nil
}
5 changes: 1 addition & 4 deletions pkg/build/strategy/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestDockerCreateBuildPod(t *testing.T) {
const dockerRegistry = "docker-test-registry"
strategy := NewDockerBuildStrategy("docker-test-image", false)
strategy := NewDockerBuildStrategy("docker-test-image")
expected := mockDockerBuild()
actual, _ := strategy.CreateBuildPod(expected, dockerRegistry)

Expand All @@ -30,9 +30,6 @@ func TestDockerCreateBuildPod(t *testing.T) {
if container.RestartPolicy != "runOnce" {
t.Errorf("Expected runOnce, but got %s!", container.RestartPolicy)
}
if !container.Privileged {
t.Errorf("Expected Privileged")
}
if e := container.Env[0]; e.Name != "BUILD_TAG" && e.Value != expected.Input.ImageTag {
t.Errorf("Expected %s, got %s:%s!", expected.Input.ImageTag, e.Name, e.Value)
}
Expand Down
Loading