Skip to content

Add shfmt and shellcheck bits #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ jobs:
with:
image: valkey
context: docker-images/valkey

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: luizm/action-sh-checker@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHFMT_OPTS: -i 4
with:
sh_checker_comment: true
4 changes: 3 additions & 1 deletion docker-images/valkey/valkey-entrypoint/reload-certs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -eu

# source the functions
# shellcheck source=/dev/null
. /opt/valkey/entrypoint/functions

wait_for_valkey
Expand All @@ -19,7 +20,7 @@ trap handle_sigterm SIGTERM
while $running; do

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

# We can connect to the local redis instance to reload the cert as this run on each valkey instance
# shellcheck disable=SC2086,SC2154
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
done
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
set -euo pipefail

# source the functions
# shellcheck source=/dev/null
. /opt/valkey/entrypoint/functions

wait_for_valkey

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

SENTINEL_QUORUM=$(get_sentinel_quorum ${VALKEY_REQUIRED_SENTINELS})
SENTINEL_QUORUM=$(get_sentinel_quorum "${VALKEY_REQUIRED_SENTINELS}")

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

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

Expand Down Expand Up @@ -64,7 +66,8 @@ else

echo "Master found: ${MASTER_ADDR}:${MASTER_PORT}"
echo "Sending 'REPLICAOF ${MASTER_ADDR} ${MASTER_PORT}' to local Valkey"
valkey-cli $common_args -p 6379 REPLICAOF ${MASTER_ADDR} ${MASTER_PORT}
# shellcheck disable=SC2086
valkey-cli $common_args -p 6379 REPLICAOF "${MASTER_ADDR}" "${MASTER_PORT}"
fi

touch /opt/valkey/etc/ready
Expand Down
12 changes: 7 additions & 5 deletions redis-base/reload-certs.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/sh

#!/usr/bin/env bash
set -eu

apk add --no-cache redis

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

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

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
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
12 changes: 7 additions & 5 deletions redis-instance/reload-certs.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/sh

#!/usr/bin/env bash
set -eu

apk add --no-cache redis

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

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

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
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
5 changes: 5 additions & 0 deletions script/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"
shfmt -f . | xargs shfmt -i 4 -w
5 changes: 5 additions & 0 deletions script/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"
shfmt -f . | xargs shellcheck