Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
Move hack/dockerbuild to docker/build
Browse files Browse the repository at this point in the history
- Make build image more like km/complete images
- Use go docker base image
- Change build image name to mesosphere/kubernetes-mesos-build
- Increase docker-compose timeouts waiting for apiserver
  • Loading branch information
Karl Isenberg committed May 28, 2015
1 parent 13b5e41 commit e866b03
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 59 deletions.
29 changes: 17 additions & 12 deletions docker/bin/install-go.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/usr/bin/env bash

set -e
# Installs go into /usr/local/go/bin
# To enable: export PATH=$PATH:/usr/local/go/bin

GOPATH=${GOPATH:-~/go}
GO_ARCHIVE_URL=${GO_ARCHIVE_URL:-https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz}
GO_ARCHIVE=/tmp/$(basename ${GO_ARCHIVE_URL})
set -ex

echo "Downloading go (${GO_ARCHIVE_URL})..."
mkdir -p $(dirname $GOROOT)
wget -q $GO_ARCHIVE_URL -O $GO_ARCHIVE
echo "Installing go (${GOROOT})..."
tar xf $GO_ARCHIVE -C $(dirname $GOROOT)
GO_VERSION=${GO_VERSION:-1.4.2}

if [ ! -d $TMPDIR ]; then
mkdir -p $TMPDIR
archive_root=go${GO_VERSION}.linux-amd64
archive_url=https://storage.googleapis.com/golang/${archive_root}.tar.gz

cd /usr/local

if [ -d ./go ]; then
echo "Uninstalling Go..."
rm -rf ./go
fi

rm -f $GO_ARCHIVE
echo "Downloading Go..."
wget -nv ${archive_url} -O ${archive_root}.tar.gz

echo "Installing Go..."
tar xf ${archive_root}.tar.gz
29 changes: 29 additions & 0 deletions docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM golang:1.4.2-wheezy
MAINTAINER Mesosphere <support@mesosphere.io>

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
wget \
curl \
g++ \
make \
mercurial \
git \
rsync \
patch \
&& \
apt-get clean

