• Home
  • Raw
  • Download

Lines Matching +full:is +full:- +full:docker

8 #      http://www.apache.org/licenses/LICENSE-2.0
11 # distributed under the License is distributed on an "AS IS" BASIS,
20 # 1. Prepare the Docker image for the test
21 # 2. Run the Docker with appropriate flags to run the test
22 # 3. Upload the newly built Docker image
24 # in a way that is somewhat compatible with trampoline_v1.
27 # (/dev/shm is passed into the container as KOKORO_GFILE_DIR).
29 # gsutil cp gs://cloud-devrel-kokoro-resources/python-docs-samples/secrets_viewer_service_account.j…
30 # gsutil cp gs://cloud-devrel-kokoro-resources/python-docs-samples/automl_secrets.txt /dev/shm
36 # TRAMPOLINE_IMAGE: The docker image to use.
41 # (true|false): Whether to upload the Docker image after the
43 # TRAMPOLINE_BUILD_FILE: The script to run in the docker container.
44 # TRAMPOLINE_WORKSPACE: The workspace path in the docker container.
50 set -euo pipefail
54 if command -v tput >/dev/null && [[ -n "${TERM:-}" ]]; then
67 [ $(LC_ALL=C type -t $1)"" == "function" ]
73 # given color. The log message will also have an RFC-3339 timestamp
79 local timestamp="$(date -u "+%Y-%m-%dT%H:%M:%SZ")"
105 readonly tmpdir=$(mktemp -d -t ci-XXXXXXXX)
107 mkdir -p "${tmphome}"
110 rm -rf "${tmpdir}"
114 RUNNING_IN_CI="${RUNNING_IN_CI:-false}"
117 TRAMPOLINE_WORKSPACE="${TRAMPOLINE_WORKSPACE:-/workspace}"
135 if [[ -n "${KOKORO_BUILD_ID:-}" ]]; then
139 if [[ "${TRAMPOLINE_USE_LEGACY_SERVICE_ACCOUNT:-}" == "true" ]]; then
140 if [[ ! -f "${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json" ]]; then
141 …ed "${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json does not exist. Did you forget to m…
145 TRAMPOLINE_SERVICE_ACCOUNT="${KOKORO_GFILE_DIR}/kokoro-trampoline.service-account.json"
147 if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then
151 gcloud auth configure-docker --quiet
166 elif [[ "${TRAVIS:-}" == "true" ]]; then
188 elif [[ -n "${GITHUB_RUN_ID:-}" ]]; then
190 TRAMPOLINE_CI="github-workflow"
206 elif [[ "${CIRCLECI:-}" == "true" ]]; then
231 # Configure the service account for pulling the docker image.
234 while [[ ! -d "${dir}/.git" ]]; do
240 # Detect the project root. In CI builds, we assume the script is in
243 if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then
256 if [[ -n "${TRAMPOLINE_SERVICE_ACCOUNT:-}" ]]; then
258 mkdir -p "${tmpdir}/gcloud"
265 gcloud auth activate-service-account \
266 --key-file "${TRAMPOLINE_SERVICE_ACCOUNT}"
268 gcloud auth configure-docker --quiet
277 if [[ -f "${PROJECT_ROOT}/.trampolinerc" ]]; then
284 if [[ -z "${!e:-}" ]]; then
291 # script: e.g. "github/repo-name/.kokoro/run_tests.sh"
295 # ignore error on docker operations and test execution
298 log_yellow "Preparing Docker image."
299 # We only download the docker image in CI builds.
300 if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then
301 # Download the docker image specified by `TRAMPOLINE_IMAGE`
303 # We may want to add --max-concurrent-downloads flag.
305 log_yellow "Start pulling the Docker image: ${TRAMPOLINE_IMAGE}."
306 if docker pull "${TRAMPOLINE_IMAGE}"; then
307 log_green "Finished pulling the Docker image: ${TRAMPOLINE_IMAGE}."
310 log_red "Failed pulling the Docker image: ${TRAMPOLINE_IMAGE}."
315 if docker images "${TRAMPOLINE_IMAGE}:latest" | grep "${TRAMPOLINE_IMAGE}"; then
323 # The default user for a Docker container has uid 0 (root). To avoid
324 # creating root-owned files in the build directory we tell docker to
326 user_uid="$(id -u)"
327 user_gid="$(id -g)"
328 user_name="$(id -un)"
330 # To allow docker in docker, we add the user to the docker group in
332 docker_gid=$(cut -d: -f3 < <(getent group docker))
335 if [[ "${TRAMPOLINE_DOCKERFILE:-none}" != "none" ]]; then
336 # Build the Docker image from the source.
339 "-f" "${TRAMPOLINE_DOCKERFILE}"
340 "-t" "${TRAMPOLINE_IMAGE}"
341 "--build-arg" "UID=${user_uid}"
342 "--build-arg" "USERNAME=${user_name}"
345 docker_build_flags+=("--cache-from" "${TRAMPOLINE_IMAGE}")
348 log_yellow "Start building the docker image."
349 if [[ "${TRAMPOLINE_VERBOSE:-false}" == "true" ]]; then
350 echo "docker build" "${docker_build_flags[@]}" "${context_dir}"
353 # ON CI systems, we want to suppress docker build logs, only
355 if [[ "${RUNNING_IN_CI:-}" == "true" ]]; then
356 if docker build "${docker_build_flags[@]}" "${context_dir}" \
358 if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then
362 log_green "Finished building the docker image."
365 log_red "Failed to build the Docker image, aborting."
371 if docker build "${docker_build_flags[@]}" "${context_dir}"; then
372 log_green "Finished building the docker image."
375 log_red "Failed to build the Docker image, aborting."
389 "--rm"
392 "--network=host"
394 # Run in priviledged mode. We are not using docker for sandboxing or
396 "--privileged"
398 # Run the docker script with the user id. Because the docker image gets to
400 # To allow docker in docker, we need to use docker gid on the host.
401 "--user" "${user_uid}:${docker_gid}"
404 "--env" "USER=${user_name}"
406 # Mount the project directory inside the Docker container.
407 "--volume" "${PROJECT_ROOT}:${TRAMPOLINE_WORKSPACE}"
408 "--workdir" "${TRAMPOLINE_WORKSPACE}"
409 "--env" "PROJECT_ROOT=${TRAMPOLINE_WORKSPACE}"
412 "--volume" "${tmphome}:/h"
413 "--env" "HOME=/h"
415 # Allow docker in docker.
416 "--volume" "/var/run/docker.sock:/var/run/docker.sock"
418 # Mount the /tmp so that docker in docker can mount the files
420 "--volume" "/tmp:/tmp"
422 # TODO(tmatsuo): This part is not portable.
423 "--env" "TRAMPOLINE_SECRET_DIR=/secrets"
424 "--volume" "${KOKORO_GFILE_DIR:-/dev/shm}:/secrets/gfile"
425 "--env" "KOKORO_GFILE_DIR=/secrets/gfile"
426 "--volume" "${KOKORO_KEYSTORE_DIR:-/dev/shm}:/secrets/keystore"
427 "--env" "KOKORO_KEYSTORE_DIR=/secrets/keystore"
431 if [[ -t 0 ]]; then
432 docker_flags+=("-it")
438 if [[ -n "${!e:-}" ]]; then
439 docker_flags+=("--env" "${e}=${!e}")
445 if [[ $# -ge 1 ]]; then
448 if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then
449 echo docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" "${commands[@]}"
451 docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}" "${commands[@]}"
453 log_yellow "Running the tests in a Docker container."
454 docker_flags+=("--entrypoint=${TRAMPOLINE_BUILD_FILE}")
455 if [[ "${TRAMPOLINE_VERBOSE:-}" == "true" ]]; then
456 echo docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}"
458 docker run "${docker_flags[@]}" "${TRAMPOLINE_IMAGE}"
464 if [[ ${test_retval} -eq 0 ]]; then
473 [[ "${TRAMPOLINE_IMAGE_UPLOAD:-false}" == "true" ]]; then
474 log_yellow "Uploading the Docker image."
475 if docker push "${TRAMPOLINE_IMAGE}"; then
476 log_green "Finished uploading the Docker image."
478 log_red "Failed uploading the Docker image."