2019-05-03 01:58:03 +08:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Set up environment --------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
2020-12-17 17:53:03 +08:00
|
|
|
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
REPLACE_LATEST=false
|
2019-06-18 22:14:18 +08:00
|
|
|
DOCKER_PUSH=false
|
2019-05-03 01:58:03 +08:00
|
|
|
AWS_COPY="aws s3 cp"
|
2019-07-10 04:48:58 +08:00
|
|
|
DOCKER="docker"
|
|
|
|
UNTAR="tar -xvzf"
|
2019-05-16 20:54:29 +08:00
|
|
|
UPLOAD_MAPS=true
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Parse arguments -----------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
DOC_STRING="Upload latest build to S3."
|
|
|
|
|
2019-06-18 22:14:18 +08:00
|
|
|
USAGE_STRING="Usage: $0 [-h|--help] [--replace-latest] [--docker-push] [--dry-run]"
|
2019-05-03 01:58:03 +08:00
|
|
|
|
2019-06-18 22:14:18 +08:00
|
|
|
OPTS=`getopt -o h --long help,replace-latest,docker-push,dry-run -n 'parse-options' -- "$@"`
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
2020-10-01 22:35:12 +08:00
|
|
|
while [[ $# -gt 0 ]]; do
|
2019-05-03 01:58:03 +08:00
|
|
|
case "$1" in
|
|
|
|
--replace-latest )
|
|
|
|
REPLACE_LATEST=true;
|
|
|
|
shift ;;
|
2019-06-18 22:14:18 +08:00
|
|
|
--docker-push )
|
|
|
|
DOCKER_PUSH=true;
|
|
|
|
shift ;;
|
2019-05-03 01:58:03 +08:00
|
|
|
--dry-run )
|
|
|
|
AWS_COPY="echo ${AWS_COPY}";
|
2019-07-10 04:48:58 +08:00
|
|
|
DOCKER="echo ${DOCKER}";
|
|
|
|
UNTAR="echo ${UNTAR}";
|
2019-05-03 01:58:03 +08:00
|
|
|
shift ;;
|
|
|
|
-h | --help )
|
|
|
|
echo "$DOC_STRING"
|
|
|
|
echo "$USAGE_STRING"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
* )
|
2020-09-30 22:57:53 +08:00
|
|
|
shift ;;
|
2019-05-03 01:58:03 +08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-12-17 17:53:03 +08:00
|
|
|
source $(dirname "$0")/Environment.sh
|
|
|
|
|
2019-05-03 01:58:03 +08:00
|
|
|
REPOSITORY_TAG=$(get_git_repository_version)
|
|
|
|
|
|
|
|
LATEST_PACKAGE=CARLA_${REPOSITORY_TAG}.tar.gz
|
|
|
|
LATEST_PACKAGE_PATH=${CARLA_DIST_FOLDER}/${LATEST_PACKAGE}
|
|
|
|
|
2020-03-05 20:16:18 +08:00
|
|
|
S3_PREFIX=s3://carla-releases/Linux
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
LATEST_DEPLOY_URI=${S3_PREFIX}/Dev/CARLA_Latest.tar.gz
|
|
|
|
|
|
|
|
if [[ ${REPOSITORY_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
|
|
log "Detected tag ${REPOSITORY_TAG}."
|
|
|
|
DEPLOY_NAME=CARLA_${REPOSITORY_TAG}.tar.gz
|
2019-06-18 22:14:18 +08:00
|
|
|
DOCKER_TAG=${REPOSITORY_TAG}
|
2020-10-01 02:22:25 +08:00
|
|
|
elif [[ ${REPOSITORY_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
|
|
log "Detected tag ${REPOSITORY_TAG}."
|
|
|
|
DEPLOY_NAME=CARLA_${REPOSITORY_TAG}.tar.gz
|
|
|
|
DOCKER_TAG=${REPOSITORY_TAG}
|
2019-05-03 01:58:03 +08:00
|
|
|
else
|
|
|
|
S3_PREFIX=${S3_PREFIX}/Dev
|
|
|
|
DEPLOY_NAME=$(git log --pretty=format:'%cd_%h' --date=format:'%Y%m%d' -n 1).tar.gz
|
2019-06-18 22:14:18 +08:00
|
|
|
DOCKER_TAG=latest
|
2019-05-03 01:58:03 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
log "Using package ${LATEST_PACKAGE} as ${DEPLOY_NAME}."
|
|
|
|
|
|
|
|
if [ ! -f ${LATEST_PACKAGE_PATH} ]; then
|
|
|
|
fatal_error "Latest package not found, please run 'make package'."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Upload --------------------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
DEPLOY_URI=${S3_PREFIX}/${DEPLOY_NAME}
|
|
|
|
|
|
|
|
${AWS_COPY} ${LATEST_PACKAGE_PATH} ${DEPLOY_URI}
|
|
|
|
|
|
|
|
log "Latest build uploaded to ${DEPLOY_URI}."
|
|
|
|
|
|
|
|
if ${REPLACE_LATEST} ; then
|
|
|
|
|
|
|
|
${AWS_COPY} ${DEPLOY_URI} ${LATEST_DEPLOY_URI}
|
|
|
|
|
|
|
|
log "Latest build uploaded to ${LATEST_DEPLOY_URI}."
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ${UPLOAD_MAPS} ; then
|
|
|
|
|
2019-07-10 04:50:55 +08:00
|
|
|
mkdir -p ${CARLA_DIST_FOLDER}
|
2019-05-03 01:58:03 +08:00
|
|
|
|
2019-07-10 04:50:55 +08:00
|
|
|
pushd "${CARLA_DIST_FOLDER}" >/dev/null
|
2019-05-03 01:58:03 +08:00
|
|
|
|
2019-07-10 04:50:55 +08:00
|
|
|
for MAP_PACKAGE in *_${REPOSITORY_TAG}.tar.gz ; do if [[ ${MAP_PACKAGE} != ${LATEST_PACKAGE} ]] ; then
|
|
|
|
|
|
|
|
DEPLOY_MAP_URI=${S3_PREFIX}/${MAP_PACKAGE}
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
${AWS_COPY} ${MAP_PACKAGE} ${DEPLOY_MAP_URI}
|
|
|
|
|
|
|
|
log "${MAP_PACKAGE} uploaded to ${DEPLOY_MAP_URI}."
|
|
|
|
|
2019-07-10 04:50:55 +08:00
|
|
|
fi ; done
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2019-06-18 22:14:18 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- Docker build and push -----------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
if ${DOCKER_PUSH} ; then
|
|
|
|
|
|
|
|
DOCKER_BUILD_FOLDER=${CARLA_BUILD_FOLDER}/${REPOSITORY_TAG}.Docker
|
|
|
|
DOCKER_NAME=carlasim/carla:${DOCKER_TAG}
|
|
|
|
|
|
|
|
mkdir -p ${DOCKER_BUILD_FOLDER}
|
|
|
|
|
2019-07-10 04:48:58 +08:00
|
|
|
${UNTAR} ${LATEST_PACKAGE_PATH} -C ${DOCKER_BUILD_FOLDER}/
|
2019-06-18 22:14:18 +08:00
|
|
|
|
|
|
|
pushd "${DOCKER_BUILD_FOLDER}" >/dev/null
|
|
|
|
|
|
|
|
log "Building Docker image ${DOCKER_NAME}."
|
|
|
|
|
2019-07-10 04:48:58 +08:00
|
|
|
${DOCKER} build -t ${DOCKER_NAME} -f Dockerfile .
|
2019-06-18 22:14:18 +08:00
|
|
|
|
|
|
|
log "Pushing Docker image."
|
|
|
|
|
2019-07-10 04:48:58 +08:00
|
|
|
${DOCKER} push ${DOCKER_NAME}
|
2019-06-18 22:14:18 +08:00
|
|
|
|
|
|
|
popd >/dev/null
|
|
|
|
|
|
|
|
fi;
|
|
|
|
|
2019-05-03 01:58:03 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- ...and we are done --------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
log "Success!"
|