diff --git a/Makefile b/Makefile index bd77980f4..69ec92940 100644 --- a/Makefile +++ b/Makefile @@ -19,9 +19,10 @@ GO111MODULE_VALUE=auto PREFIX ?= out/ CMD=containerd-stargz-grpc ctr-remote - CMD_BINARIES=$(addprefix $(PREFIX),$(CMD)) +OUT_POSIX=out-posix + .PHONY: all build check install-check-tools install uninstall clean test test-root test-all integration test-optimize benchmark test-pullsecrets test-cri all: build @@ -61,6 +62,7 @@ uninstall: clean: @echo "$@" @rm -f $(CMD_BINARIES) + @rm -f $(OUT_POSIX) test: @echo "$@" @@ -86,3 +88,6 @@ test-pullsecrets: test-cri: @./script/cri/test.sh + +test-posix: + @./script/posix/test.sh \ No newline at end of file diff --git a/script/posix/Dockerfile b/script/posix/Dockerfile new file mode 100644 index 000000000..43b803aa9 --- /dev/null +++ b/script/posix/Dockerfile @@ -0,0 +1,33 @@ +# Copyright The containerd Authors. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM golang:1.13 + +# basic packages +RUN apt-get update -y && \ + apt-get --no-install-recommends install -y libbtrfs-dev libseccomp-dev fuse \ + apt-transport-https gnupg2 software-properties-common + +# runtime dependencies +RUN git clone https://github.com/opencontainers/runc \ + $GOPATH/src/github.com/opencontainers/runc && \ + cd $GOPATH/src/github.com/opencontainers/runc && \ + git checkout d736ef14f0288d6993a1845745d6756cfc9ddd5a && \ + GO111MODULE=off make BUILDTAGS='seccomp apparmor' && \ + GO111MODULE=off make install && \ + git clone https://github.com/containerd/containerd \ + $GOPATH/src/github.com/containerd/containerd && \ + cd $GOPATH/src/github.com/containerd/containerd && \ + git checkout 990076b731ec9446437972b41176a6b0f3b7bcbf && \ + GO111MODULE=off make && GO111MODULE=off make install diff --git a/script/posix/config/config.containerd.toml b/script/posix/config/config.containerd.toml new file mode 100644 index 000000000..32f99b120 --- /dev/null +++ b/script/posix/config/config.containerd.toml @@ -0,0 +1,4 @@ +[proxy_plugins] + [proxy_plugins.stargz] + type = "snapshot" + address = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock" diff --git a/script/posix/config/config.stargz.toml b/script/posix/config/config.stargz.toml new file mode 100644 index 000000000..ba4384789 --- /dev/null +++ b/script/posix/config/config.stargz.toml @@ -0,0 +1 @@ +noprefetch = false diff --git a/script/posix/pjdfstest/Dockerfile b/script/posix/pjdfstest/Dockerfile new file mode 100644 index 000000000..3b8e653b0 --- /dev/null +++ b/script/posix/pjdfstest/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.9 AS stage-build +WORKDIR /work +RUN apk add git automake autoconf build-base && \ + git clone https://github.com/pjd/pjdfstest.git /work/pjdfstest && \ + cd /work/pjdfstest && \ + git checkout a75ea1caf843a3a1e6c866b61bf954f68cee4a85 && \ + autoreconf -ifs && ./configure && make pjdfstest + +FROM alpine:3.9 AS stage-final +WORKDIR /work +COPY --from=stage-build /work/pjdfstest /work/pjdfstest +RUN apk add openssl perl-test-harness-utils +CMD ["prove", "-rv", "/work/pjdfstest/tests"] \ No newline at end of file diff --git a/script/posix/run.sh b/script/posix/run.sh new file mode 100755 index 000000000..ded1d9168 --- /dev/null +++ b/script/posix/run.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Copyright The containerd Authors. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euo pipefail + +# Check Dockerfile at script/posix/Dockerfile +IMAGE_PJDFSTEST="${IMAGE_PJDFSTEST:-docker.io/sequix/pjdfstest:v1-stargz}" +CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +function retry { + local RETRYNUM=30 + local RETRYINTERVAL=1 + local TIMEOUTSEC=180 + local SUCCESS=false + for i in $(seq ${RETRYNUM}) ; do + if eval "timeout ${TIMEOUTSEC} ${@}" ; then + SUCCESS=true + break + fi + echo "Fail(${i}). Retrying..." + sleep ${RETRYINTERVAL} + done + if [ "${SUCCESS}" == "true" ] ; then + return 0 + else + return 1 + fi +} + +specList() { + uname -r + cat /etc/os-release + cat /proc/cpuinfo + cat /proc/meminfo + mount + df -T +} +echo "Machine spec list:" +specList + +setup() { + local REPO_CONFIG_DIR=$CONTEXT/config/ + local CONTAINERD_CONFIG_DIR=/etc/containerd/ + local REMOTE_SNAPSHOTTER_SOCKET=/run/containerd-stargz-grpc/containerd-stargz-grpc.sock + local REMOTE_SNAPSHOTTER_CONFIG_DIR=/etc/containerd-stargz-grpc/ + + mkdir -p /tmp/out + PREFIX=/tmp/out/ make clean + PREFIX=/tmp/out/ make -j2 + PREFIX=/tmp/out/ make install + mkdir -p "${CONTAINERD_CONFIG_DIR}" + cp "${REPO_CONFIG_DIR}"config.containerd.toml "${CONTAINERD_CONFIG_DIR}" + mkdir -p "${REMOTE_SNAPSHOTTER_CONFIG_DIR}" + cp "${REPO_CONFIG_DIR}"config.stargz.toml "${REMOTE_SNAPSHOTTER_CONFIG_DIR}" + + containerd-stargz-grpc --log-level=debug \ + --address="${REMOTE_SNAPSHOTTER_SOCKET}" \ + --config="${REMOTE_SNAPSHOTTER_CONFIG_DIR}config.stargz.toml" \ + &>/var/log/containerd-stargz-grpc.log & + retry ls "${REMOTE_SNAPSHOTTER_SOCKET}" + + containerd --log-level debug \ + --config="${CONTAINERD_CONFIG_DIR}config.containerd.toml" \ + &>/var/log/containerd.log & + retry ctr version +} +echo "Setting up stargz-snaphsotter & containerd..." +setup + +testPosix() { + local containerID="posix-test_$(basename $(mktemp))" + ctr-remote image rpull "$IMAGE_PJDFSTEST" + ctr-remote run --rm --snapshotter=stargz "$IMAGE_PJDFSTEST" "$containerID" >/output || \ + echo -e "\e[91mPosix test failed!\e[0m" +} +echo "Testing posix calls..." +testPosix diff --git a/script/posix/test.sh b/script/posix/test.sh new file mode 100755 index 000000000..c357a0cbd --- /dev/null +++ b/script/posix/test.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Copyright The containerd Authors. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euo pipefail + +cleanup() { + local ORG_EXIT_CODE="${1}" + rm "${DOCKER_COMPOSE_YAML}" || true + exit "${ORG_EXIT_CODE}" +} +trap 'cleanup "$?"' EXIT SIGHUP SIGINT SIGQUIT SIGTERM + +CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/" +REPO="${CONTEXT}../../" + +echo "Preparing docker-compose.yml..." +DOCKER_COMPOSE_YAML=$(mktemp) +BENCHMARKING_NODE=posix-test +BENCHMARKING_CONTAINER=posix-test +cat < "${DOCKER_COMPOSE_YAML}" +version: "3" +services: + ${BENCHMARKING_NODE}: + build: + context: "${CONTEXT}/" + dockerfile: Dockerfile + container_name: ${BENCHMARKING_CONTAINER} + privileged: true + working_dir: /go/src/github.com/containerd/stargz-snapshotter + command: tail -f /dev/null + environment: + - NO_PROXY=127.0.0.1,localhost + - HTTP_PROXY=${HTTP_PROXY:-} + - HTTPS_PROXY=${HTTPS_PROXY:-} + - http_proxy=${http_proxy:-} + - https_proxy=${https_proxy:-} + tmpfs: + - /tmp:exec,mode=777 + volumes: + - "${REPO}:/go/src/github.com/containerd/stargz-snapshotter:ro" + - "/dev/fuse:/dev/fuse" + - "containerd-data:/var/lib/containerd:delegated" + - "containerd-stargz-grpc-data:/var/lib/containerd-stargz-grpc:delegated" + - "containerd-stargz-grpc-status:/run/containerd-stargz-grpc:delegated" +volumes: + containerd-data: + containerd-stargz-grpc-data: + containerd-stargz-grpc-status: +EOF + +echo "Setup posix test environment..." +docker-compose -f "${DOCKER_COMPOSE_YAML}" build ${DOCKER_BUILD_ARGS:-} "${BENCHMARKING_NODE}" +docker-compose -f "${DOCKER_COMPOSE_YAML}" up -d --force-recreate + +echo "Posix testing..." +docker exec -i "${BENCHMARKING_CONTAINER}" script/posix/run.sh + +echo "Harvesting output..." +docker cp "${BENCHMARKING_CONTAINER}:/output" "${REPO}/out-posix" + +echo "Cleaning up benchmark environment..." +docker-compose -f "${DOCKER_COMPOSE_YAML}" down -v