Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 3d3fd3d

Browse files
committed
New: Add mdline command and use tags instead latest
1 parent 62a492f commit 3d3fd3d

1 file changed

Lines changed: 50 additions & 34 deletions

File tree

kd.sh

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function removeSentinel() {
2424
function assertCommandExist () {
2525
local search="$1"
2626
for command in ${commandList[*]}; do
27-
[[ "$command" == "$search" ]] && return 0
27+
[[ "$(echo $command|cut -f 1 -d ':')" == $search ]] && return 0
2828
done
2929
echo_err "The Docker Command '$search' does not exist. Aborting"
3030
echo_debug "end"
@@ -33,11 +33,12 @@ function assertCommandExist () {
3333

3434
# Initialize
3535
commandList=(
36-
commit-validator
37-
get-next-release-number
38-
git-changelog-generator
39-
hello-world
40-
md2html
36+
commit-validator:0.1.1
37+
get-next-release-number:1.0.2
38+
git-changelog-generator:0.7.4
39+
hello-world:0.2.1
40+
md2html:1.1.1
41+
mdline:0.1.0
4142
)
4243
imagePrefix="kairops/dc-"
4344
commandCacheSeconds=86400
@@ -65,21 +66,34 @@ Examples:
6566
6667
Available commands:
6768
"
68-
6969
for item in ${commandList[*]}; do
70-
echo "* $item"
70+
echo -n "* $(echo $item|cut -f 1 -d ':')"
71+
if [ "$KD_EDGE" == "1" ]; then
72+
echo " (latest)"
73+
else
74+
echo " v$(echo $item|cut -f 2 -d ':')"
75+
fi
7176
done
7277

7378
echo_err
74-
echo_err "You can set KD_DEBUG=1 with 'export KD_DEBUG=1' to enable verbose debug info"
79+
echo_err "Other options:
80+
- KD_DEBUG=1 to enable verbose debug info (``export KD_DEBUG=1``)
81+
- KD_EDGE=1 to use the latest release of the commands (``export KD_EDGE=1``)
82+
- KD_SENTINEL=1 to enable a 24h image cache sentinel (``export KD_SENTINEL=1``)
83+
"
7584
echo_debug "end"
7685
exit 0
7786
fi
7887

7988
# Command check
8089
command=$1
8190
assertCommandExist $command
82-
image=$imagePrefix$command:latest
91+
if [ "$KD_EDGE" == "1" ]; then
92+
command=$(echo $command|cut -f 1 -d ':')
93+
command=$(echo "$command:latest")
94+
echo $command
95+
fi
96+
image=$imagePrefix$command
8397
shift
8498

8599
# Parameter (file and folder) check
@@ -105,33 +119,35 @@ if [ "$mountFolder" != "" ]; then
105119
fi
106120

107121
# Update command cache
108-
sentinel=$(docker images ${imagePrefix}sentinel-*|awk 'NR>1 {print $1}')
109-
if [ "$sentinel" != "" ]; then
110-
# If more then one sentinel cache images exists, drop all
111-
if [ $(echo "$sentinel"|wc -l) -gt 1 ]; then
112-
removeSentinel "$sentinel"
113-
else
114-
# Check time elapsed since sentinel cache image creation
115-
sentinelTimestamp=$(echo $sentinel|awk -F '-' '{print $NF}')
116-
currentTimestamp=$(date +%s)
117-
echo_debug "Sentinel timestamp: $sentinelTimestamp"
118-
echo_debug "Current timesamp: $currentTimestamp"
119-
secondsElapsed=$((currentTimestamp - sentinelTimestamp))
120-
echo_debug "Seconds Elapsed: $secondsElapsed"
121-
if [ $secondsElapsed -gt $commandCacheSeconds ]; then
122+
if [ "$KD_SENTINEL" == "1" ]; then
123+
sentinel=$(docker images ${imagePrefix}sentinel-*|awk 'NR>1 {print $1}')
124+
if [ "$sentinel" != "" ]; then
125+
# If more then one sentinel cache images exists, drop all
126+
if [ $(echo "$sentinel"|wc -l) -gt 1 ]; then
122127
removeSentinel "$sentinel"
128+
else
129+
# Check time elapsed since sentinel cache image creation
130+
sentinelTimestamp=$(echo $sentinel|awk -F '-' '{print $NF}')
131+
currentTimestamp=$(date +%s)
132+
echo_debug "Sentinel timestamp: $sentinelTimestamp"
133+
echo_debug "Current timesamp: $currentTimestamp"
134+
secondsElapsed=$((currentTimestamp - sentinelTimestamp))
135+
echo_debug "Seconds Elapsed: $secondsElapsed"
136+
if [ $secondsElapsed -gt $commandCacheSeconds ]; then
137+
removeSentinel "$sentinel"
138+
fi
123139
fi
124140
fi
125-
fi
126-
if [ "$sentinel" == "" ]; then
127-
# Retrieve all command cache
128-
sentinelTimestamp=$(date +%s)
129-
echo_debug "Creating new sentinel image $sentinelTimestamp"
130-
echo -e "FROM alpine\nRUN echo $sentinelTimestamp > /.sentinel.lock" | docker build -t ${imagePrefix}sentinel-${sentinelTimestamp} - > /dev/null 2>&1
131-
for command in ${commandList[*]}; do
132-
echo_debug "Removing docker-command image for '$command'"
133-
docker rmi ${imagePrefix}$command > /dev/null 2>&1 || true
134-
done
141+
if [ "$sentinel" == "" ]; then
142+
# Retrieve all command cache
143+
sentinelTimestamp=$(date +%s)
144+
echo_debug "Creating new sentinel image $sentinelTimestamp"
145+
echo -e "FROM alpine\nRUN echo $sentinelTimestamp > /.sentinel.lock" | docker build -t ${imagePrefix}sentinel-${sentinelTimestamp} - > /dev/null 2>&1
146+
for command in ${commandList[*]}; do
147+
echo_debug "Removing docker-command image for '$command'"
148+
docker rmi ${imagePrefix}$command > /dev/null 2>&1 || true
149+
done
150+
fi
135151
fi
136152

137153
# Get image if not exist

0 commit comments

Comments
 (0)