Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docker/Dockerfile.builder.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Image for compiling mantle.

FROM ubuntu:17.10

ARG GO_VERSION=1.10

RUN apt-get update && apt-get install -y \
apt-utils \
gcc \
gcc-aarch64-linux-gnu \
git \
wget \
&& rm -rf /var/lib/apt/lists/*

RUN wget --no-verbose https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -C /usr/local -xf go${GO_VERSION}.linux-amd64.tar.gz && \
rm go${GO_VERSION}.linux-amd64.tar.gz

ENV PATH /usr/local/go/bin:${PATH}

CMD /bin/bash
20 changes: 20 additions & 0 deletions docker/Dockerfile.builder.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Image for compiling mantle.

FROM arm64v8/ubuntu:17.10

ARG GO_VERSION=1.10

RUN apt-get update && apt-get install -y \
apt-utils \
gcc \
git \
wget \
&& rm -rf /var/lib/apt/lists/*

RUN wget --no-verbose https://storage.googleapis.com/golang/go${GO_VERSION}.linux-arm64.tar.gz && \
tar -C /usr/local -xf go${GO_VERSION}.linux-arm64.tar.gz && \
rm go${GO_VERSION}.linux-arm64.tar.gz

ENV PATH /usr/local/go/bin:${PATH}

CMD /bin/bash
16 changes: 16 additions & 0 deletions docker/Dockerfile.runner.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Image for running mantle programs.

FROM ubuntu:17.10

RUN apt-get update && apt-get install -y \
apt-utils \
qemu-system-arm \
qemu-system-x86-64 \
dnsmasq \
&& rm -rf /var/lib/apt/lists/*

COPY ./bin /usr/lib/kola/

ENV PATH /usr/lib/kola:${PATH}

CMD /bin/bash
15 changes: 15 additions & 0 deletions docker/Dockerfile.runner.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Image for running mantle programs.

FROM arm64v8/ubuntu:17.10

RUN apt-get update && apt-get install -y \
apt-utils \
qemu-system-arm \
dnsmasq \
&& rm -rf /var/lib/apt/lists/*

COPY ./bin /usr/lib/kola/

ENV PATH /usr/lib/kola:${PATH}

CMD /bin/bash
37 changes: 37 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Mantle Container Support

## Command Summary

- `build-builder` Builds a docker image that contains tools for building mantle. Default docker image tag is `mantle-builder:${VERSION}${ARCH_TAG}`.
- `build-mantle` Builds mantle programs using a mantle-builder container.
- `build-runner` Builds a docker image that containes the mantle programs. Default docker image tag is `mantle-runner:${VERSION}${ARCH_TAG}`.
- `run-mantle` Runs mantle programs in a mantle-runner container.

## Examples

### Build the mantle-runner Container Image

./build-builder -v
./build-mantle -vt
./build-runner -v

### Run Kola Tests in a mantle-runner Container

See https://coreos.com/releases for release info.

CHANNEL=alpha
BOARD=amd64-usr
#BOARD=arm64-usr
RELEASE=current
SERVER=https://${CHANNEL}.release.core-os.net/${BOARD}/${RELEASE}
RELEASES=/tmp/coreos-releses

mkdir -p ${RELEASES}/${CHANNEL}/${BOARD}/${RELEASE}
pushd ${RELEASES}/${CHANNEL}/${BOARD}/${RELEASE}
wget --no-verbose ${SERVER}/coreos_production_qemu_uefi{.DIGESTS,.sh,_efi_code.fd,_efi_vars.fd}
wget --no-verbose ${SERVER}/coreos_production_image.bin.bz2{.DIGESTS,}
bunzip2 coreos_production_image.bin.bz2
popd

ls ${RELEASES}/${CHANNEL}/${BOARD}/${RELEASE}
DOCKER_ARGS="-v ${RELEASES}:/releases:ro" ./run-mantle -kv -- kola run coreos.basic --board="${BOARD}" --parallel=2 --platform=qemu --qemu-bios=/releases/${CHANNEL}/${BOARD}/${RELEASE}/coreos_production_qemu_uefi_efi_code.fd --qemu-image=/releases/${CHANNEL}/${BOARD}/${RELEASE}/coreos_production_image.bin
101 changes: 101 additions & 0 deletions docker/build-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

set -e

name="$(basename $0)"

: ${TOP_DIR:="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"}

source ${TOP_DIR}/docker/builder-include

: ${DOCKER_FILE:="${TOP_DIR}/docker/Dockerfile.builder.$(goarch)"}
: ${GO_VERSION:="1.10"}

usage () {
echo "${name} - Builds a docker image that contains tools for building mantle." >&2
echo "Usage: ${name} [flags]" >&2
echo "Option flags:" >&2
echo " -d --dry-run - Do not run docker commands." >&2
echo " -h --help - Show this help and exit." >&2
echo " -p --purge - Remove existing docker image and rebuild." >&2
echo " -r --rebuild - Rebuild existing docker image." >&2
echo " -t --tag - Print Docker tag to stdout and exit." >&2
echo " -v --verbose - Verbose execution." >&2
echo "Environment:" >&2
echo " DOCKER_FILE - Default: '${DOCKER_FILE}'" >&2
echo " DOCKER_TAG - Default: '${DOCKER_TAG}'" >&2
echo " GO_VERSION - Default: '${GO_VERSION}'" >&2
}

short_opts="dhprtv"
long_opts="dry-run,help,purge,rebuild,tag,verbose"

opts=$(getopt --options ${short_opts} --long ${long_opts} -n "${name}" -- "$@")

if [ $? != 0 ]; then
echo "${name}: Terminating..." >&2
exit 1
fi

eval set -- "${opts}"

while true ; do
case "${1}" in
-d | --dry-run)
dry_run="--dry-run"
shift
;;
-h | --help)
usage
exit 0
;;
-p | --purge)
purge=1
shift
;;
-r | --rebuild)
rebuild=1
shift
;;
-t | --tag)
show_tag
exit 0
;;
-v | --verbose)
set -x
verbose=1
shift
;;
--)
shift
break
;;
*)
echo "Error: Unknown option '${1}'." >&2
usage
exit 1
;;
esac
done

if [[ -n "${purge}" ]] && docker inspect --type image ${DOCKER_TAG} >/dev/null 2>/dev/null; then
echo "Removing docker image: ${DOCKER_TAG}" >&2
[[ -n ${dry_run} ]] || docker rmi --force ${DOCKER_TAG}
elif [[ -z "${rebuild}" ]] && docker inspect --type image ${DOCKER_TAG} >/dev/null 2>/dev/null; then
echo "Docker image exists: ${DOCKER_TAG}" >&2
show_tag
exit 0
fi

echo "Building docker image: ${DOCKER_TAG}" >&2

if [[ -z ${dry_run} ]]; then
cd ${TOP_DIR}
docker build \
--file ${DOCKER_FILE} \
--build-arg GO_VERSION=${GO_VERSION} \
--tag ${DOCKER_TAG} \
.
fi

show_tag
114 changes: 114 additions & 0 deletions docker/build-mantle
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash

set -e

: ${TOP_DIR:="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"}

source ${TOP_DIR}/docker/builder-include

: ${CC:="gcc"}
: ${GOARCH:="$(goarch)"}
: ${NO_CROSS:=""}

usage () {
echo "$(basename $0) - Builds mantle programs using a ${DOCKER_TAG} container." >&2
echo "Usage: $(basename $0) [flags] [--] [build_args]" >&2
echo "Option flags:" >&2
echo " -a --arm64 - Build with common arm64 cross compile args." >&2
echo " -d --dry-run - Do not run docker commands." >&2
echo " -h --help - Show this help and exit." >&2
echo " -r --verify - Run golang tests after build." >&2
echo " -t --test - Run golang tests." >&2
echo " -v --verbose - Verbose execution." >&2
echo "Environment:" >&2
echo " CC - Default: '${CC}'" >&2
echo " GOARCH - Default: '${GOARCH}'" >&2
echo " NO_CROSS - Default: '${NO_CROSS}'" >&2
echo " DOCKER_TAG - Default: '${DOCKER_TAG}'" >&2
echo "Examples:" >&2
echo " $(basename $0) -vt"
echo " $(basename $0) -v -- cork"
echo " CC=aarch64-linux-gnu-gcc GOARCH=arm64 NO_CROSS=1 $(basename $0)"
}

short_opts="adhrtv"
long_opts="arm64,dry-run,help,verify,test,verbose"

opts=$(getopt --options ${short_opts} --long ${long_opts} -n "${name}" -- "$@")

if [ $? != 0 ]; then
echo "${name}: Terminating..." >&2
exit 1
fi

eval set -- "${opts}"

while true ; do
case "${1}" in
-a | --arm64)
CC="aarch64-linux-gnu-gcc"
GOARCH="arm64"
NO_CROSS="1"
shift
;;
-d | --dry-run)
dry_run="--dry-run"
shift
;;
-h | --help)
usage
exit 0
;;
-r | --verify)
verify=1
shift
;;
-t | --test)
test=1
shift
;;
-v | --verbose)
set -x
verbose=1
bash_debug="bash -x"
test_extra="-v"
shift
;;
--)
shift
build_args=${*}
break
;;
*)
build_args="${build_args} ${1}"
shift
;;
esac
done

docker_args="--rm \
-e CC=${CC}
-e GOARCH=${GOARCH} \
-e GOCACHE=/tmp/gocache \
-e NO_CROSS=${NO_CROSS} \
-u $(id -u):$(id -g) \
-v /etc/group:/etc/group:ro \
-v /etc/passwd:/etc/passwd:ro \
-v ${TOP_DIR}:/opt/mantle \
-w /opt/mantle \
"

# Need this for linkat to work in container.
docker_test_args="-v /tmp:/tmp:rw"

cd ${TOP_DIR}

[[ -z ${dry_run} ]] || exit 0

if [[ -z "${test}" ]]; then
docker run ${docker_args} ${DOCKER_TAG} ${bash_debug} ./build ${build_args}
fi

if [[ -n "${test}" || -n "${verify}" ]]; then
docker run ${docker_args} ${docker_test_args} ${DOCKER_TAG} ${bash_debug} ./test ${test_extra}
fi
Loading