Skip to content
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

Adding shellcheck static analysis in CI #151

Merged
merged 2 commits into from
Dec 12, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
matrix:
linter:
- golangci-lint
- shellcheck
steps:
- uses: actions/checkout@v4
# - name: Setup Nix
Expand Down
4 changes: 2 additions & 2 deletions modules/common/containerd-rootless-child.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -e
export PATH="@path@"


if ! [ -w $HOME ]; then
if ! [ -w "$HOME" ]; then
echo "HOME needs to be set and writable"
exit 1
fi
Expand Down Expand Up @@ -43,7 +43,7 @@ for i in "${!mountSources[@]}"; do
# The actual files in the parent namespace are *not removed* by this rm command.
rm -rf "$mountPoint"

echo >&2 Bind mounting ${mountSource} to ${mountPoint} inside mount namespace
echo >&2 Bind mounting "${mountSource}" to "${mountPoint}" inside mount namespace
mkdir -p "$mountSource" "$mountPoint"
mount --bind "$mountSource" "$mountPoint"
done
Expand Down
2 changes: 1 addition & 1 deletion modules/common/containerd-rootless.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -e
export PATH="@path@"


if ! [ -w $XDG_RUNTIME_DIR ]; then
if ! [ -w "$XDG_RUNTIME_DIR" ]; then
echo "XDG_RUNTIME_DIR needs to be set and writable"
exit 1
fi
Expand Down
3 changes: 3 additions & 0 deletions modules/flake/linters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
golangci-lint = pkgs.writeScriptBin "golangci-lint" ''
${pkgs.golangci-lint}/bin/golangci-lint run -v
'';
shellcheck = pkgs.writeScriptBin "shellcheck" ''
${pkgs.shellcheck}/bin/shellcheck -x $(find . -name "*.sh" -type f)
'';
};

apps =
Expand Down
2 changes: 1 addition & 1 deletion script/kind/usr/local/bin/kind-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
> /sys/fs/cgroup/cgroup.subtree_control
fi

exec $@
exec "$@"
6 changes: 5 additions & 1 deletion script/rootless/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export REPO_DIR=$(git rev-parse --show-toplevel)
#!/bin/bash
set -euo pipefail

REPO_DIR="$(git rev-parse --show-toplevel)"
export REPO_DIR

export BIN_DIR="${REPO_DIR}/build/bin"
export CONTAINERD_ADDRESS="${REPO_DIR}/build/containerd/containerd.sock"
Expand Down
3 changes: 2 additions & 1 deletion script/rootless/containerd.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

rootlesskit \
Expand All @@ -9,5 +10,5 @@ rootlesskit \
--copy-up=/run \
--copy-up=/var/lib \
--port-driver=slirp4netns \
--state-dir=$REPO_DIR/build/rootlesskit-containerd \
--state-dir="$REPO_DIR/build/rootlesskit-containerd" \
sh -c "containerd --config ${CONTAINERD_CONFIG_FILE}"
5 changes: 3 additions & 2 deletions script/rootless/create-containerd-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

mkdir -p $(dirname $CONTAINERD_CONFIG_FILE)
cat <<EOM > $CONTAINERD_CONFIG_FILE
mkdir -p "$(dirname "$CONTAINERD_CONFIG_FILE")"
cat <<EOM > "$CONTAINERD_CONFIG_FILE"
version = 2
root = "$REPO_DIR/build/containerd/root"
state = "$REPO_DIR/build/containerd/state"
Expand Down
5 changes: 3 additions & 2 deletions script/rootless/create-nerdctl-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

mkdir -p $(dirname $NERDCTL_TOML)
cat <<EOM > $NERDCTL_TOML
mkdir -p "$(dirname "$NERDCTL_TOML")"
cat <<EOM > "$NERDCTL_TOML"
address = "${REPO_DIR}/build/containerd/containerd.sock"
snapshotter = "nix"
data_root = "${REPO_DIR}/build/nerdctl/root/"
Expand Down
5 changes: 3 additions & 2 deletions script/rootless/create-nix-snapshotter-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

mkdir -p $(dirname $NIX_SNAPSHOTTER_CONFIG_FILE)
cat <<EOM > $NIX_SNAPSHOTTER_CONFIG_FILE
mkdir -p "$(dirname "$NIX_SNAPSHOTTER_CONFIG_FILE")"
cat <<EOM > "$NIX_SNAPSHOTTER_CONFIG_FILE"
address = "${REPO_DIR}/build/nix-snapshotter/nix-snapshotter.sock"
root = "${REPO_DIR}/build/containerd/root/io.containerd.snapshotter.v1.nix"

Expand Down
5 changes: 3 additions & 2 deletions script/rootless/load-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

image=$1

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

outPath=$(nix build --print-out-paths .#image-${image})
${BIN_DIR}/nix2container --address $CONTAINERD_ADDRESS load ${outPath}
outPath=$(nix build --print-out-paths .#image-"${image}")
"${BIN_DIR}"/nix2container --address "$CONTAINERD_ADDRESS" load "${outPath}"
1 change: 1 addition & 0 deletions script/rootless/nerdctl.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

nerdctl "$@"
1 change: 1 addition & 0 deletions script/rootless/nix-snapshotter.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

./build/bin/nix-snapshotter \
Expand Down
3 changes: 2 additions & 1 deletion script/rootless/nsenter.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# shellcheck disable=SC1091
source "${BASH_SOURCE%/*}/common.sh"

pid=$(cat "$REPO_DIR/build/rootlesskit-containerd/child_pid")
nsenter -U --preserve-credentials -m -n -t "$pid" $@
nsenter -U --preserve-credentials -m -n -t "$pid" "$@"
Loading