1818# be used to reproduce errors locally by modifying WORKDIR to be
1919# the top-level directory of the checked out TFMOT Github repository.
2020
21- # TODO(b/185727163): switch to prebuilt Docker image to speed this up.
22-
2321# Make Bash more strict, for easier debugging.
2422set -e # Exit on the first error.
2523set -u # Treat unset variables as error.
@@ -34,22 +32,53 @@ set -o pipefail # Treat the failure of a command in a pipeline as error.
3432# parameters, will print the full command, with credentials, in the build logs.
3533# set -x
3634
37- # Code under repo is checked out to
38- # ${KOKORO_ARTIFACTS_DIR}/github/tensorflow_model_optimization.
39- WORKDIR=" ${KOKORO_ARTIFACTS_DIR} /github/tensorflow_model_optimization"
35+ # The TFMOT Git repository is checked out here.
36+ GIT_REPO_DIR=" ${KOKORO_ARTIFACTS_DIR} /github/tensorflow_model_optimization"
37+
38+
39+ cleanup () {
40+ # Collect the test logs.
41+ docker exec tfmot find \
42+ -L " bazel-testlogs" \
43+ \( -name " test.log" -o -name " test.xml" \) \
44+ -exec cp --parents {} " ${KOKORO_ARTIFACTS_DIR} " \;
45+
46+ # Rename test.xml to sponge_log.xml so they show up in Sponge.
47+ docker exec tfmot find " ${KOKORO_ARTIFACTS_DIR} /bazel-testlogs" \
48+ -type f \
49+ -name test.xml \
50+ -execdir mv " {}" sponge_log.xml \;
4051
52+ # Rename test.log to sponge_log.log so they show up in Sponge.
53+ docker exec tfmot find " ${KOKORO_ARTIFACTS_DIR} /bazel-testlogs" \
54+ -type f \
55+ -name test.log \
56+ -execdir mv " {}" sponge_log.log \;
57+
58+ # Stop the container
59+ docker stop tfmot
60+ }
61+
62+ # Build the Docker image.
63+ # TODO(b/185727163): switch to prebuilt Docker image to speed this up.
4164docker build --tag tfmot \
42- $WORKDIR /ci/kokoro/gcp_ubuntu
65+ " ${GIT_REPO_DIR} /ci/kokoro/gcp_ubuntu"
4366
44- # Mount the checked out repository, make that the working directory and run
45- # ci/kokoro/build.sh from the repository, which runs all the unit tests.
67+ # Start a Docker container in the background.
68+ # The Kokoro artitifacts directory is mounted and the work directory
69+ # conveniently set to the TFMOT Git repository.
4670docker run \
47- --volume " ${WORKDIR?} : ${WORKDIR?} " \
48- --workdir= " ${WORKDIR?} " \
71+ -it \
72+ -d \
4973 --rm \
74+ --name tfmot \
75+ --volume " ${KOKORO_ARTIFACTS_DIR} :${KOKORO_ARTIFACTS_DIR} " \
76+ --workdir=" ${GIT_REPO_DIR} " \
5077 tfmot:latest \
51- ci/kokoro/build.sh
78+ bash
79+
80+ # On exit: collect the test logs and stop the container.
81+ trap cleanup EXIT
5282
53- # Kokoro will rsync this entire directory back to the executor orchestrating the
54- # build which takes forever and is totally useless.
55- sudo rm -rf " ${KOKORO_ARTIFACTS_DIR?} " /*
83+ # Run the tests inside the container,
84+ docker exec tfmot " ${GIT_REPO_DIR} /ci/kokoro/build.sh"
0 commit comments