Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
version: v2.36.0
- name: docker compose up
run: docker compose up -d --build
- name: wait for container setup
run: sleep 2
- name: run tests
run: docker compose exec shell-dev-tools bashunit

11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ ENV bashunit_version='0.23.0'
ENV bashunit_hash='7043c1818016f330ee12671a233f89906f0d373f3b2aa231a8c40123be5a222b'

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

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

# verify the sha256sum for bashunit 0.14.0
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"; }
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;

RUN bashunit --version

RUN groupadd -g 1000 dev && useradd -m -u 1000 -g dev dev
RUN groupadd -g 1000 dev && useradd -m -u 1000 -g dev dev && \
echo "dev ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/dev && chmod 0440 /etc/sudoers.d/dev

WORKDIR /home/dev/shell-dev-tools

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

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# shell dev tools

![tests status](https://github.com/devloberto/shell-dev-tools/actions/workflows/test.yml/badge.svg)
[![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)

handy tools for developers using bash or zsh

Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ services:
- shell-dev-tools:debian-trixie
volumes:
- $PWD:/home/dev/shell-dev-tools
entrypoint: tail -f /dev/null
- /var/run/docker.sock:/var/run/docker.sock:ro

13 changes: 13 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# setup docker group to match the host's docker socket group
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
if ! getent group docker >/dev/null; then
sudo groupadd -g "$DOCKER_GID" docker
else
sudo groupmod -g "$DOCKER_GID" docker
fi
sudo usermod -aG docker dev # and add 'dev' user to docker group

# keep the container running
tail -f /dev/null
1 change: 1 addition & 0 deletions shell-dev-tools.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SOURCE="${BASH_SOURCE[0]:-${(%):-%x}}" # bash and zsh compatability
SCRIPT_DIR="$(realpath -e -- "$(dirname -- "$SOURCE")")"

source "$SCRIPT_DIR/src/docker.sh"
source "$SCRIPT_DIR/src/git_delete_all_branches_but_default.sh"
source "$SCRIPT_DIR/src/strcnt.sh"
source "$SCRIPT_DIR/src/unix.sh"
3 changes: 3 additions & 0 deletions src/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dockerll() {
docker ps -a --format "table {{ .Names }}\t{{ .Status }}\t{{ .Networks }}\t{{ .Ports }}" $@
}
38 changes: 38 additions & 0 deletions tests/docker_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

function set_up() {
ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")/.."
source "$ROOT_DIR/src/docker.sh"
}

test_dockerll() {
local output=$(dockerll)

assert_greater_or_equal_than 2 "$(echo "$output" | wc -l)"

# output header
local first_line=$(echo "$output" | head -n 1)
assert_contains "NAMES " "$first_line"
assert_contains " STATUS " "$first_line"
assert_contains " NETWORKS " "$first_line"
assert_contains " PORTS" "$first_line"
}

test_dockerll_filtered_by_name() {
local output=$(dockerll --filter name=shell-dev-tools)

assert_line_count 2 "$output"

# output header
local first_line=$(echo "$output" | head -n 1)
assert_contains "NAMES " "$first_line"
assert_contains " STATUS " "$first_line"
assert_contains " NETWORKS " "$first_line"
assert_contains " PORTS" "$first_line"

# output shell-dev-tools container
local second_line=$(echo "$output" | sed -n '2p')
assert_contains "shell-dev-tools " "$second_line"
assert_matches " Up [0-9]+ (seconds|minutes) " "$second_line"
assert_contains " shell-dev-tools_default" "$second_line"
}