Browse code

Allow specifing docker registry credentials

Maciej Szulik authored on 2014/09/24 18:31:23
Showing 6 changed files
... ...
@@ -14,7 +14,7 @@ Getting Started
14 14
 ---------------
15 15
 You can develop [locally on your host](CONTRIBUTING.adoc#develop-locally-on-your-host) or with a [virtual machine](CONTRIBUTING.adoc#develop-on-virtual-machine-using-vagrant), or if you want to just try out OpenShift [download the latest Linux 64bit pre-built binary](CONTRIBUTING.adoc#download-from-github).
16 16
 
17
-First, **get up and running with the** [**Contributing Guide**](CONTRIBUTING.adoc). 
17
+First, **get up and running with the** [**Contributing Guide**](CONTRIBUTING.adoc).
18 18
 
19 19
 Once setup, you can:
20 20
 
... ...
@@ -49,6 +49,26 @@ This example is simply running the ['openshift/hello-openshift' Docker image](ht
49 49
 
50 50
 Remember, you can pass a URL to `-c` when using the `kube` command, so you can [download the latest release](CONTRIBUTING.adoc#download-from-github) and pass a URL to the content on GitHub so you don't even need clone the source.
51 51
 
52
+### Docker registry
53
+
54
+OpenShift builds allow pushing built images into docker registry. Currently we only support one registry per OpenShift installation.
55
+Still you can use either private [docker registry](https://github.com/docker/docker-registry) or the [official docker hub](https://hub.docker.com/).
56
+
57
+**Private docker registry**
58
+
59
+To setup private docker registry you can either follow the steps [here](https://github.com/docker/docker-registry#quick-start)
60
+or use [simple-ruby-app example](https://github.com/openshift/origin/blob/master/examples/simple-ruby-app)
61
+to host one inside OpenShift. Afterwards you need to pass `DOCKER_REGISTRY` environment variable to `openshift start`
62
+command, specifying the address of your registry, e.g. `DOCKER_REGISTRY=localhost:5000`.
63
+
64
+**Docker Hub**
65
+
66
+To access the [official docker hub](https://hub.docker.com/) you need to login using `docker login` command.
67
+In result a file named `.dockercfg` is created in your home directory. It contains credentials used
68
+when accessing the hub. Now when running OpenShift, the binary will pick up these credentials and
69
+use them inside build pods to push your result images to the hub.
70
+
71
+NOTE: Make sure to tag your build appropriately to match hub requirements, meaning `username/imagename`.
52 72
 
53 73
 Design Documents
54 74
 ----------------
... ...
@@ -16,6 +16,6 @@ fi
16 16
 
17 17
 docker build --rm -t $TAG $DOCKER_CONTEXT_URL
18 18
 
19
-if [ -n "$DOCKER_REGISTRY" ]; then
19
+if [ -n "$DOCKER_REGISTRY" ] || [ -s "/.dockercfg" ]; then
20 20
   docker push $TAG
21 21
 fi
... ...
@@ -17,9 +17,9 @@ if [ -n "$SOURCE_REF" ]; then
17 17
   REF_OPTION="--ref $SOURCE_REF"
18 18
 fi
19 19
 
20
-BUILD_TEMP_DIR=${TEMP_DIR-$TMPDIR} 
20
+BUILD_TEMP_DIR=${TEMP_DIR-$TMPDIR}
21 21
 TMPDIR=$BUILD_TEMP_DIR sti build $SOURCE_URI $BUILDER_IMAGE $TAG $REF_OPTION
22 22
 
23
-if [ -n "$DOCKER_REGISTRY" ]; then
23
+if [ -n "$DOCKER_REGISTRY" ] || [ -s "/.dockercfg" ]; then
24 24
   docker push $TAG
25 25
 fi
... ...
@@ -44,5 +44,6 @@ func (bs *DockerBuildStrategy) CreateBuildPod(build *buildapi.Build, dockerRegis
44 44
 	}
45 45
 
46 46
 	setupDockerSocket(pod)
47
+	setupDockerConfig(pod)
47 48
 	return pod, nil
48 49
 }
... ...
@@ -66,6 +66,7 @@ func (bs *STIBuildStrategy) CreateBuildPod(build *buildapi.Build, dockerRegistry
66 66
 	}
67 67
 
68 68
 	setupDockerSocket(pod)
69
+	setupDockerConfig(pod)
69 70
 	return pod, nil
70 71
 }
71 72
 
... ...
@@ -1,6 +1,9 @@
1 1
 package strategy
2 2
 
3 3
 import (
4
+	"os"
5
+	"path"
6
+
4 7
 	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
5 8
 )
6 9
 
... ...
@@ -26,3 +29,27 @@ func setupDockerSocket(podSpec *api.Pod) {
26 26
 		append(podSpec.DesiredState.Manifest.Containers[0].VolumeMounts,
27 27
 			dockerSocketVolumeMount)
28 28
 }
29
+
30
+// setupDockerConfig configures the path to .dockercfg which contains registry credentials
31
+func setupDockerConfig(podSpec *api.Pod) {
32
+	dockerConfigVolume := api.Volume{
33
+		Name: "docker-cfg",
34
+		Source: &api.VolumeSource{
35
+			HostDirectory: &api.HostDirectory{
36
+				Path: path.Join(os.Getenv("HOME"), ".dockercfg"),
37
+			},
38
+		},
39
+	}
40
+
41
+	dockerConfigVolumeMount := api.VolumeMount{
42
+		Name:      "docker-cfg",
43
+		ReadOnly:  true,
44
+		MountPath: "/.dockercfg",
45
+	}
46
+
47
+	podSpec.DesiredState.Manifest.Volumes = append(podSpec.DesiredState.Manifest.Volumes,
48
+		dockerConfigVolume)
49
+	podSpec.DesiredState.Manifest.Containers[0].VolumeMounts =
50
+		append(podSpec.DesiredState.Manifest.Containers[0].VolumeMounts,
51
+			dockerConfigVolumeMount)
52
+}