Skip to content

Instantly share code, notes, and snippets.

@osowski
Last active September 23, 2015 18:59
Show Gist options
  • Save osowski/8dca076ac07b5069aabe to your computer and use it in GitHub Desktop.
Save osowski/8dca076ac07b5069aabe to your computer and use it in GitHub Desktop.
IBM Bluemix DevOps Services build scripts for Let's Chat Docker images. Based off the default scripts provided by the service, these have had most comments removed for clarity.
#!/bin/bash
log_and_echo "$LABEL" "Starting build script"
cd ${WORKSPACE}/lets-chat
if [ -f Dockerfile ]; then
log_and_echo "$LABEL" "Building ${FULL_REPOSITORY_NAME}"
${EXT_DIR}/utilities/sendMessage.sh -l info -m "New container build requested for ${FULL_REPOSITORY_NAME}"
# build image
BUILD_COMMAND=""
if [ "${USE_CACHED_LAYERS}" == "true" ]; then
BUILD_COMMAND="build --pull --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}/lets-chat"
ice_retry ${BUILD_COMMAND}
RESULT=$?
else
BUILD_COMMAND="build --no-cache --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}/lets-chat"
ice_retry ${BUILD_COMMAND}
RESULT=$?
fi
if [ $RESULT -ne 0 ]; then
log_and_echo "$ERROR" "Error building image"
ice info
ice images
${EXT_DIR}/print_help.sh
${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Container build of ${FULL_REPOSITORY_NAME} failed. $(get_error_info)"
exit 1
else
log_and_echo "$SUCCESSFUL" "Container build of ${FULL_REPOSITORY_NAME} was successful"
${EXT_DIR}/utilities/sendMessage.sh -l good -m "Container build of ${FULL_REPOSITORY_NAME} was successful"
fi
else
log_and_echo "$ERROR" "Dockerfile not found in project"
${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Failed to get Dockerfile. $(get_error_info)"
exit 1
fi
######################################################################################
# Copy any artifacts that will be needed for deployment and testing to $WORKSPACE #
######################################################################################
echo "IMAGE_NAME=${FULL_REPOSITORY_NAME}" >> $ARCHIVE_DIR/build.properties
#!/bin/bash
echo -e "${label_color}Starting deployment script${no_color}"
# Forked script to allow for singleton containers without Public IPs bound.
git_retry clone https://github.com/osowski/deployscripts.git deployscripts
/bin/bash deployscripts/deploycontainer.sh
RESULT=$?
# source the deploy property file
if [ -f "${DEPLOY_PROPERTY_FILE}" ]; then
source "$DEPLOY_PROPERTY_FILE"
fi
if [ $RESULT -ne 0 ]; then
echo -e "${red}Executed failed or had warnings ${no_color}"
${EXT_DIR}/print_help.sh
exit $RESULT
fi
echo -e "${green}Execution complete${no_label}"
#!/bin/bash
echo -e "${label_color}Starting deployment script${no_color}"
git_retry clone https://github.com/Osthanes/deployscripts.git deployscripts
/bin/bash deployscripts/deploycontainer.sh
RESULT=$?
# source the deploy property file
if [ -f "${DEPLOY_PROPERTY_FILE}" ]; then
source "$DEPLOY_PROPERTY_FILE"
fi
if [ $RESULT -ne 0 ]; then
echo -e "${red}Executed failed or had warnings ${no_color}"
${EXT_DIR}/print_help.sh
exit $RESULT
fi
echo -e "${green}Execution complete${no_label}"
#!/bin/bash
log_and_echo "$LABEL" "Starting build script"
cd ${WORKSPACE}/nginx
if [ -f Dockerfile ]; then
log_and_echo "$LABEL" "Building ${FULL_REPOSITORY_NAME}"
${EXT_DIR}/utilities/sendMessage.sh -l info -m "New container build requested for ${FULL_REPOSITORY_NAME}"
# build image
BUILD_COMMAND=""
if [ "${USE_CACHED_LAYERS}" == "true" ]; then
BUILD_COMMAND="build --pull --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}/nginx"
ice_retry ${BUILD_COMMAND}
RESULT=$?
else
BUILD_COMMAND="build --no-cache --tag ${FULL_REPOSITORY_NAME} ${WORKSPACE}/nginx"
ice_retry ${BUILD_COMMAND}
RESULT=$?
fi
if [ $RESULT -ne 0 ]; then
log_and_echo "$ERROR" "Error building image"
ice info
ice images
${EXT_DIR}/print_help.sh
${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Container build of ${FULL_REPOSITORY_NAME} failed. $(get_error_info)"
exit 1
else
log_and_echo "$SUCCESSFUL" "Container build of ${FULL_REPOSITORY_NAME} was successful"
${EXT_DIR}/utilities/sendMessage.sh -l good -m "Container build of ${FULL_REPOSITORY_NAME} was successful"
fi
else
log_and_echo "$ERROR" "Dockerfile not found in project"
${EXT_DIR}/utilities/sendMessage.sh -l bad -m "Failed to get Dockerfile. $(get_error_info)"
exit 1
fi
######################################################################################
# Copy any artifacts that will be needed for deployment and testing to $WORKSPACE #
######################################################################################
echo "IMAGE_NAME=${FULL_REPOSITORY_NAME}" >> $ARCHIVE_DIR/build.properties
#!/bin/bash
echo -e "${label_color}Starting deployment script${no_color}"
git_retry clone https://github.com/Osthanes/deployscripts.git deployscripts
CIDS=`ice ps | grep lets-chat-bmx | awk '{print $1}'`
export CONTAINER_A=`echo ${CIDS} | awk '{print $1}'`
export CONTAINER_B=`echo ${CIDS} | awk '{print $2}'`
echo "Container A has an ID of ${CONTAINER_A}"
echo "Container B has an ID of ${CONTAINER_B}"
# ${OPTIONAL_ARGS} is equal to "--link __CIDSA__:lets-chat-1 --link __CIDSB__:lets-chat-2"
# to be lazily replaced with the values pulled above from the running container IDs
export OPTIONAL_ARGS=`echo ${OPTIONAL_ARGS} | sed 's/__CIDSA__/'"${CONTAINER_A}"'/' | sed 's/__CIDSB__/'"${CONTAINER_B}"'/'`
echo "Optional Args:" ${OPTIONAL_ARGS}
# Deploy with containers:
/bin/bash deployscripts/deploycontainer.sh
RESULT=$?
# source the deploy property file
if [ -f "${DEPLOY_PROPERTY_FILE}" ]; then
source "$DEPLOY_PROPERTY_FILE"
fi
# The following colors have been defined to help with presentation of logs: green, red, label_color, no_color.
if [ $RESULT -ne 0 ]; then
echo -e "${red}Executed failed or had warnings ${no_color}"
${EXT_DIR}/print_help.sh
exit $RESULT
fi
echo -e "${green}Execution complete${no_label}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment