Skip to content

Commit f92e946

Browse files
author
Joshua Anderson
committed
test(registry): run shell scripts through shellcheck
1 parent 0d06570 commit f92e946

3 files changed

Lines changed: 29 additions & 27 deletions

File tree

registry/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ COMPONENT = registry
44
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
55
DEV_IMAGE = $(REGISTRY)$(IMAGE)
66

7+
SHELL_SCRIPTS = $(shell find "." -name '*.sh') $(wildcard bin/*)
8+
79
build: check-docker
810
docker build -t $(IMAGE) .
911

@@ -51,7 +53,7 @@ test-functional:
5153
GOPATH=`cd ../tests/ && godep path`:$(GOPATH) go test -v ./tests/...
5254

5355
test-style:
54-
@echo no style tests
56+
shellcheck $(SHELL_SCRIPTS)
5557

5658
test-unit:
5759
@echo no unit tests

registry/bin/boot

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,31 @@ set -eo pipefail
1010
[[ $DEBUG ]] && set -x
1111

1212
# configure etcd
13-
export ETCD_PORT=${ETCD_PORT:-4001}
13+
export ETCD_PORT="${ETCD_PORT:-4001}"
1414
export ETCD="$HOST:$ETCD_PORT"
15-
export ETCD_PATH=${ETCD_PATH:-/deis/registry}
16-
export HOST_ETCD_PATH=${HOST_ETCD_PATH:-/deis/registry/hosts/$HOST}
17-
export ETCD_TTL=${ETCD_TTL:-20}
15+
export ETCD_PATH="${ETCD_PATH:-/deis/registry}"
16+
export HOST_ETCD_PATH="${HOST_ETCD_PATH:-/deis/registry/hosts/$HOST}"
17+
export ETCD_TTL="${ETCD_TTL:-20}"
1818

1919
# run.sh requires $REGISTRY_PORT
20-
export REGISTRY_PORT=${PORT:-5000}
20+
export REGISTRY_PORT="${PORT:-5000}"
2121

22-
export BUCKET_NAME=${BUCKET_NAME:-registry}
22+
export BUCKET_NAME="${BUCKET_NAME:-registry}"
2323

2424
# wait for etcd to be available
25-
until etcdctl --no-sync -C $ETCD ls >/dev/null 2>&1; do
25+
until etcdctl --no-sync -C "$ETCD" ls >/dev/null 2>&1; do
2626
echo "waiting for etcd at $ETCD..."
27-
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
27+
sleep $((ETCD_TTL/2)) # sleep for half the TTL
2828
done
2929

3030
# wait until etcd has discarded potentially stale values
31-
sleep $(($ETCD_TTL+1))
31+
sleep $((ETCD_TTL+1))
3232

3333
function etcd_set_default {
3434
set +e
35-
ERROR="$(etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 2>&1 >/dev/null)"
36-
if [[ $? -ne 0 && $(echo $ERROR | grep -ive "key already exists") ]]; then
35+
ERROR="$(etcdctl --no-sync -C "$ETCD" mk "$ETCD_PATH/$1" "$2" 2>&1 >/dev/null)"
36+
37+
if [[ $? -ne 0 ]] && echo "$ERROR" | grep -iqve "key already exists"; then
3738
echo "etcd_set_default: an etcd error occurred ($ERROR)"
3839
echo "aborting..."
3940
exit 1
@@ -43,12 +44,12 @@ function etcd_set_default {
4344

4445
# seed initial service configuration if necessary
4546
etcd_set_default protocol http
46-
etcd_set_default bucketName ${BUCKET_NAME}
47+
etcd_set_default bucketName "${BUCKET_NAME}"
4748

4849
# wait for confd to run once and install initial templates
49-
until confd -onetime -node $ETCD --confdir /app --log-level error; do
50+
until confd -onetime -node "$ETCD" --confdir /app --log-level error; do
5051
echo "registry: waiting for confd to write initial templates..."
51-
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
52+
sleep $((ETCD_TTL/2)) # sleep for half the TTL
5253
done
5354

5455
# ensure registry bucket exists
@@ -68,8 +69,7 @@ function on_exit() {
6869
trap on_exit INT TERM
6970

7071
# spawn confd in the background to update services based on etcd changes
71-
confd -node $ETCD --confdir /app --log-level error --interval 5 &
72-
CONFD_PID=$!
72+
confd -node "$ETCD" --confdir /app --log-level error --interval 5 &
7373

7474
echo deis-registry running...
7575

@@ -87,16 +87,16 @@ if [[ ! -z $EXTERNAL_PORT ]]; then
8787

8888
# while the port is listening, publish to etcd
8989
while [[ ! -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PORT\" && \$1 ~ \"$PROTO.?\"") ]] ; do
90-
if etcdctl --no-sync -C $ETCD mk ${ETCD_PATH}/masterLock $HOSTNAME --ttl $ETCD_TTL >/dev/null 2>&1 \
91-
|| [[ `etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/masterLock` == "$HOSTNAME" ]] ; then
92-
etcdctl --no-sync -C $ETCD set $ETCD_PATH/host $HOST --ttl $ETCD_TTL >/dev/null
93-
etcdctl --no-sync -C $ETCD set $ETCD_PATH/port $EXTERNAL_PORT --ttl $ETCD_TTL >/dev/null
94-
etcdctl --no-sync -C $ETCD update ${ETCD_PATH}/masterLock $HOSTNAME --ttl $ETCD_TTL >/dev/null
90+
if etcdctl --no-sync -C "$ETCD" mk "${ETCD_PATH}/masterLock" "$HOSTNAME" --ttl "$ETCD_TTL" >/dev/null 2>&1 \
91+
|| [[ $(etcdctl --no-sync -C "$ETCD" get "${ETCD_PATH}/masterLock") == "$HOSTNAME" ]] ; then
92+
etcdctl --no-sync -C "$ETCD" set "$ETCD_PATH/host" "$HOST" --ttl "$ETCD_TTL" >/dev/null
93+
etcdctl --no-sync -C "$ETCD" set "$ETCD_PATH/port" "$EXTERNAL_PORT" --ttl "$ETCD_TTL" >/dev/null
94+
etcdctl --no-sync -C "$ETCD" update "${ETCD_PATH}/masterLock" "$HOSTNAME" --ttl "$ETCD_TTL" >/dev/null
9595
fi
96-
etcdctl --no-sync -C $ETCD set $HOST_ETCD_PATH/host $HOST --ttl $ETCD_TTL >/dev/null
97-
etcdctl --no-sync -C $ETCD set $HOST_ETCD_PATH/port $EXTERNAL_PORT --ttl $ETCD_TTL >/dev/null
96+
etcdctl --no-sync -C "$ETCD" set "$HOST_ETCD_PATH/host" "$HOST" --ttl "$ETCD_TTL" >/dev/null
97+
etcdctl --no-sync -C "$ETCD" set "$HOST_ETCD_PATH/port" "$EXTERNAL_PORT" --ttl "$ETCD_TTL" >/dev/null
9898

99-
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
99+
sleep $((ETCD_TTL/2)) # sleep for half the TTL
100100
done
101101

102102
# if the loop quits, something went wrong

registry/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ cd /docker-registry && pip install --disable-pip-version-check --no-cache-dir -r
4242
pip install --disable-pip-version-check --no-cache-dir /docker-registry/depends/docker-registry-core
4343

4444
# Install registry
45-
pip install --disable-pip-version-check --no-cache-dir file:///docker-registry#egg=docker-registry[bugsnag,newrelic,cors]
45+
pip install --disable-pip-version-check --no-cache-dir "file:///docker-registry#egg=docker-registry[bugsnag,newrelic,cors]"
4646

4747
patch \
48-
$(python -c 'import boto; import os; print os.path.dirname(boto.__file__)')/connection.py \
48+
"$(python -c 'import boto; import os; print os.path.dirname(boto.__file__)')/connection.py" \
4949
< /docker-registry/contrib/boto_header_patch.diff
5050

5151
# cleanup. indicate that python is a required package.

0 commit comments

Comments
 (0)