[cmd_deploy][cmd_update][parser] Added --from option to define OLD_COMMIT
[parser] --git-dir option now expects no = in front of it
This commit is contained in:
parent
5d199f8315
commit
cfd00e3e2d
3 changed files with 43 additions and 18 deletions
|
@ -6,13 +6,14 @@
|
|||
# cmd_deploy - Command that deploys IMAGEIDs using deploy_imageid function
|
||||
#
|
||||
# USAGE
|
||||
# cmd_deploy - </path/to/git/dir> </path/to/target>
|
||||
# cmd_deploy - </path/to/git/dir> </path/to/target> [<old git commit>]
|
||||
#
|
||||
# }
|
||||
|
||||
cmd_deploy() {
|
||||
local GIT_DIR="${1}"
|
||||
local TARGET="${2}"; shift 2
|
||||
local TARGET="${2}"
|
||||
local OLD_COMMIT="${3}"
|
||||
local ERR=false
|
||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||
|
@ -23,7 +24,7 @@ cmd_deploy() {
|
|||
fi
|
||||
|
||||
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
|
||||
local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_DEPLOY"){print $2}}' ${DB_FILE})
|
||||
[[ -z "${OLD_COMMIT}" ]] && local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_DEPLOY"){print $2}}' ${DB_FILE})
|
||||
local removableidList=($(awk 'BEGIN{FS="\t"}{if(($1=="null" || $1=="false") && $4!="null"){print $2"--"$3}}' "${DB_FILE}"))
|
||||
local deployableidList=($(awk 'BEGIN{FS="\t"}{if($1=="true" && $4=="null"){print $2}}' "${DB_FILE}" | awk '!seen[$0]++'))
|
||||
local changedidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
# cmd_update - Updates database of TARGET from git HEAD to last commit hash.
|
||||
#
|
||||
# USAGE
|
||||
# cmd_update </path/to/git/dir> </path/to/target/dir>
|
||||
# cmd_update </path/to/git/dir> </path/to/target/dir> [<old git commit>]
|
||||
#
|
||||
# }
|
||||
|
||||
cmd_update() {
|
||||
local GIT_DIR="${1}"
|
||||
local TARGET="${2}"
|
||||
local OLD_COMMIT="${3}"
|
||||
local DB_FILE="${TARGET}/${_OPT_DB_FILE}"
|
||||
[[ ! -f "${DB_FILE}" ]] && return 3
|
||||
[[ ! -d "${GIT_DIR}/.git" ]] && return 2
|
||||
|
@ -26,7 +27,7 @@ cmd_update() {
|
|||
# Defines what imageids needs updating by determining what files has changed since last
|
||||
# update via git diff --name-only.
|
||||
local NEW_COMMIT=$(git -C "${GIT_DIR}" rev-parse HEAD)
|
||||
local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_UPDATE"){print $2}}' ${DB_FILE})
|
||||
[[ -z "${OLD_COMMIT}" ]] && local OLD_COMMIT=$(awk 'BEGIN{FS="\t"}{if($1=="LAST_UPDATE"){print $2}}' ${DB_FILE})
|
||||
local imageidList=($(sed 's/\(.*\)\..*/\1/' <<< $(git -C "${GIT_DIR}" diff --name-only ${NEW_COMMIT} ${OLD_COMMIT}) | awk '!seen[$0]++' | grep SHA256))
|
||||
|
||||
local COUNT=1
|
||||
|
|
49
src/parser
49
src/parser
|
@ -7,7 +7,7 @@
|
|||
GIT_DIR="./"
|
||||
|
||||
#Recursive argument parser
|
||||
while true; do
|
||||
while [[ -z "${1}" ]]; do
|
||||
case ${1} in
|
||||
--help)
|
||||
shift
|
||||
|
@ -23,17 +23,11 @@ while true; do
|
|||
;;
|
||||
|
||||
|
||||
--git-dir=*)
|
||||
if [ -z "${1#*=}" ]; then
|
||||
help
|
||||
else
|
||||
GIT_DIR="${1#*=}"
|
||||
fi
|
||||
|
||||
--git-dir)
|
||||
shift
|
||||
GIT_DIR="${1}"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
shift
|
||||
|
@ -60,7 +54,21 @@ case "${1}" in
|
|||
|
||||
deploy)
|
||||
shift
|
||||
cmd_deploy "${GIT_DIR}" ${@}
|
||||
while [[ -n "${1}" ]]; do
|
||||
case ${1} in
|
||||
--from)
|
||||
shift
|
||||
OLD_COMMIT=${1}
|
||||
shift
|
||||
;;
|
||||
|
||||
*)
|
||||
TARGET="${1}"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
cmd_deploy "${GIT_DIR}" "${TARGET}" "${OLD_COMMIT}"
|
||||
EXIT=$?
|
||||
[[ ${EXIT} -eq 0 ]] && echo "Deployment completed successfully"
|
||||
[[ ${EXIT} -eq 1 ]] && echo "Deployment completed with errors"
|
||||
|
@ -70,7 +78,22 @@ case "${1}" in
|
|||
|
||||
update)
|
||||
shift
|
||||
cmd_update "${GIT_DIR}" ${@}
|
||||
while [[ -n "${1}" ]]; do
|
||||
case ${1} in
|
||||
--from)
|
||||
shift
|
||||
OLD_COMMIT=${1}
|
||||
shift
|
||||
;;
|
||||
|
||||
*)
|
||||
TARGET="${1}"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
cmd_update "${GIT_DIR}" "${TATGET}" "${OLD_COMMIT}"
|
||||
EXIT=$?
|
||||
[[ ${EXIT} -eq 0 ]] && echo "Update completed successfully"
|
||||
[[ ${EXIT} -eq 1 ]] && echo "Update completed with errors"
|
||||
|
|
Loading…
Reference in a new issue