Skip to content

Instantly share code, notes, and snippets.

@mrunalp
Last active March 28, 2016 16:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrunalp/fa5f420addea0cff31d1 to your computer and use it in GitHub Desktop.
Save mrunalp/fa5f420addea0cff31d1 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
set -x
RUNC_GOPATH="$(mktemp -d)"
CONTAINERD_GOPATH="$(mktemp -d)"
PWD="$(pwd)"
function cleanup() {
rm -rf "${RUNC_GOPATH}"
rm -rf "${CONTAINERD_GOPATH}"
cd "${PWD}"
}
trap cleanup EXIT
dockerfile_path="${GOPATH}/src/github.com/docker/docker/Dockerfile"
RUNC_COMMIT=$(grep RUNC_COMMIT $dockerfile_path | head -n 1 | cut -d" " -f 3)
echo $RUNC_COMMIT
CONTAINERD_COMMIT=$(grep CONTAINERD_COMMIT $dockerfile_path | head -n 1 | cut -d" " -f 3)
echo $CONTAINERD_COMMIT
echo "Building runc"
GOPATH=$RUNC_GOPATH
git clone git://github.com/opencontainers/runc.git "$GOPATH/src/github.com/opencontainers/runc"
pushd "$GOPATH/src/github.com/opencontainers/runc"
git checkout -q "$RUNC_COMMIT"
make BUILDTAGS="seccomp selinux"
cp runc /usr/local/bin/docker-runc
popd
echo "Building containerd"
GOPATH=$CONTAINERD_GOPATH
git clone git://github.com/docker/containerd.git "$GOPATH/src/github.com/docker/containerd"
pushd "$GOPATH/src/github.com/docker/containerd"
git checkout -q "$CONTAINERD_COMMIT"
make
cp bin/containerd /usr/local/bin/docker-containerd
cp bin/containerd-shim /usr/local/bin/docker-containerd-shim
cp bin/ctr /usr/local/bin/docker-containerd-ctr
popd
@rhatdan
Copy link

rhatdan commented Mar 25, 2016

Thanks, bug yuck.

@runcom
Copy link

runcom commented Mar 25, 2016

@mrunalp I've edited this slightly to not clutter the GOPATH of the caller:

old_gopath="${GOPATH}" # at the beginning
...
# your script here
...
export GOPATH=${old_gopath} # at the end

@runcom
Copy link

runcom commented Mar 25, 2016

I've also found out that with set -e the scripts exits immediately when, for instance, containerd is running on the system and you cannot cp the binary cause the file is busy (I simply systemctl stop docker before running this script so containerd exits and the script can cp)

@mrunalp
Copy link
Author

mrunalp commented Mar 25, 2016

@runcom, yes adding those changes makes sense. I was trying to see if others are willing to use it. We can maintain this in a repo so it makes it easier to build docker on Fedora/RHEL. Thanks!

@mrunalp
Copy link
Author

mrunalp commented Mar 28, 2016

@runcom I have updated it with improvements. It doesn't clobber the global GOPATH. It ensures cleanup of the tmp build directories and returns you to the directory from where the script was executed. Please try it out! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment