build: update README files for build and images

This commit is contained in:
Bassam Tabbara committed 2017-06-20 20:57:46 -07:00
1 parent 1e68e35c16
commit 18e34ac3ce
5 files changed
+79 -310

No files matched your search

-192
View File
@@ -1,192 +0,0 @@
## Link Mode
`rookd` is golang binary that uses cgo to interface with embedded Ceph. The Ceph
project is a submodule of Rook and is built from the top level Makefile. Ceph
has numerous dependencies. We support the following link modes when linking:
### All Static
This option produces completely static binaries for `rookd` and `rook`. These
binaries can easily be used inside scratch containers, or on distributions
where dependencies can not be easily satisfied. To build statically we recommend
the you build only through the build container. While its possible to build statically
on the host, you might not be able to satisfy the needed dependencies.
```
build/run make LINKMODE=static
```
Here's an example of what the dependencies look like in this mode:
```
> ldd bin/linux_amd64/rookd
not a dynamic executable
```
### All Dynamic (Default)
This option produces binaries that link dynamically to dependent packages, and
is intended for traditional Linux distributions like Ubuntu or CentOS. All
dependencies would need to be installed on the system for `rookd` to run
correctly. This is the default LINKMODE.
```
make LINKMODE=dynamic
```
In this mode the system dependencies can vary from one distro to another. Here's an
example of what the dependencies look like on Ubuntu:
```
> build/run ldd bin/linux_amd64/rookd
linux-vdso.so.1 => (0x00007ffc053c3000)
libboost_system.so.1.62.0 => /usr/local/lib/x86_64-linux-gnu/libboost_system.so.1.62.0 (0x00007f56f6e33000)
libboost_thread.so.1.62.0 => /usr/local/lib/x86_64-linux-gnu/libboost_thread.so.1.62.0 (0x00007f56f6c0b000)
libboost_iostreams.so.1.62.0 => /usr/local/lib/x86_64-linux-gnu/libboost_iostreams.so.1.62.0 (0x00007f56f69f6000)
libboost_random.so.1.62.0 => /usr/local/lib/x86_64-linux-gnu/libboost_random.so.1.62.0 (0x00007f56f67f0000)
libblkid.so.1 => /usr/local/lib/x86_64-linux-gnu/libblkid.so.1 (0x00007f56f65aa000)
libz.so.1 => /usr/local/lib/x86_64-linux-gnu/libz.so.1 (0x00007f56f6392000)
libsnappy.so.1 => /usr/lib/x86_64-linux-gnu/libsnappy.so.1 (0x00007f56f6184000)
libcrypto++.so.6 => /usr/lib/x86_64-linux-gnu/libcrypto++.so.6 (0x00007f56f5c05000)
libaio.so.1 => /lib/x86_64-linux-gnu/libaio.so.1 (0x00007f56f5a03000)
libcurl.so.4 => /usr/local/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f56f57cd000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f56f5396000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f56f5192000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f56f4f77000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f56f4d59000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f56f49d1000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f56f46c8000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f56f44af000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f56f40e8000)
/lib64/ld-linux-x86-64.so.2 (0x0000564ace68d000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f56f3ee0000)
libuuid.so.1 => /usr/local/lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f56f3cdb000)
(more)
```
Note the Libraries like libcurl can bring in lots of other dependencies, and vary widely
between distributions.
### Dynamic Standard Library
This option produces mostly static binaries, whith just the standard C/C++ libraries
dynamically linked. Its intended for restricted Linux environments like CoreOS when
running directly on the host OS (and not inside a container).
```
make LINKMODE=stdlib
```
Here's an example of what the dependencies look like in this mode:
```
> ldd bin/linux_amd64/rookd
linux-vdso.so.1 => (0x00007fff45fb6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5305d4e000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f5305b33000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5305915000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f530558d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5305284000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f530506b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5304ca4000)
/lib64/ld-linux-x86-64.so.2 (0x000055d3eb36e000)
```
## Hardened binary (PIE)
You can build a Position Independent executable. Note that this requires LINKMODE set
to `dynamic` or `stdlib`
```
make LINKMODE=stdlib PIE=1
```
## Switching Allocators
Using a different memory allocator can impact the overall performance of the system.
Three allocators are currently supported: jemalloc, tcmalloc and libc. To specify
an allocator during the build run the following:
```
make ALLOCATOR=jemalloc
```
## Debug Builds
To build a binary with debug symbols run the following:
```
make DEBUG=1
```
Note the binary will be significantly larger in size.
## Verbose Builds
To turn on verbose build output run the following
```
make V=1
```
## Parallel Builds
You can speed up the build significantly by passing the -j flag to make as follows:
```
make -j4
```
## Enabling ccache
C++ code can take time to compile. CCache can increase the speed of compilation. If you're
using the build container this is enabled by default. To enable make sure you have
ccache installed:
```
apt-get install ccache
```
to run with ccache enabled run the following:
```
export CCACHE_DIR=~/.ccache
make
```
to check ccache stats run:
```
ccache -s
```
to clear the stats run:
```
ccache -z
```
to clear the cache run:
```
ccache -C
```
## Cross Compiling
To cross compile run:
```
make -j4 cross
```
This will build Rook for all supported platforms. If you want to cross compile for a specific
platform pass GOOS and GOARCH as follows:
```
make -j4 GOOS=windows GOARCH=amd64
```
Note that `rookd` is only supported on Linux and it will be skipped when building on an
unsupported OS or arch.
+20 -88
View File
@@ -1,75 +1,21 @@
# Building Rook
While it is possible to build Rook directly on your host, we highly discourage it.
Rook has many dependencies (mostly through Ceph) and it might be hard to keep
up with the different versions across distros. Instead we recommend that you use
the build process that runs inside a Docker container. It results in a consistent
build, test and release environment.
Rook is a golang project and can be built directly on the host with just `make`
and `golang` installed.
## Requirements
Rook can also be built inside a Docker container and results in a consistent
build, test and release environment. We recommend the cross build container, and
our Jenkins build and test environment uses it.
A capable machine (2+ cores, 8+ GB of memory) with Docker installed locally:
## Building Rook for the host platform
* MacOS: you can use Docker for Mac or your own docker-machine
* Linux: any distro with a recent version of Docker would work
We do not currently support building on a remote docker host.
### QEMU support on host
If you use docker for Mac it already has support for this. Skip this.
If you are planning on cross building the arm and aarch64 containers you must
install QEMU and enable binfmt support. On an Ubuntu machine with a 4.8+ kernel
you need to run install the following:
Now you can build in the container normally, like so:
```
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
binfmt-support
qemu-user-static
make -j4
```
You also need to run the following on every boot:
```
docker run --rm --privileged hypriot/qemu-register
```
you can install a systemd unit to help with this if you'd like, for example:
```
cat <<EOF > /etc/systemd/system/update-binfmt.service
[Unit]
After=docker.service
[Service]
Type=oneshot
ExecStart=/usr/bin/docker run --rm --privileged hypriot/qemu-register
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
systemctl enable update-binfmt.service
```
To test run the following:
```
docker run --rm -ti armhf/alpine uname -a
docker run --rm -ti aarch64/alpine uname -a
```
## Update the git submodules
Rook has many git submodules, and before you can
build Rook you need to initialize them:
```
git submodule sync --recursive
git submodule update --recursive --init
```
This will build just the binaries and copy them to the applicable subfolder of ./bin.
## Using the Build Container
@@ -79,11 +25,12 @@ To run a command inside the container:
> build/run <command>
```
This will run `<command>` from inside the container where all tools and dependencies
This will run `<command>` from inside the container where all tools and dependencies
have been installed and configured. The current directory is set to the source directory
which is bind mounted (or rsync'd on some platforms) inside the container.
The first run of `build/run` will pull the container (which can take a while).
The first run of `build/run` will build the container itself and could take a few
minutes to complete.
If you don't pass a command you get an interactive shell inside the container.
@@ -92,41 +39,26 @@ If you don't pass a command you get an interactive shell inside the container.
rook@moby:~/go/src/github.com/rook/rook$
```
## Building Rook
## Building Rook for all platforms
Now you can build in the container normally, like so:
```
build/run make -j4
make -j4 build.all
```
This will build just the binaries and copy them to the applicable subfolder of ./bin.
## Building all releasable artifacts
See [Makefile](Makefile.md) for more build options.
## Updating the Build container
To modify the build container change the Dockerfile and/or associated scripts. Also bump
the version in `build/container/version`. We require a version bump for any change
in order to use the correct version of the container across releases and branches.
To create a new build of the container run:
To build all release artifats run:
```
cd build/container
make
make -j4 release
```
If all looks good you can publish it by calling `make publish`. Note that you need
quay.io credentials to push a new build.
## Resetting the build container
Here's a rough sketch of the proposed approach somewhat influenced by how CoreOS is released.
## Resetting the Container
To reset the build container and it's persistent volumes, you can run the below command.
You shouldn't have to do this often unless something is broken or stale with your
build container:
If you're running the build container on the Mac using Docker for Mac, the build
container will rely on rsync to copy source to and from the host. To reset the build container and it's persistent volumes, you can run the below command. You shouldn't have to do this often unless something is broken or stale with your build container:
```
build/reset
+1 -4
View File
@@ -57,7 +57,6 @@ help:
@echo ' current build.'
@echo ' prune Prunes orphaned and cached images at the.'
@echo ' host level.'
@echo ' push Pushes public images to registry.'
@echo ''
@echo 'Advanced Targets:'
@echo ' cross Build images used for cross building.'
@@ -72,12 +71,10 @@ help:
@echo ' REGISTRY The docker registry to push to. Default is'
@echo ' quay.io/rook.'
@echo ' V Set to 1 enable verbose build. Default is 0.'
@echo ' VERSION The version used for image tags. The default'
@echo ' is obtained from git.'
@echo ''
@echo 'Advanced Options:'
@echo ' PRUNE_HOURS The number of hours from when an image is'
@echo ' created for it to be considered a target for'
@echo ' last used for it to be considered a target for'
@echo ' pruning. Default is 48 hrs.'
@echo ' PRUNE_KEEP The minimum number of cached images to keep.'
@echo ' Default is 24 images.'
+58 -19
View File
@@ -2,30 +2,39 @@
This folder contains all images used by the Rook project:
- base - this is a small base Ubuntu image
- base - small base Ubuntu image used as the base for other images
- ceph - images that build ceph
- cross - an image that contains tools for cross building
- cross-gnu - an image that contains gnu tools for cross compiling
- cross-go - an image that contains gnu tools and go tools for cross compiling
- rookd - an image that contains rookd, ceph and other tools
# Versioning
# Building Images
Be sure to bump the version number everytime you make a change to the container,
regardless of how small that change.
## Build Requirements
# Build Requirements
A capable machine (2+ cores, 8+ GB of memory) with Docker installed locally:
A capable machine (2+ cores, 8+ GB of memory):
* MacOS: you can use Docker for Mac or your own docker-machine
* Linux: any distro with a recent version of Docker would work
* Linux: any distro with Docker 1.12+
We do not currently support building on a remote docker host.
## Cross Building Containers
## Building for the host platform
If you are using a recent Docker for Mac build you can skip this section, since
they added support for binfmt and multi-arch docker builds.
Run `make` or `make build` will build all the images for the host platform. Note that this
will build all images and cache them (see Image Caching below).
If you are planning on cross building the arm and arm64 containers you must
install QEMU and enable binfmt support. On an Ubuntu machine with a 4.8+ kernel
you need to run install the following:
## Building for other platforms
To build for all supported platforms run `make build.all`.
In order to build container images for these platforms we rely on cross-compilers and QEMU. Cross compiling is much faster than QEMU and so we lean heavily on it.
In order for QEMU to work inside docker containers you need to do a few things on
the linux host. If you are using a recent Docker for Mac build you can skip this section, since they added support for binfmt and multi-arch docker builds.
On an Ubuntu machine with a 4.8+ kernel you need to run install the following:
```
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
@@ -48,6 +57,7 @@ After=docker.service
[Service]
Type=oneshot
ExecStartPre=/usr/bin/docker pull hypriot/qemu-register
ExecStart=/usr/bin/docker run --rm --privileged hypriot/qemu-register
RemainAfterExit=yes
@@ -58,14 +68,43 @@ EOF
systemctl enable update-binfmt.service
```
## Checking if multi-arch is supported
### Checking if multi-arch is supported
To test run the following:
```
> docker run --rm -ti armhf/alpine uname -a
Linux 6ab4ed3ad07a 4.10.0-20-generic #22-Ubuntu SMP Thu Apr 20 09:22:42 UTC 2017 armv7l Linux
> docker run --rm -ti armhf/ubuntu uname -a
Linux dece9819612d 4.10.0-21-generic #23-Ubuntu SMP Fri Apr 28 16:14:22 UTC 2017 armv7l armv7l armv7l GNU/Linux
> docker run --rm -ti aarch64/alpine uname -a
Linux 758d8063d612 4.10.0-20-generic #22-Ubuntu SMP Thu Apr 20 09:22:42 UTC 2017 aarch64 Linux
> docker run --rm -ti aarch64/ubuntu uname -a
Linux 7ed5f0d0b618 4.10.0-21-generic #23-Ubuntu SMP Fri Apr 28 16:14:22 UTC 2017 aarch64 aarch64 aarch64 GNU/Linux
```
# Image Caching and Pruning
Doing a complete build of Rook and the storage packages it depends on can take a long time (more than an hour on a typical macbook). To speed things up we rely heavily on image caching in docker. Docker support content-addressable images by default and we use that
effectively when building images. Images are factored to increase reusability across
builds. We also tag and timestamp images that should remain in the cache to help future builds.
Not all parts of our build, however, can rely on content-addressable image caching. For example to build Ceph using `docker build` would mean that we could not `ccache` and the build could take much longer. Instead we build Ceph by running the build process with
`docker run` using a base image that has all the Ceph code and tools. To avoid building
Ceph over and over, we create a container image with the output of the ceph build and add it to the docker image cache.
## Pruning the cache
To prune the number of cached images run `make prune`. There are two options that control the level of pruning performed:
- `PRUNE_HOURS` - the number of hours from when an image was last used (a cache hit) for it to be considered for pruning. The default is 48 hrs.
- `PRUNE_KEEP` - the minimum number of cached images to keep in the cache. Default is 24 images.
# Apt Package Caching
When building images numerous apt-get operations are performed which can slow down the build significantly. To speed things up install the apt-cacher-ng package which will
cache apt packages on the host.
```
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends apt-cacher-ng
```
Our base image enables transparent proxy detection and will use the apt-cacher if available on the host. See images/base/Dockerfile for more information.
-7
View File
@@ -31,11 +31,6 @@ REGISTRY ?= quay.io/rook
# if we are running inside the container get our own cid
SELF_CID := $(shell cat /proc/self/cgroup | grep docker | grep -o -E '[0-9a-f]{64}' | head -n 1)
# version to use if not defined
ifeq ($(origin VERSION), undefined)
VERSION := $(shell git describe --dirty --always --tags)
endif
# the base ubuntu image to use
OSBASE ?= ubuntu:zesty
@@ -92,8 +87,6 @@ all: build
build: build.images
@$(MAKE) cache.images
push: push.images
clean: clean.build
prune: cache.prune