apollo_docker.sh 3.1 KB
Newer Older
D
Dong Li 已提交
1 2 3 4 5 6
#!/usr/bin/env bash


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${DIR}"

L
Lei Wang 已提交
7 8
# the machine type, currently support x86_64, aarch64
MACHINE_ARCH=$(uname -m)
D
Dong Li 已提交
9 10 11 12
source ${DIR}/scripts/apollo_base.sh

TIME=$(date  +%Y%m%d_%H%M)
if [ -z "${DOCKER_REPO}" ]; then
L
Lei Wang 已提交
13
    DOCKER_REPO=apolloauto/apollo
D
Dong Li 已提交
14 15 16
fi

function print_usage() {
L
Lei Wang 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  RED='\033[0;31m'
  BLUE='\033[0;34m'
  BOLD='\033[1m'
  NONE='\033[0m'

  echo -e "\n${RED}Usage${NONE}:
  .${BOLD}/apollo_docker.sh${NONE} [OPTION]"

  echo -e "\n${RED}Options${NONE}:
  ${BLUE}build${NONE}: run build only
  ${BLUE}build_opt${NONE}: build optimized binary for the code
  ${BLUE}build_gpu${NONE}: run build only with Caffe GPU mode support
  ${BLUE}build_opt_gpu${NONE}: build optimized binary with Caffe GPU mode support
  ${BLUE}build_fe${NONE}: compile frontend javascript code, this requires all the node_modules to be installed already
  ${BLUE}buildify${NONE}: fix style of BUILD files
  ${BLUE}check${NONE}: run build/lint/test, please make sure it passes before checking in new code
  ${BLUE}clean${NONE}: run Bazel clean
  ${BLUE}config${NONE}: run configurator tool
  ${BLUE}coverage${NONE}: generate test coverage report
  ${BLUE}doc${NONE}: generate doxygen document
  ${BLUE}lint${NONE}: run code style check
  ${BLUE}usage${NONE}: print this menu
  ${BLUE}release${NONE}: build release version
  ${BLUE}test${NONE}: run all unit tests
  ${BLUE}version${NONE}: display current commit and date
  ${BLUE}push${NONE}: pushes the images to Docker hub
  ${BLUE}gen${NONE}: release a docker release image
  "
D
Dong Li 已提交
45 46 47 48 49 50 51 52 53 54
}

function start_build_docker() {
  docker ps --format "{{.Names}}" | grep apollo_dev 1>/dev/null 2>&1
  if [ $? != 0 ]; then
    bash docker/scripts/dev_start.sh
  fi
}

function gen_docker() {
L
Lei Wang 已提交
55
  IMG="apolloauto/apollo:run-${MACHINE_ARCH}-20171211_1820"
D
Dong Li 已提交
56
  RELEASE_DIR=${HOME}/.cache/release
L
Lei Wang 已提交
57 58
  RELEASE_NAME="${DOCKER_REPO}:release-${MACHINE_ARCH}-${TIME}"
  DEFAULT_NAME="${DOCKER_REPO}:release-${MACHINE_ARCH}-latest"
D
Dong Li 已提交
59
  docker pull $IMG
L
Lei Wang 已提交
60
  echo "time : ${TIME}" >> ${RELEASE_DIR}/meta.ini
D
Dong Li 已提交
61

L
Lei Wang 已提交
62 63 64 65 66
  docker ps -a --format "{{.Names}}" | grep 'apollo_release' 1>/dev/null
  if [ $? == 0 ];then
    docker stop apollo_release 1>/dev/null
    docker rm -f apollo_release 1>/dev/null
  fi
D
Dong Li 已提交
67 68 69 70 71 72 73 74
  docker run -it \
      -d \
      --name apollo_release \
      --net host \
      -v "$RELEASE_DIR:/root/mnt" \
      -w /apollo \
      "$IMG"

L
Lei Wang 已提交
75
  docker exec apollo_release bash -c "cp -Lr /root/mnt/* ."
D
Dong Li 已提交
76 77 78 79 80 81 82
  CONTAINER_ID=$(docker ps | grep apollo_release | awk '{print $1}')
  docker commit "$CONTAINER_ID" "$RELEASE_NAME"
  docker commit "$CONTAINER_ID" "$DEFAULT_NAME"
  docker stop "$CONTAINER_ID"
}

function push() {
L
Lei Wang 已提交
83 84
  local DEFAULT_NAME="${DOCKER_REPO}:release-${MACHINE_ARCH}-latest"
  local RELEASE_NAME="${DOCKER_REPO}:release-${MACHINE_ARCH}-${TIME}"
D
Dong Li 已提交
85 86 87 88 89
  docker tag "$DEFAULT_NAME" "$RELEASE_NAME"
  docker push "$DEFAULT_NAME"
  docker push "$RELEASE_NAME"
}

L
Lei Wang 已提交
90
if [ $# == 0 ];then
D
Dong Li 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    print_usage
    exit 1
fi

start_build_docker

case $1 in
  print_usage)
    print_usage
    ;;
  push)
    push
    ;;
  gen)
    gen_docker
    ;;
  *)
L
Lei Wang 已提交
108
    docker exec -u $USER apollo_dev bash -c "./apollo.sh $@"
D
Dong Li 已提交
109 110
    ;;
esac