COPY ./docker/bin/* /kubernetes-mesos/bin/
COPY ./docker/build/bin/* /kubernetes-mesos/bin/
ENV PATH /kubernetes-mesos/bin:$PATH

RUN go get github.com/tools/godep

VOLUME /target
CMD [ ]

# optional: if $SNAP is host-volume-mounted into the container at run-time then
# use that as the project source code repo instead of github
ENV SNAP /snapshot
ENTRYPOINT [ "km-build" ]
18 changes: 9 additions & 9 deletions hack/dockerbuild/README.md → docker/build/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Overview

The intent of the dockerbuilder is to leverage Docker as cleanroom build environment for this project.
The intent of kubernetes-mesos-build is to leverage Docker as cleanroom build environment for this project.
Once built the Docker image contains all the libraries, headers, and tooling for compiling the binaries required to run the kubernetes-mesos framework.

## Building the Docker image

The `build` file in this directory will generate a docker image capable of building kubernetes-mesos binaries.
The `build.sh` file in this directory will generate a docker image capable of building kubernetes-mesos binaries.

$ . build
$ ./build.sh

## Building the project

Expand All @@ -21,7 +21,7 @@ This example copies the resulting binaries into the host-mounted volume `/tmp/ta

To build and copy the binaries:

$ docker run --rm -v /tmp/target:/target mesosphere/kubernetes-mesos:build
$ docker run --rm -v /tmp/target:/target mesosphere/kubernetes-mesos-build
...
git clone https://${GOPKG}.git .
Cloning into '.'...
Expand All @@ -43,30 +43,30 @@ To build and copy the binaries:

Alternatively, it can be used to generate binaries from a branch:

$ docker run --rm -v /tmp/target:/target -e GIT_BRANCH=default_port mesosphere/kubernetes-mesos:build
$ docker run --rm -v /tmp/target:/target -e GIT_BRANCH=default_port mesosphere/kubernetes-mesos-build

Want a quick-and-dirty development environment to start hacking?

$ docker run -ti -v /tmp/target:/target mesosphere/kubernetes-mesos:build bash
$ docker run -ti -v /tmp/target:/target mesosphere/kubernetes-mesos-build bash
root@5883c3a460a6$ make bootstrap all

Need to build the project, but from a forked git repo?

$ docker run --rm -v /tmp/target:/target -e GIT_REPO=https://github.com/whoami/kubernetes-mesos \
mesosphere/kubernetes-mesos:build
mesosphere/kubernetes-mesos-build

To hack in your currently checked out repo mount the root of the github repo to `/snapshot`:

$ docker run -ti -v /tmp/target:/target -v /home/jdef/kubernetes-mesos:/snapshot \
mesosphere/kubernetes-mesos:build bash
mesosphere/kubernetes-mesos-build bash

## Profiling

Profiling in the cloud with Kubernetes-Mesos is easy!
First, ssh into your Mesos cluster and generate a set of project binaries:

$ docker run --rm -ti -e GIT_BRANCH=offer_storage \
-v $(pwd)/bin:/target mesosphere/kubernetes-mesos:build
-v $(pwd)/bin:/target mesosphere/kubernetes-mesos-build

Next, [start the framework](https://github.com/mesosphere/kubernetes-mesos/#start-the-framework) with the `--profiling` flag and schedule some pods.
Once the framework and executors are up and running you can start capturing heaps:
Expand Down
14 changes: 11 additions & 3 deletions hack/dockerbuild/run.sh → docker/build/bin/km-build
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash

# NOT FOR LOCAL USE!
# Designed for use by docker/build/Dockerfile

echo Running with args "${@}"

set -e
Expand All @@ -8,14 +12,18 @@ set -vx
GOPKG=github.com/mesosphere/kubernetes-mesos

test ${#} -eq 0 && CMD=( make bootstrap install ) || CMD=( "${@}" )
test -n "$GOPATH" || GOPATH=/pkg

if [ -z "$GOPATH" ]; then
echo "ERROR: GOPATH must be set" >&2
exit 1
fi

# gopath is first directory in GOPATH : separated list
gopath="${GOPATH%%:*}"
pkg="${gopath}/src/${GOPKG}"

if [ -d $SNAP ]; then
test ! -L "${pkg}" || /bin/rm -vf "${pkg}" # remove any existing link
test ! -L "${pkg}" || rm -vf "${pkg}" # remove any existing link
parent=$(dirname "${pkg}")
mkdir -pv "$parent"
ln -sv $SNAP "$parent/$(basename $GOPKG)"
Expand Down
43 changes: 43 additions & 0 deletions docker/build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# paths relative to project dir
EXPECTED_SCRIPT_DIR=docker/build
EXPECTED_BINARY_DIR=bin

set -ex

script_dir=$(cd $(dirname $0) && pwd -P)

# defence against lazy refactoring
[[ "$script_dir" != *"$EXPECTED_SCRIPT_DIR" ]] && echo "Build script has moved! Expected location: $EXPECTED_SCRIPT_DIR" && exit 1

project_dir=$(cd "${script_dir}/../.." && pwd -P)
cd ${project_dir}

# create temp dir in project dir to avoid permission issues
WORKSPACE=$(env TMPDIR=$PWD mktemp -d -t "k8sm-workspace")
echo "Workspace created: $WORKSPACE"

cleanup() {
rm -rf ${WORKSPACE}
echo "Workspace deleted: $WORKSPACE"
}
trap 'cleanup' EXIT

mkdir ${WORKSPACE}/bin

# setup workspace to mirror project dir (for resources required by the dockerfile)
echo "Setting up workspace"
mkdir -p ${WORKSPACE}/docker/bin
cp ${project_dir}/docker/bin/* ${WORKSPACE}/docker/bin/
mkdir -p ${WORKSPACE}/docker/build/bin
cp ${project_dir}/docker/build/bin/* ${WORKSPACE}/docker/build/bin/

# Dockerfile must be within build context
cp ${project_dir}/${EXPECTED_SCRIPT_DIR}/Dockerfile ${WORKSPACE}/

cd ${WORKSPACE}

# build docker image
echo "Building kubernetes-mesos-build docker image"
docker build -t mesosphere/kubernetes-mesos-build .
3 changes: 2 additions & 1 deletion docker/complete/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

# paths relative to project dir
EXPECTED_SCRIPT_DIR=docker/complete
EXPECTED_BINARY_DIR=bin

Expand All @@ -26,7 +27,7 @@ trap 'cleanup' EXIT
mkdir ${WORKSPACE}/bin

echo "Building kubernetes-mesos binaries"
docker run --rm -v ${WORKSPACE}/bin:/target mesosphere/kubernetes-mesos:build
docker run --rm -v ${WORKSPACE}/bin:/target mesosphere/kubernetes-mesos-build

echo "Binaries produced:"
ls ${WORKSPACE}/bin
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ controller:
(grep "mesos-master\s*=" /opt/mesos-cloud.conf || echo " mesos-master = mesos:5050" >> /opt/mesos-cloud.conf) &&
await-health-check http://etcd:4001/health &&
await-health-check http://mesos:5050/health &&
await-health-check http://apiserver:8888/healthz &&
await-health-check -t=30 http://apiserver:8888/healthz &&
km controller-manager
--master=http://apiserver:8888
--cloud_config=/opt/mesos-cloud.conf
Expand All @@ -87,7 +87,7 @@ scheduler:
(grep "mesos-master\s*=" /opt/mesos-cloud.conf || echo " mesos-master = mesos:5050" >> /opt/mesos-cloud.conf) &&
await-health-check http://etcd:4001/health &&
await-health-check http://mesos:5050/health &&
await-health-check http://apiserver:8888/healthz &&
await-health-check -t=30 http://apiserver:8888/healthz &&
km scheduler
--address=$(resolveip scheduler)
--hostname_override=scheduler
Expand Down
2 changes: 1 addition & 1 deletion docker/km/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trap 'cleanup' EXIT
mkdir ${WORKSPACE}/bin

echo "Building kubernetes-mesos binaries"
docker run --rm -v ${WORKSPACE}/bin:/target mesosphere/kubernetes-mesos:build
docker run --rm -v ${WORKSPACE}/bin:/target mesosphere/kubernetes-mesos-build

echo "Binaries produced:"
ls ${WORKSPACE}/bin
Expand Down
3 changes: 0 additions & 3 deletions hack/dockerbuild/.dockerignore

This file was deleted.

24 changes: 0 additions & 24 deletions hack/dockerbuild/Dockerfile

This file was deleted.

4 changes: 0 additions & 4 deletions hack/dockerbuild/build

This file was deleted.

0 comments on commit e866b03

Please sign in to comment.