1 changed files with 60 additions and 8 deletions
-
68build.sh
@ -1,17 +1,69 @@ |
|||||
#!/usr/bin/env bash |
#!/usr/bin/env bash |
||||
set -o errexit |
set -o errexit |
||||
|
|
||||
# Set the image name |
## PRE-RUN SETUP & CONFIGURATION |
||||
IMAGE_NAME="phlak/mumble" |
######################################## |
||||
|
|
||||
# Set script directory path |
|
||||
SCRIPT_DIR="$(dirname $(readlink -f ${0}))" |
SCRIPT_DIR="$(dirname $(readlink -f ${0}))" |
||||
|
|
||||
# Set image tag |
IMAGE_NAME="phlak/mumble" |
||||
TAG="$(grep 'ENV MUMBLE_VERSION' Dockerfile | awk '{print $3}')" |
TAG="$(grep 'ENV MUMBLE_VERSION' Dockerfile | awk '{print $3}')" |
||||
|
|
||||
# Build the image |
## SCRIPT USAGE |
||||
docker build --force-rm --pull --tag ${IMAGE_NAME}:${TAG} ${SCRIPT_DIR} |
######################################## |
||||
|
|
||||
|
function usageShort() { |
||||
|
echo "Usage: $(basename ${0}) [OPTIONS]" |
||||
|
} |
||||
|
|
||||
|
function usageLong() { |
||||
|
|
||||
|
usageShort |
||||
|
|
||||
|
cat <<-EOF |
||||
|
|
||||
|
OPTIONS: |
||||
|
|
||||
|
-h, --help Print this help dialogue |
||||
|
-p, --purge Purge the image after build |
||||
|
|
||||
|
EOF |
||||
|
|
||||
|
} |
||||
|
|
||||
|
## OPTION / PARAMATER PARSING |
||||
|
######################################## |
||||
|
|
||||
|
PARSED_OPTIONS=$(getopt -n "${0}" -o hp -l "help,purge" -- "$@") |
||||
|
|
||||
|
eval set -- "${PARSED_OPTIONS}" |
||||
|
|
||||
|
while true; do |
||||
|
case "${1}" in |
||||
|
-h|--help) usageLong; exit ;; |
||||
|
-p|--purge) PURGE=true; shift ;; |
||||
|
--) shift; break ;; |
||||
|
esac |
||||
|
done |
||||
|
|
||||
|
## SCRIPT FUNCTIONS |
||||
|
######################################## |
||||
|
|
||||
|
function buildImage() { |
||||
|
docker build --force-rm --pull --tag ${IMAGE_NAME}:${TAG} ${SCRIPT_DIR} |
||||
|
} |
||||
|
|
||||
|
function purgeImage() { |
||||
|
docker rmi --force ${IMAGE_NAME}:${TAG} |
||||
|
echo "Purged image: ${IMAGE_NAME}:${TAG}" |
||||
|
} |
||||
|
|
||||
|
function main() { |
||||
|
buildImage; [[ "${PURGE}" == true ]] && purgeImage |
||||
|
echo "Successfully built ${IMAGE_NAME}:${TAG}" |
||||
|
} |
||||
|
|
||||
|
# MAKE IT SO |
||||
|
######################################## |
||||
|
|
||||
# Notify user of success |
main |
||||
echo "Sucessfully created image: ${IMAGE_NAME}:${TAG}" |
|
Reference in new issue
xxxxxxxxxx