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
|
2024-01-26 00:43:46 +08:00
|
|
|
PROFILE="--profile Jenkins-CVC"
|
|
|
|
ENDPOINT="--endpoint-url=https://s3.us-east-005.backblazeb2.com/"
|
|
|
|
TEST=false
|
|
|
|
|
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
|
|
|
|
2024-01-26 00:43:46 +08:00
|
|
|
OPTS=`getopt -o h --long help,replace-latest,docker-push,dry-run,test -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
|
2024-01-26 00:43:46 +08:00
|
|
|
--test )
|
|
|
|
TEST=true
|
|
|
|
shift ;;
|
2019-05-03 01:58:03 +08:00
|
|
|
--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}
|
2023-04-14 14:41:52 +08:00
|
|
|
LATEST_PACKAGE2=AdditionalMaps_${REPOSITORY_TAG}.tar.gz
|
|
|
|
LATEST_PACKAGE_PATH2=${CARLA_DIST_FOLDER}/${LATEST_PACKAGE2}
|
2019-05-03 01:58:03 +08:00
|
|
|
|
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
|
2023-04-14 14:41:52 +08:00
|
|
|
LATEST_DEPLOY_URI2=${S3_PREFIX}/Dev/AdditionalMaps_Latest.tar.gz
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
if [[ ${REPOSITORY_TAG} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
|
|
log "Detected tag ${REPOSITORY_TAG}."
|
|
|
|
DEPLOY_NAME=CARLA_${REPOSITORY_TAG}.tar.gz
|
2023-04-14 14:41:52 +08:00
|
|
|
DEPLOY_NAME2=AdditionalMaps_${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
|
2023-04-14 14:41:52 +08:00
|
|
|
DEPLOY_NAME2=AdditionalMaps_${REPOSITORY_TAG}.tar.gz
|
2020-10-01 02:22:25 +08:00
|
|
|
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
|
2023-04-14 14:41:52 +08:00
|
|
|
DEPLOY_NAME2=AdditionalMaps_$(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}."
|
2023-04-14 14:41:52 +08:00
|
|
|
log "Using package ${LATEST_PACKAGE2} as ${DEPLOY_NAME2}."
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
if [ ! -f ${LATEST_PACKAGE_PATH} ]; then
|
|
|
|
fatal_error "Latest package not found, please run 'make package'."
|
|
|
|
fi
|
|
|
|
|
2024-01-26 00:43:46 +08:00
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- TEST --------------------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
if ${TEST} ; then
|
|
|
|
LATEST_PACKAGE=test_CARLA_${REPOSITORY_TAG}.tar.gz
|
|
|
|
LATEST_PACKAGE_PATH=./${LATEST_PACKAGE}
|
|
|
|
LATEST_PACKAGE2=test_AdditionalMaps_${REPOSITORY_TAG}.tar.gz
|
|
|
|
LATEST_PACKAGE_PATH2=./${LATEST_PACKAGE2}
|
|
|
|
|
|
|
|
DEPLOY_NAME=test_CARLA_${REPOSITORY_TAG}.tar.gz
|
|
|
|
DEPLOY_NAME2=test_AdditionalMaps_${REPOSITORY_TAG}.tar.gz
|
|
|
|
|
|
|
|
touch ${LATEST_PACKAGE}
|
|
|
|
touch ${LATEST_PACKAGE2}
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2019-05-03 01:58:03 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- Upload --------------------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
DEPLOY_URI=${S3_PREFIX}/${DEPLOY_NAME}
|
2023-04-14 14:41:52 +08:00
|
|
|
DEPLOY_URI2=${S3_PREFIX}/${DEPLOY_NAME2}
|
2019-05-03 01:58:03 +08:00
|
|
|
|
2024-01-26 00:43:46 +08:00
|
|
|
${AWS_COPY} ${LATEST_PACKAGE_PATH} ${DEPLOY_URI} ${ENDPOINT} ${PROFILE}
|
2019-05-03 01:58:03 +08:00
|
|
|
log "Latest build uploaded to ${DEPLOY_URI}."
|
|
|
|
|
2024-01-26 00:43:46 +08:00
|
|
|
${AWS_COPY} ${LATEST_PACKAGE_PATH2} ${DEPLOY_URI2} ${ENDPOINT} ${PROFILE}
|
2023-04-14 14:41:52 +08:00
|
|
|
log "Latest build uploaded to ${DEPLOY_URI2}."
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Replace Latest ------------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
2019-05-03 01:58:03 +08:00
|
|
|
if ${REPLACE_LATEST} ; then
|
|
|
|
|
2024-01-26 00:43:46 +08:00
|
|
|
${AWS_COPY} ${DEPLOY_URI} ${LATEST_DEPLOY_URI} ${ENDPOINT} ${PROFILE}
|
2019-05-03 01:58:03 +08:00
|
|
|
log "Latest build uploaded to ${LATEST_DEPLOY_URI}."
|
2023-04-14 14:41:52 +08:00
|
|
|
|
2024-01-26 00:43:46 +08:00
|
|
|
${AWS_COPY} ${DEPLOY_URI2} ${LATEST_DEPLOY_URI2} ${ENDPOINT} ${PROFILE}
|
2023-04-14 14:41:52 +08:00
|
|
|
log "Latest build uploaded to ${LATEST_DEPLOY_URI2}."
|
2019-05-03 01:58:03 +08:00
|
|
|
|
|
|
|
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!"
|