Skip to content

Commit 80dcd91

Browse files
authored
Add shfmt and shellcheck bits (#14)
* Add shfmt and shellcheck bits * Fix shell format and safety issues
1 parent ff2abbd commit 80dcd91

File tree

7 files changed

+43
-13
lines changed

7 files changed

+43
-13
lines changed

.github/workflows/ci.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ jobs:
2525
with:
2626
image: valkey
2727
context: docker-images/valkey
28+
29+
lint:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: luizm/action-sh-checker@master
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
SHFMT_OPTS: -i 4
37+
with:
38+
sh_checker_comment: true

docker-images/valkey/valkey-entrypoint/reload-certs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -eu
33

44
# source the functions
5+
# shellcheck source=/dev/null
56
. /opt/valkey/entrypoint/functions
67

78
wait_for_valkey
@@ -19,7 +20,7 @@ trap handle_sigterm SIGTERM
1920
while $running; do
2021

2122
# Ensure that a SIGTERM causes a fast exit of this process
22-
for _ in $(seq 1 $RELOAD_INTERVAL); do
23+
for _ in $(seq 1 "${RELOAD_INTERVAL}"); do
2324
if ! $running; then
2425
exit 0
2526
fi
@@ -28,5 +29,6 @@ while $running; do
2829
echo "Reloading TLS certificates"
2930

3031
# We can connect to the local redis instance to reload the cert as this run on each valkey instance
32+
# shellcheck disable=SC2086,SC2154
3133
valkey-cli $common_args --raw CONFIG GET tls-key-file | tail -n1 | head -c -1 | valkey-cli $common_args -x CONFIG SET tls-key-file
3234
done

docker-images/valkey/valkey-entrypoint/replication-coordinator

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
set -euo pipefail
33

44
# source the functions
5+
# shellcheck source=/dev/null
56
. /opt/valkey/entrypoint/functions
67

78
wait_for_valkey
89

910
echo "Waiting for Valkey Sentinel to be ready"
1011
wait_for_sentinel "valkey-sentinel" "26379"
1112

12-
SENTINEL_QUORUM=$(get_sentinel_quorum ${VALKEY_REQUIRED_SENTINELS})
13+
SENTINEL_QUORUM=$(get_sentinel_quorum "${VALKEY_REQUIRED_SENTINELS}")
1314

1415
echo "Discovering Valkey Master via Sentinel"
1516
MASTER=$(get_master_addr_by_name "valkey-sentinel" "${VALKEY_NAME}")
@@ -30,6 +31,7 @@ if [[ "${MASTER}" == "null" ]]; then
3031
fi
3132
done
3233

34+
# shellcheck disable=SC2086,SC2154
3335
valkey-cli $common_args -p 6379 REPLICAOF no one
3436
echo "Notifying all Sentinels"
3537

@@ -64,7 +66,8 @@ else
6466

6567
echo "Master found: ${MASTER_ADDR}:${MASTER_PORT}"
6668
echo "Sending 'REPLICAOF ${MASTER_ADDR} ${MASTER_PORT}' to local Valkey"
67-
valkey-cli $common_args -p 6379 REPLICAOF ${MASTER_ADDR} ${MASTER_PORT}
69+
# shellcheck disable=SC2086
70+
valkey-cli $common_args -p 6379 REPLICAOF "${MASTER_ADDR}" "${MASTER_PORT}"
6871
fi
6972

7073
touch /opt/valkey/etc/ready

redis-base/reload-certs.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#!/bin/sh
2-
1+
#!/usr/bin/env bash
32
set -eu
43

54
apk add --no-cache redis
65

76
# Note: using REDIS_URL works because we know there's a single replica.
87
# If we ever introduce read replicas, we'd need to connect to each one to force cert reload.
9-
redis_args="-e --tls -u $REDIS_URL"
8+
redis_args=(-e --tls -u "${REDIS_URL}")
109

1110
if [ -e /srv/redis-ca-bundle/ca-certs.crt ]; then
12-
redis_args="$redis_args --cacert /srv/redis-ca-bundle/ca-certs.crt"
11+
redis_args=("${redis_args[@]}" --cacert /srv/redis-ca-bundle/ca-certs.crt)
1312
fi
1413

15-
redis-cli $redis_args --raw CONFIG GET tls-key-file | tail -n1 | head -c -1 | redis-cli $redis_args -x CONFIG SET tls-key-file
14+
redis-cli "${redis_args[@]}" --raw CONFIG GET tls-key-file |
15+
tail -n1 |
16+
head -c -1 |
17+
redis-cli "${redis_args[@]}" -x CONFIG SET tls-key-file

redis-instance/reload-certs.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#!/bin/sh
2-
1+
#!/usr/bin/env bash
32
set -eu
43

54
apk add --no-cache redis
65

76
# Note: using REDIS_URL works because we know there's a single replica.
87
# If we ever introduce read replicas, we'd need to connect to each one to force cert reload.
9-
redis_args="-e --tls -u $REDIS_URL"
8+
redis_args=(-e --tls -u "${REDIS_URL}")
109

1110
if [ -e /srv/redis-ca-bundle/ca-certs.crt ]; then
12-
redis_args="$redis_args --cacert /srv/redis-ca-bundle/ca-certs.crt"
11+
redis_args=("${redis_args[@]}" --cacert /srv/redis-ca-bundle/ca-certs.crt)
1312
fi
1413

15-
redis-cli $redis_args --raw CONFIG GET tls-key-file | tail -n1 | head -c -1 | redis-cli $redis_args -x CONFIG SET tls-key-file
14+
redis-cli "${redis_args[@]}" --raw CONFIG GET tls-key-file |
15+
tail -n1 |
16+
head -c -1 |
17+
redis-cli "${redis_args[@]}" -x CONFIG SET tls-key-file

script/format

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd "$(git rev-parse --show-toplevel)"
5+
shfmt -f . | xargs shfmt -i 4 -w

script/lint

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cd "$(git rev-parse --show-toplevel)"
5+
shfmt -f . | xargs shellcheck

0 commit comments

Comments
 (0)