Debian Codegraph @

script/integration/test.sh

raw
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 INTEGRATION_BASE_IMAGE_NAME="integration-image-base"
23 INTEGRATION_TEST_IMAGE_NAME="integration-image-test"
24 REGISTRY_HOST=registry-integration.test
25 REGISTRY_ALT_HOST=registry-alt.test
26 CONTAINERD_NODE=testenv_integration
27 DUMMYUSER=dummyuser
28 DUMMYPASS=dummypass
29
30 IPFS_VERSION=v0.17.0
31
32 source "${REPO}/script/util/utils.sh"
33
34 if [ "${INTEGRATION_NO_RECREATE:-}" != "true" ] ; then
35 echo "Preparing node image..."
36
37 TARGET_STAGE=snapshotter-base
38 if [ "${BUILTIN_SNAPSHOTTER:-}" == "true" ] ; then
39 TARGET_STAGE=containerd-snapshotter-base
40 fi
41
42 # Enable to check race
43 # Temporary disable race check until docker/cli fixing race issue
44 # https://github.com/docker/cli/pull/3264
45 # BUILD_FLAGS="-race"
46 BUILD_FLAGS=""
47 docker build ${DOCKER_BUILD_ARGS:-} -t "${INTEGRATION_BASE_IMAGE_NAME}" \
48 --target "${TARGET_STAGE}" \
49 --build-arg=SNAPSHOTTER_BUILD_FLAGS="${BUILD_FLAGS}" \
50 "${REPO}"
51 fi
52
53 USE_METADATA_STORE="memory"
54 if [ "${METADATA_STORE:-}" != "" ] ; then
55 USE_METADATA_STORE="${METADATA_STORE}"
56 fi
57
58 SNAPSHOTTER_CONFIG_FILE=/etc/containerd-stargz-grpc/config.toml
59 if [ "${BUILTIN_SNAPSHOTTER:-}" == "true" ] ; then
60 SNAPSHOTTER_CONFIG_FILE=/etc/containerd/config.toml
61 fi
62
63 DOCKER_COMPOSE_YAML=$(mktemp)
64 AUTH_DIR=$(mktemp -d)
65 SS_ROOT_DIR=$(mktemp -d)
66 TMP_CONTEXT=$(mktemp -d)
67 function cleanup {
68 local ORG_EXIT_CODE="${1}"
69 rm "${DOCKER_COMPOSE_YAML}" || true
70 rm -rf "${AUTH_DIR}" || true
71 rm -rf "${SS_ROOT_DIR}" || true
72 rm -rf "${TMP_CONTEXT}" || true
73 exit "${ORG_EXIT_CODE}"
74 }
75 trap 'cleanup "$?"' EXIT SIGHUP SIGINT SIGQUIT SIGTERM
76
77 cp -R "${CONTEXT}/containerd" \
78 "${REPO}/script/util/utils.sh" \
79 "${TMP_CONTEXT}"
80 cat <<EOF > "${TMP_CONTEXT}/Dockerfile"
81 FROM ${INTEGRATION_BASE_IMAGE_NAME}
82
83 RUN apt-get update -y && \
84 apt-get --no-install-recommends install -y iptables jq && \
85 go install github.com/google/crfs/stargz/stargzify@71d77da419c90be7b05d12e59945ac7a8c94a543 && \
86 wget https://dist.ipfs.io/go-ipfs/${IPFS_VERSION}/go-ipfs_${IPFS_VERSION}_linux-amd64.tar.gz && \
87 tar -xvzf go-ipfs_${IPFS_VERSION}_linux-amd64.tar.gz && \
88 cd go-ipfs && \
89 bash install.sh
90
91 COPY ./containerd/config.containerd.toml /etc/containerd/config.toml
92 COPY ./containerd/config.stargz.toml /etc/containerd-stargz-grpc/config.toml
93 COPY ./containerd/entrypoint.sh ./utils.sh /
94
95 RUN sed -i 's/^metadata_store.*/metadata_store = "${USE_METADATA_STORE}"/g' "${SNAPSHOTTER_CONFIG_FILE}"
96
97 ENV CONTAINERD_SNAPSHOTTER=""
98
99 ENTRYPOINT [ "/entrypoint.sh" ]
100 EOF
101 docker build ${DOCKER_BUILD_ARGS:-} -t "${INTEGRATION_TEST_IMAGE_NAME}" ${DOCKER_BUILD_ARGS:-} "${TMP_CONTEXT}"
102
103 echo "Preparing creds..."
104 prepare_creds "${AUTH_DIR}" "${REGISTRY_HOST}" "${DUMMYUSER}" "${DUMMYPASS}"
105
106 echo "Preparing docker-compose.yml..."
107 cat <<EOF > "${DOCKER_COMPOSE_YAML}"
108 version: "3.3"
109 services:
110 ${CONTAINERD_NODE}:
111 image: ${INTEGRATION_TEST_IMAGE_NAME}
112 container_name: testenv_integration
113 privileged: true
114 environment:
115 - NO_PROXY=127.0.0.1,localhost,${REGISTRY_HOST}:443,${REGISTRY_ALT_HOST}:5000
116 - HTTP_PROXY=${HTTP_PROXY:-}
117 - HTTPS_PROXY=${HTTPS_PROXY:-}
118 - http_proxy=${http_proxy:-}
119 - https_proxy=${https_proxy:-}
120 - BUILTIN_SNAPSHOTTER=${BUILTIN_SNAPSHOTTER:-}
121 tmpfs:
122 - /tmp:exec,mode=777
123 volumes:
124 - "${REPO}:/go/src/github.com/containerd/stargz-snapshotter:ro"
125 - ${AUTH_DIR}:/auth
126 - /dev/fuse:/dev/fuse
127 - "integration-containerd-data:/var/lib/containerd"
128 - "integration-containerd-stargz-grpc-data:/var/lib/containerd-stargz-grpc"
129 registry:
130 image: registry:2
131 container_name: ${REGISTRY_HOST}
132 environment:
133 - HTTP_PROXY=${HTTP_PROXY:-}
134 - HTTPS_PROXY=${HTTPS_PROXY:-}
135 - http_proxy=${http_proxy:-}
136 - https_proxy=${https_proxy:-}
137 - REGISTRY_AUTH=htpasswd
138 - REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm"
139 - REGISTRY_AUTH_HTPASSWD_PATH=/auth/auth/htpasswd
140 - REGISTRY_HTTP_TLS_CERTIFICATE=/auth/certs/domain.crt
141 - REGISTRY_HTTP_TLS_KEY=/auth/certs/domain.key
142 - REGISTRY_HTTP_ADDR=${REGISTRY_HOST}:443
143 volumes:
144 - ${AUTH_DIR}:/auth
145 registry-alt:
146 image: registry:2
147 container_name: "${REGISTRY_ALT_HOST}"
148 volumes:
149 integration-containerd-data:
150 integration-containerd-stargz-grpc-data:
151 EOF
152
153 echo "Testing..."
154 FAIL=
155 if ! ( cd "${CONTEXT}" && \
156 docker-compose -f "${DOCKER_COMPOSE_YAML}" build ${DOCKER_BUILD_ARGS:-} \
157 "${CONTAINERD_NODE}" && \
158 docker-compose -f "${DOCKER_COMPOSE_YAML}" up --abort-on-container-exit ) ; then
159 FAIL=true
160 fi
161 docker-compose -f "${DOCKER_COMPOSE_YAML}" down -v
162 if [ "${FAIL}" == "true" ] ; then
163 exit 1
164 fi
165
166 exit 0
167