Skip to content

Commit 0467e06

Browse files
committed
implement dockerll function incl. unit test
1 parent 07c5be9 commit 0467e06

7 files changed

Lines changed: 47 additions & 8 deletions

File tree

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ ENV bashunit_version='0.23.0'
55
ENV bashunit_hash='7043c1818016f330ee12671a233f89906f0d373f3b2aa231a8c40123be5a222b'
66

77
# bashunit installation dependencies
8-
RUN apt-get update; apt-get install -y curl perl git; rm -rf /var/lib/apt/lists/*
8+
RUN apt-get update; apt-get install -y curl perl git docker.io sudo; rm -rf /var/lib/apt/lists/*
99

1010
RUN mkdir -p $bashunit_dir
1111
RUN curl -o /tmp/install.sh https://bashunit.typeddevs.com/install.sh
1212
RUN bash /tmp/install.sh $bashunit_dir $bashunit_version; ln -s $bashunit_dir/bashunit /usr/bin/bashunit; chmod +x $bashunit_dir/bashunit
1313

1414
# verify the sha256sum for bashunit 0.14.0
15-
RUN DIR="$bashunit_dir"; KNOWN_HASH="$bashunit_hash"; FILE="$DIR/bashunit"; [ "$(shasum -a 256 "$FILE" | awk '{ print $1 }')" = "$KNOWN_HASH" ] && echo -e "✓ \033[1mbashunit\033[0m verified." || { echo -e "✗ \033[1mbashunit\033[0m corrupt"; rm "$FILE"; }
15+
RUN DIR="$bashunit_dir"; KNOWN_HASH="$bashunit_hash"; FILE="$DIR/bashunit"; [ "$(shasum -a 256 "$FILE" | awk '{ print $1 }')" = "$KNOWN_HASH" ] && echo -e "✓ \033[1mbashunit\033[0m verified." || { echo -e "✗ \033[1mbashunit\033[0m corrupt"; rm "$FILE"; } ; bashunit --version;
1616

17-
RUN bashunit --version
18-
19-
RUN groupadd -g 1000 dev && useradd -m -u 1000 -g dev dev
17+
RUN groupadd -g 1000 dev && useradd -m -u 1000 -g dev dev && \
18+
echo "dev ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/dev && chmod 0440 /etc/sudoers.d/dev
2019

2120
WORKDIR /home/dev/shell-dev-tools
2221

@@ -30,5 +29,5 @@ RUN git config --global init.defaultBranch master && \
3029
git config --global user.email "shell@dev.tools" && \
3130
git config --global user.name "dev"
3231

33-
ENTRYPOINT ["/bin/bash"]
32+
ENTRYPOINT ["/home/dev/shell-dev-tools/docker-entrypoint.sh"]
3433

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# shell dev tools
22

3-
![tests status](https://github.com/devloberto/shell-dev-tools/actions/workflows/test.yml/badge.svg)
3+
[![tests status](https://github.com/devloberto/shell-dev-tools/actions/workflows/test.yml/badge.svg)](https://github.com/devloberto/shell-dev-tools/actions/workflows/test.yml)
44

55
handy tools for developers using bash or zsh
66

compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ services:
88
- shell-dev-tools:debian-trixie
99
volumes:
1010
- $PWD:/home/dev/shell-dev-tools
11-
entrypoint: tail -f /dev/null
11+
- /var/run/docker.sock:/var/run/docker.sock:ro
1212

docker-entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# setup docker group to match the host's docker socket group
4+
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
5+
if ! getent group docker >/dev/null; then
6+
sudo groupadd -g "$DOCKER_GID" docker
7+
else
8+
sudo groupmod -g "$DOCKER_GID" docker
9+
fi
10+
sudo usermod -aG docker dev # and add 'dev' user to docker group
11+
12+
# keep the container running
13+
tail -f /dev/null

shell-dev-tools.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
SOURCE="${BASH_SOURCE[0]:-${(%):-%x}}" # bash and zsh compatability
22
SCRIPT_DIR="$(realpath -e -- "$(dirname -- "$SOURCE")")"
33

4+
source "$SCRIPT_DIR/src/docker.sh"
45
source "$SCRIPT_DIR/src/git_delete_all_branches_but_default.sh"
56
source "$SCRIPT_DIR/src/strcnt.sh"
67
source "$SCRIPT_DIR/src/unix.sh"

src/docker.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dockerll() {
2+
docker ps -a --format "table {{ .Names }}\t{{ .Status }}\t{{ .Networks }}\t{{ .Ports }}"
3+
}

tests/docker_test.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
function set_up() {
4+
ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.."
5+
source "$ROOT_DIR/src/docker.sh"
6+
}
7+
8+
test_dockerll() {
9+
local output=$(dockerll)
10+
11+
# output header
12+
local first_line=$(echo "$output" | head -n 1)
13+
assert_contains "NAMES " "$first_line"
14+
assert_contains " STATUS " "$first_line"
15+
assert_contains " NETWORKS " "$first_line"
16+
assert_contains " PORTS" "$first_line"
17+
18+
# output shell-dev-tools container
19+
local second_line=$(echo "$output" | sed -n '2p') # @TODO: what if it's not the 2. line?
20+
assert_contains "shell-dev-tools " "$second_line"
21+
assert_matches " Up [0-9]+ minutes " "$second_line"
22+
assert_contains " shell-dev-tools_default" "$second_line"
23+
}

0 commit comments

Comments
 (0)