Skip to content

Commit a25d03c

Browse files
committed
Merge pull request #279 from luxas/cross_compile
Docker development container
2 parents ed85720 + 2a21d1d commit a25d03c

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git

Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2015 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This is a Dockerfile for running and building Kubernetes dashboard
16+
# It installs all deps in the container and adds the dashboard source
17+
# This way it abstracts all required build tools away and lets the user run gulp tasks on the code with only docker installed
18+
19+
# golang is based on debian:jessie
20+
FROM golang:1.5.3
21+
22+
# Install python, java and nodejs. go is already installed
23+
# A small tweak, apt-get update is already run by the nodejs setup script, so there's no need to run it again
24+
RUN curl -sL https://deb.nodesource.com/setup_5.x | bash - \
25+
&& apt-get install -y --no-install-recommends \
26+
file \
27+
python \
28+
openjdk-7-jre \
29+
nodejs \
30+
&& rm -rf /var/lib/apt/lists/* \
31+
&& apt-get clean
32+
33+
# Download a statically linked docker client, so the container is able to build images on the host
34+
RUN curl -sSL https://get.docker.com/builds/Linux/x86_64/docker-1.9.1 > /usr/bin/docker && \
35+
chmod +x /usr/bin/docker
36+
37+
# Current directory is always /dashboard
38+
WORKDIR /dashboard
39+
40+
# Make an normal user, required for npm and bower, they are user programs and should not be called as root
41+
RUN useradd normaluser -m -s /bin/bash && \
42+
chown -R normaluser /dashboard
43+
# Our normal user should have access to /dashboard
44+
45+
# Switch user to normaluser
46+
USER normaluser
47+
48+
# Copy over package.json bower.json and postinstall.sh.
49+
# Why? Because of docker caching, npm install will only run again if one of these have changed
50+
COPY package.json bower.json ./
51+
COPY build/postinstall.sh build/
52+
53+
# Install all npm deps, bower deps and godep. This will take a while.
54+
RUN npm install
55+
56+
# Copy over the rest of the source
57+
COPY ./ ./
58+
59+
# Switch back to the root user when where going to communicate with docker
60+
USER root

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,32 @@ Kubernetes Dashboard project consists of two main components. They are called he
1616
## Preparation
1717

1818
Make sure the following software is installed and added to the `$PATH` variable:
19-
* Docker (1.3+)
19+
* docker (1.3+)
2020
* go (1.5+)
2121
* nodejs (4.2.2+)
2222
* npm (1.3+)
2323
* java (7+)
2424
* gulp (3.9+)
25+
* bash
2526

2627
Clone the repository and install the dependencies:
2728
```
2829
$ npm install
2930
```
3031

32+
## Run dashboard inside a container
33+
34+
It's possible to run `gulp` and all the dependencies inside a development container. To do this, just replace `gulp [some arg]` commands with `build/run-gulp-in-docker.sh [some arg]`. If you do this, the only dependency is `docker`, and required commands such as `npm install` will be run automatically.
35+
3136
## Run a Kubernetes Cluster
3237

33-
For development it is recommended to run a local Kubernetes cluster. For your convenience, a task is provided that checks out the latest stable version, and runs it inside a Docker container. Open a separate tab in your terminal and run the following command:
38+
For development it is recommended to run a local Kubernetes cluster. For your convenience, a task is provided that runs a small Kubernetes cluster inside Docker containers. Run the following command:
3439

3540
```
3641
$ gulp local-up-cluster
3742
```
3843

39-
This will build and start a lightweight local cluster, consisting of a master and a single node. All processes run locally, in Docker container. The local cluster should behave like a real cluster, however, plugins like heapster are not installed. To shut it down, type the following command that kills all running Docker containers:
44+
This will start a lightweight local cluster. All processes run locally, in Docker containers. The local cluster should behave like a real cluster, but it has some shortcomings. See issues related to https://github.com/kubernetes/kubernetes/tree/master/docs/getting-started-guides/docker.md for more details. To shut it down, you can type the following command that kills all running Docker containers:
4045

4146
```
4247
$ docker kill $(docker ps -aq)
@@ -91,11 +96,9 @@ Open a browser and access the UI under `localhost:9090.` The following processes
9196

9297
Dashboard backend (9090) ---> Kubernetes API server (8080)
9398

94-
95-
9699
In order to package everything into a ready-to-run Docker image, use the following task:
97100
```
98-
$ gulp docker-image
101+
$ gulp docker-image:canary
99102
```
100103
You might notice that the Docker image is very small and requires only a few MB. Only Dashboard assets are added to a scratch image. This is possible, because the `dashboard` binary has no external dependencies. Awesome!
101104

build/run-gulp-in-docker.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Copyright 2015 Google Inc. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# This is a script that runs gulp in a docker container,
17+
# for machines that doesn't have nodejs, go and java installed.
18+
19+
DOCKER_RUN_OPTS=${DOCKER_RUN_OPTS:-}
20+
DASHBOARD_IMAGE_NAME="kubernetes-dashboard-build-image"
21+
DEFAULT_COMMAND=${DEFAULT_COMMAND:-"node_modules/.bin/gulp"}
22+
23+
# Always test if the image is up-to-date. If nothing has changed since last build, it'll just use the already-built image
24+
docker build -t ${DASHBOARD_IMAGE_NAME} .
25+
26+
# Run gulp in the container in interactive mode and expose necessary ports automatically
27+
docker run \
28+
-it \
29+
--rm \
30+
--net=host \
31+
-v /var/run/docker.sock:/var/run/docker.sock \
32+
${DOCKER_RUN_OPTS} \
33+
${DASHBOARD_IMAGE_NAME} \
34+
${DEFAULT_COMMAND} $@

0 commit comments

Comments
 (0)