| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Copyright The containerd Authors. |
| 4 |
|
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
# you may not use this file except in compliance with the License. |
| 7 |
# You may obtain a copy of the License at |
| 8 |
|
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
|
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
|
| 17 |
set -euo pipefail |
| 18 |
|
| 19 |
CONTEXT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/" |
| 20 |
REPO="${CONTEXT}../../" |
| 21 |
|
| 22 |
source "${CONTEXT}/const.sh" |
| 23 |
source "${REPO}/script/util/utils.sh" |
| 24 |
|
| 25 |
CRI_TOOLS_VERSION=$(get_version_from_arg "${REPO}/Dockerfile" "CRI_TOOLS_VERSION") |
| 26 |
GINKGO_VERSION=v1.16.5 |
| 27 |
|
| 28 |
if [ "${CRI_NO_RECREATE:-}" != "true" ] ; then |
| 29 |
echo "Preparing node image..." |
| 30 |
|
| 31 |
docker build ${DOCKER_BUILD_ARGS:-} -t "${NODE_BASE_IMAGE_NAME}" --target crio-stargz-store "${REPO}" |
| 32 |
docker build ${DOCKER_BUILD_ARGS:-} -t "${PREPARE_NODE_IMAGE}" --target containerd-base "${REPO}" |
| 33 |
fi |
| 34 |
|
| 35 |
USE_METADATA_STORE="memory" |
| 36 |
if [ "${METADATA_STORE:-}" != "" ] ; then |
| 37 |
USE_METADATA_STORE="${METADATA_STORE}" |
| 38 |
fi |
| 39 |
|
| 40 |
TMP_CONTEXT=$(mktemp -d) |
| 41 |
IMAGE_LIST=$(mktemp) |
| 42 |
function cleanup { |
| 43 |
local ORG_EXIT_CODE="${1}" |
| 44 |
rm -rf "${TMP_CONTEXT}" || true |
| 45 |
rm "${IMAGE_LIST}" || true |
| 46 |
exit "${ORG_EXIT_CODE}" |
| 47 |
} |
| 48 |
trap 'cleanup "$?"' EXIT SIGHUP SIGINT SIGQUIT SIGTERM |
| 49 |
|
| 50 |
# Prepare the testing node |
| 51 |
cat <<EOF > "${TMP_CONTEXT}/Dockerfile" |
| 52 |
# Legacy builder that doesn't support TARGETARCH should set this explicitly using --build-arg. |
| 53 |
# If TARGETARCH isn't supported by the builder, the default value is "amd64". |
| 54 |
|
| 55 |
FROM ${NODE_BASE_IMAGE_NAME} |
| 56 |
ARG TARGETARCH |
| 57 |
|
| 58 |
ENV PATH=$PATH:/usr/local/go/bin |
| 59 |
ENV GOPATH=/go |
| 60 |
# Do not install git and its dependencies here which will cause failure of building the image |
| 61 |
RUN apt-get update && apt-get install -y --no-install-recommends make && \ |
| 62 |
curl -Ls https://dl.google.com/go/go1.19.linux-\${TARGETARCH:-amd64}.tar.gz | tar -C /usr/local -xz && \ |
| 63 |
go install github.com/onsi/ginkgo/ginkgo@${GINKGO_VERSION} && \ |
| 64 |
mkdir -p \${GOPATH}/src/github.com/kubernetes-sigs/cri-tools /tmp/cri-tools && \ |
| 65 |
curl -sL https://github.com/kubernetes-sigs/cri-tools/archive/refs/tags/v${CRI_TOOLS_VERSION}.tar.gz | tar -C /tmp/cri-tools -xz && \ |
| 66 |
mv /tmp/cri-tools/cri-tools-${CRI_TOOLS_VERSION}/* \${GOPATH}/src/github.com/kubernetes-sigs/cri-tools/ && \ |
| 67 |
cd \${GOPATH}/src/github.com/kubernetes-sigs/cri-tools && \ |
| 68 |
make && make install -e BINDIR=\${GOPATH}/bin |
| 69 |
|
| 70 |
RUN echo "metadata_store = \"${USE_METADATA_STORE}\"" >> /etc/stargz-store/config.toml |
| 71 |
|
| 72 |
ENTRYPOINT [ "/usr/local/bin/entrypoint" ] |
| 73 |
EOF |
| 74 |
docker build -t "${NODE_TEST_IMAGE_NAME}" ${DOCKER_BUILD_ARGS:-} "${TMP_CONTEXT}" |
| 75 |
|
| 76 |
echo "Testing..." |
| 77 |
"${CONTEXT}/test-legacy.sh" "${IMAGE_LIST}" |
| 78 |
"${CONTEXT}/test-stargz.sh" "${IMAGE_LIST}" |