Skip to content

Commit

Permalink
bazel: introduce "--output_user_root" startup option
Browse files Browse the repository at this point in the history
  • Loading branch information
storypku authored and xiaoxq committed May 12, 2020
1 parent 29c7693 commit 2314d77
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache
docs
docker
scripts
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ docs/demo_guide/*.record

# Bash Environment
.dev_bash_hist

# bazel cache and others
.cache/
3 changes: 2 additions & 1 deletion apollo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ function warn_proprietary_sw() {
}

function release() {
RELEASE_DIR="${HOME}/.cache/apollo_release"
CACHE_DIR="/apollo/.cache"
RELEASE_DIR="${CACHE_DIR}/apollo_release"
if [ -d "${RELEASE_DIR}" ]; then
rm -rf "${RELEASE_DIR}"
fi
Expand Down
18 changes: 7 additions & 11 deletions apollo_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ function start_build_docker() {

function gen_docker() {
IMG="apolloauto/apollo:run-${MACHINE_ARCH}-20181017_1330"
RELEASE_DIR=${HOME}/.cache/apollo_release
APOLLO_DIR="${RELEASE_DIR}/apollo"
CACHE_ROOT_DIR="${DIR}/.cache"
APOLLO_DIR="${CACHE_ROOT_DIR}/apollo_release/apollo"

if [ ! -d "${APOLLO_DIR}" ]; then
echo "Release directory does not exist!"
Expand All @@ -102,7 +102,7 @@ function gen_docker() {
-d \
--name apollo_release \
--net host \
-v $HOME/.cache:/root/mnt \
-v ${CACHE_ROOT_DIR}:/root/mnt \
-w /apollo \
"$IMG"

Expand All @@ -112,16 +112,11 @@ function gen_docker() {
RELEASE_TGZ="apollo_release.tar.gz"
SEC_RELEASE_TGZ="sec_apollo_release.tar.gz"

if [ -e "$HOME/.cache/$RELEASE_TGZ" ]; then
rm $HOME/.cache/$RELEASE_TGZ
fi

if [ -e "$HOME/.cache/$SEC_RELEASE_TGZ" ]; then
rm $HOME/.cache/$SEC_RELEASE_TGZ
fi
[ -e "${CACHE_ROOT_DIR}/${RELEASE_TGZ}" ] && rm -f "${CACHE_ROOT_DIR}/${RELEASE_TGZ}"
[ -e "${CACHE_ROOT_DIR}/${SEC_RELEASE_TGZ}" ] && rm -f "${CACHE_ROOT_DIR}/${SEC_RELEASE_TGZ}"

# generate security release package
tar czf $HOME/.cache/$RELEASE_TGZ -C $HOME/.cache apollo_release
tar czf "${CACHE_ROOT_DIR}/${RELEASE_TGZ}" -C "${CACHE_ROOT_DIR}" apollo_release
python modules/tools/ota/create_sec_package.py
docker exec apollo_release cp /root/mnt/${SEC_RELEASE_TGZ} /root
fi
Expand Down Expand Up @@ -162,6 +157,7 @@ case $1 in
gen_docker
;;
*)
# TODO(storypku): fix user account issue
docker exec -u $USER apollo_dev_$USER bash -c "./apollo.sh $@"
;;
esac
12 changes: 5 additions & 7 deletions docker/scripts/cyber_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd -P)"
CACHE_ROOT_DIR="${APOLLO_ROOT_DIR}/.cache"

INCHINA="no"
LOCAL_IMAGE="no"
Expand Down Expand Up @@ -86,7 +88,6 @@ do
done
}

APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"

if [ ! -e /apollo ]; then
sudo ln -sf ${APOLLO_ROOT_DIR} /apollo
Expand Down Expand Up @@ -160,8 +161,7 @@ IMG=${DOCKER_REPO}:$VERSION

function local_volumes() {
# Apollo root and bazel cache dirs are required.
volumes="-v $APOLLO_ROOT_DIR:/apollo \
-v $HOME/.cache:${DOCKER_HOME}/.cache"
volumes="-v $APOLLO_ROOT_DIR:/apollo"
case "$(uname -s)" in
Linux)
case "$(lsb_release -r | cut -f2)" in
Expand All @@ -179,8 +179,6 @@ function local_volumes() {
-v /lib/modules:/lib/modules"
;;
Darwin)
# MacOS has strict limitations on mapping volumes.
chmod -R a+wr ~/.cache/bazel
;;
esac
echo "${volumes}"
Expand Down Expand Up @@ -223,8 +221,8 @@ function main(){
if [ "$USER" == "root" ];then
DOCKER_HOME="/root"
fi
if [ ! -d "$HOME/.cache" ];then
mkdir "$HOME/.cache"
if [ ! -d "${CACHE_ROOT_DIR}" ]; then
mkdir "${CACHE_ROOT_DIR}"
fi

info "Starting docker container \"${APOLLO_CYBER}\" ..."
Expand Down
16 changes: 8 additions & 8 deletions docker/scripts/dev_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# limitations under the License.
###############################################################################

APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
CACHE_ROOT_DIR="${APOLLO_ROOT_DIR}/.cache"

LOCAL_IMAGE="no"
FAST_BUILD_MODE="no"
FAST_TEST_MODE="no"
Expand Down Expand Up @@ -85,14 +88,14 @@ do
fi
done
}

function set_registry_mirrors()
{
sed -i '$aDOCKER_OPTS=\"--registry-mirror=http://hub-mirror.c.163.com\"' /etc/default/docker
sed -i '$i ,"registry-mirrors": [ "http://hub-mirror.c.163.com"]' /etc/docker/daemon.json
service docker restart

}
APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd -P )"

if [ "$(readlink -f /apollo)" != "${APOLLO_ROOT_DIR}" ]; then
sudo ln -snf ${APOLLO_ROOT_DIR} /apollo
Expand Down Expand Up @@ -207,8 +210,7 @@ LOCAL_THIRD_PARTY_VOLUME_IMAGE=${DOCKER_REPO}:local_third_party_volume-${ARCH}-l
function local_volumes() {
set +x
# Apollo root and bazel cache dirs are required.
volumes="-v $APOLLO_ROOT_DIR:/apollo \
-v $HOME/.cache:${DOCKER_HOME}/.cache"
volumes="-v $APOLLO_ROOT_DIR:/apollo"
APOLLO_TELEOP="${APOLLO_ROOT_DIR}/../apollo-teleop"
if [ -d ${APOLLO_TELEOP} ]; then
volumes="-v ${APOLLO_TELEOP}:/apollo/modules/teleop ${volumes}"
Expand All @@ -231,8 +233,6 @@ function local_volumes() {
-v /lib/modules:/lib/modules"
;;
Darwin)
# MacOS has strict limitations on mapping volumes.
chmod -R a+wr ~/.cache/bazel
;;
esac
echo "${volumes}"
Expand Down Expand Up @@ -280,7 +280,7 @@ function main(){
if [ $? == 0 ]; then
if [[ "$(docker inspect --format='{{.Config.Image}}' $APOLLO_DEV 2> /dev/null)" != "$APOLLO_DEV_IMAGE" ]]; then
rm -rf $APOLLO_ROOT_DIR/bazel-*
rm -rf $HOME/.cache/bazel/*
rm -rf ${CACHE_ROOT_DIR}/bazel/*
fi
docker stop $APOLLO_DEV 1>/dev/null
docker rm -v -f $APOLLO_DEV 1>/dev/null
Expand Down Expand Up @@ -350,8 +350,8 @@ function main(){
if [ "$USER" == "root" ];then
DOCKER_HOME="/root"
fi
if [ ! -d "$HOME/.cache" ];then
mkdir "$HOME/.cache"
if [ ! -d "${CACHE_ROOT_DIR}" ]; then
mkdir "${CACHE_ROOT_DIR}"
fi

info "Starting docker container \"${APOLLO_DEV}\" ..."
Expand Down
7 changes: 4 additions & 3 deletions docker/scripts/release_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@


APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")/../.." && pwd )"
CACHE_ROOT_DIR="${APOLLO_ROOT_DIR}/.cache"

# the machine type, currently support x86_64, aarch64
MACHINE_ARCH=$(uname -m)

Expand Down Expand Up @@ -80,8 +82,8 @@ function main() {
if [ "$USER" == "root" ];then
DOCKER_HOME="/root"
fi
if [ ! -d "$HOME/.cache" ];then
mkdir "$HOME/.cache"
if [ ! -d "${CACHE_ROOT_DIR}" ]; then
mkdir "${CACHE_ROOT_DIR}"
fi

DOCKER_CMD="nvidia-docker"
Expand All @@ -96,7 +98,6 @@ function main() {
-v ${HOME}/data:/apollo/data \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-v /etc/localtime:/etc/localtime:ro \
-v $HOME/.cache:${DOCKER_HOME}/.cache \
-w /apollo \
-e DISPLAY=${display} \
-e RELEASE_DOCKER=1 \
Expand Down
23 changes: 11 additions & 12 deletions scripts/ota.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
###############################################################################

APOLLO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
CACHE_DIR="${APOLLO_ROOT}/.cache"

function update() {
UPDATE_TAG=$(python ${APOLLO_ROOT}/modules/tools/ota/query_client.py)
Expand All @@ -31,28 +32,26 @@ function update() {
if [ "$user_agreed" != "y" ] && [ "$user_agreed" != "Y" ]; then
exit 1
fi
cp ${APOLLO_ROOT}/scripts/ota.sh /home/$DOCKER_USER/.cache/
ssh $DOCKER_USER@localhost bash /home/$DOCKER_USER/.cache/ota.sh download $UPDATE_TAG
cp ${APOLLO_ROOT}/scripts/ota.sh "${CACHE_DIR}"
ssh $DOCKER_USER@localhost bash ${CACHE_DIR}/ota.sh download $UPDATE_TAG
python ${APOLLO_ROOT}/modules/tools/ota/verify_client.py
if [ "$?" != "0" ]; then
exit 1
fi

if [ -e "$HOME/.cache/apollo_release" ]; then
rm -rf "$HOME/.cache/apollo_release"
fi
tar xzf /home/$DOCKER_USER/.cache/apollo_release.tar.gz -C /home/$DOCKER_USER/.cache
[ -e "${CACHE_DIR}/apollo_release" ] && rm -rf "${CACHE_DIR}/apollo_release"
tar xzf ${CACHE_DIR}/apollo_release.tar.gz -C ${CACHE_DIR}
NEW_TAG="${UPDATE_TAG}-local"

ssh $DOCKER_USER@localhost bash /home/$DOCKER_USER/.cache/ota.sh setup $NEW_TAG
ssh $DOCKER_USER@localhost bash ${CACHE_DIR}/ota.sh setup $NEW_TAG
python ${APOLLO_ROOT}/modules/tools/ota/update_client.py ${UPDATE_TAG}
}

function clean() {
rm -rf $HOME/.cache/apollo_update
rm -rf $HOME/.cache/apollo_release.tar.gz
rm -rf $HOME/.cache/sec_apollo_release.tar.gz
rm -rf $HOME/.cache/ota.sh
rm -rf ${CACHE_DIR}/apollo_update
rm -rf ${CACHE_DIR}/apollo_release.tar.gz
rm -rf ${CACHE_DIR}/sec_apollo_release.tar.gz
rm -rf ${CACHE_DIR}/ota.sh
docker stop test_container 1>/dev/null
docker rm test_container 1>/dev/null
}
Expand All @@ -78,7 +77,7 @@ function download() {
docker stop test_container 1>/dev/null
docker rm -f test_container 1>/dev/null
fi
docker run -d -it --name test_container -v $HOME/.cache:/root/mnt $UPDATE_TAG
docker run -d -it --name test_container -v ${CACHE_DIR}:/root/mnt $UPDATE_TAG
docker exec test_container cp /root/sec_apollo_release.tar.gz /root/mnt
}

Expand Down
1 change: 1 addition & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ startup --batch_cpu_scheduling

startup --host_jvm_args=-XX:-UseParallelGC

startup --output_user_root=/apollo/.cache/bazel
# +------------------------------------------------------------+
# | Test Configurations |
# +------------------------------------------------------------+
Expand Down

0 comments on commit 2314d77

Please sign in to comment.