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

Improve test script and add release script #16

Merged
merged 3 commits into from
Oct 16, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ARG DOCKER_PATH="/usr/local/bin/docker"
RUN mv -f "${DOCKER_PATH}" "${DOCKER_PATH}.orig"

# Install dond-shim at the same path as the original docker cli
ARG DOND_SHIM_VERSION="0.6.1"
ARG DOND_SHIM_VERSION="0.7.0"
ADD "https://github.com/felipecrs/docker-on-docker-shim/raw/v${DOND_SHIM_VERSION}/dond" "${DOCKER_PATH}"
RUN chmod 755 "${DOCKER_PATH}"
```
Expand All @@ -82,7 +82,7 @@ FROM docker:latest
RUN apk add --no-cache bash

# Install dond-shim to /usr/local/bin/dond
ARG DOND_SHIM_VERSION="0.6.1"
ARG DOND_SHIM_VERSION="0.7.0"
ARG DOND_SHIM_PATH="/usr/local/bin/dond"
ADD "https://github.com/felipecrs/docker-on-docker-shim/raw/v${DOND_SHIM_VERSION}/dond" "${DOND_SHIM_PATH}"
RUN chmod 755 "${DOND_SHIM_PATH}"
Expand Down
21 changes: 21 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -euxo pipefail

version="${1}"

echo "Releasing version ${version}..."

script_path=$(realpath "$0")
script_dir=$(dirname "${script_path}")
build_dir="$(realpath "${script_dir}/..")"
readonly build_dir
unset script_path script_dir

docker build "${build_dir}" --pull --push \
--tag "ghcr.io/felipecrs/dond-shim-bin:${version}"
docker build "${build_dir}" --pull --push \
--target dond-shim-bin --tag "ghcr.io/felipecrs/dond-shim-bin:${version}"

git_sha=$(git rev-parse HEAD)
gh release create "v${version}" --title "v${version}" --target "${git_sha}"
82 changes: 49 additions & 33 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,111 +33,127 @@ fixtures_dir="$(realpath "${script_dir}/../tests/fixtures")"
readonly fixtures_dir
unset script_path script_dir

# this avoids messing with the test output during the tests itself
echo "Pulling docker images used in tests"
docker pull -q busybox

for docker_version in "${docker_versions[@]}"; do
echo "Testing with docker version: ${docker_version}"

image_id="$(docker build --target test --build-arg "DOCKER_VERSION=${docker_version}" --quiet .)"

echo "Do not change global options or after the image"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${fixtures_dir}:/wd" "${image_id}" \
docker --host test run --volume /wd:/wd alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test run --volume ${fixtures_dir}:/wd alpine --volume /wd:/wd$"
docker --host test run --volume /wd:/wd busybox --volume /wd:/wd |
grep -q "^docker.orig --host test run --volume ${fixtures_dir}:/wd busybox --volume /wd:/wd$"

echo "Same as above, but retaining read only mode"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${fixtures_dir}:/wd" "${image_id}" \
docker --host test run --volume /wd:/wd:ro alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro alpine --volume /wd:/wd$"
docker --host test run --volume /wd:/wd:ro busybox --volume /wd:/wd |
grep -q "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro busybox --volume /wd:/wd$"

echo "Same as above but with --mount"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${fixtures_dir}:/wd" "${image_id}" \
docker --host test run --volume /wd:/wd:ro --mount=type=bind,source=/wd,readonly,destination=/wd2 alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro --mount=type=bind,source=${fixtures_dir},readonly,destination=/wd2 alpine --volume /wd:/wd$"
docker --host test run --volume /wd:/wd:ro --mount=type=bind,source=/wd,readonly,destination=/wd2 busybox --volume /wd:/wd |
grep -q "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro --mount=type=bind,source=${fixtures_dir},readonly,destination=/wd2 busybox --volume /wd:/wd$"

echo "Same as above (without --mount), but retaining read only mode on auto added volume"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --env DOND_SHIM_MOCK_CONTAINER_ROOT_ON_HOST=/container-root --volume "${fixtures_dir}:/wd" --volume "${fixtures_dir}/testfile:/test/testfile" "${image_id}" \
docker --host test run --volume /wd:/wd:ro --volume /test:/test:ro alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro --volume /container-root/test:/test:ro --volume ${fixtures_dir}/testfile:/test/testfile:ro alpine --volume /wd:/wd$"
docker --host test run --volume /wd:/wd:ro --volume /test:/test:ro busybox --volume /wd:/wd |
grep -q "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro --volume /container-root/test:/test:ro --volume ${fixtures_dir}/testfile:/test/testfile:ro busybox --volume /wd:/wd$"

echo "Same as above but should not auto add mounts which are not bind mounts"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --env DOND_SHIM_MOCK_CONTAINER_ROOT_ON_HOST=/container-root --volume "${fixtures_dir}:/wd" --volume "${fixtures_dir}/testfile:/test/testfile" --mount type=tmpfs,target=/test/tmpfsdir "${image_id}" \
docker --host test run --volume /wd:/wd:ro --volume /test:/test:ro alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro --volume /container-root/test:/test:ro --volume ${fixtures_dir}/testfile:/test/testfile:ro alpine --volume /wd:/wd$"
docker --host test run --volume /wd:/wd:ro --volume /test:/test:ro busybox --volume /wd:/wd |
grep -q "^docker.orig --host test run --volume ${fixtures_dir}:/wd:ro --volume /container-root/test:/test:ro --volume ${fixtures_dir}/testfile:/test/testfile:ro busybox --volume /wd:/wd$"

echo "Same as above (with --mount src and target, dst), but retaining read only mode on auto added volume"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --env DOND_SHIM_MOCK_CONTAINER_ROOT_ON_HOST=/container-root --volume "${fixtures_dir}:/wd" --volume "${fixtures_dir}/testfile:/test/testfile" "${image_id}" \
docker --host test run --mount type=bind,src=/wd,target=/wd,readonly --mount type=bind,source=/test,dst=/test,readonly alpine --mount type=bind,source=/wd,destination=/wd,readonly |
grep --quiet "^docker.orig --host test run --mount type=bind,src=${fixtures_dir},target=/wd,readonly --mount type=bind,source=/container-root/test,dst=/test,readonly --mount type=bind,source=${fixtures_dir}/testfile,dst=/test/testfile,readonly alpine --mount type=bind,source=/wd,destination=/wd,readonly$"
docker --host test run --mount type=bind,src=/wd,target=/wd,readonly --mount type=bind,source=/test,dst=/test,readonly busybox --mount type=bind,source=/wd,destination=/wd,readonly |
grep -q "^docker.orig --host test run --mount type=bind,src=${fixtures_dir},target=/wd,readonly --mount type=bind,source=/container-root/test,dst=/test,readonly --mount type=bind,source=${fixtures_dir}/testfile,dst=/test/testfile,readonly busybox --mount type=bind,source=/wd,destination=/wd,readonly$"

echo "Same but for container run"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${fixtures_dir}:/wd" "${image_id}" \
docker --host test container run --volume /wd:/wd alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test container run --volume ${fixtures_dir}:/wd alpine --volume /wd:/wd$"
docker --host test container run --volume /wd:/wd busybox --volume /wd:/wd |
grep -q "^docker.orig --host test container run --volume ${fixtures_dir}:/wd busybox --volume /wd:/wd$"

echo "Same but for create"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${fixtures_dir}:/wd" "${image_id}" \
docker --host test create --volume /wd:/wd alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test create --volume ${fixtures_dir}:/wd alpine --volume /wd:/wd$"
docker --host test create --volume /wd:/wd busybox --volume /wd:/wd |
grep -q "^docker.orig --host test create --volume ${fixtures_dir}:/wd busybox --volume /wd:/wd$"

echo "Same but container create"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${fixtures_dir}:/wd" "${image_id}" \
docker --host test container create --volume /wd:/wd alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test container create --volume ${fixtures_dir}:/wd alpine --volume /wd:/wd$"
docker --host test container create --volume /wd:/wd busybox --volume /wd:/wd |
grep -q "^docker.orig --host test container create --volume ${fixtures_dir}:/wd busybox --volume /wd:/wd$"

echo "Do not do anything for other commands"
"${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${fixtures_dir}:/wd" "${image_id}" \
docker --host test whatever --volume /wd:/wd alpine --volume /wd:/wd |
grep --quiet "^docker.orig --host test whatever --volume /wd:/wd alpine --volume /wd:/wd$"
docker --host test whatever --volume /wd:/wd busybox --volume /wd:/wd |
grep -q "^docker.orig --host test whatever --volume /wd:/wd busybox --volume /wd:/wd$"

echo "Check if docker on docker is working"
"${docker_args[@]}" "${image_id}" \
docker version >/dev/null

echo "Check if mounting an volume from the container gets fixed"
echo "Check if mounting a volume from the container gets fixed"
"${docker_args[@]}" "${image_id}" \
docker run --rm --volume /test/only-inside-container:/only-inside-container ubuntu:latest grep "^test$" /only-inside-container >/dev/null
docker run --rm --volume /test/only-inside-container:/only-inside-container busybox \
grep -q "^test$" /only-inside-container

echo "Same but with equals sign"
"${docker_args[@]}" "${image_id}" \
docker run --rm --volume=/test/only-inside-container:/only-inside-container ubuntu:latest grep "^test$" /only-inside-container >/dev/null
docker run --rm --volume=/test/only-inside-container:/only-inside-container busybox \
grep -q "^test$" /only-inside-container

echo "Check if mounting a volume which is already a volume gets fixed"
"${docker_args[@]}" --volume "${fixtures_dir}:/wd" "${image_id}" \
docker run --rm --volume /wd:/wd ubuntu:latest grep "^test$" /wd/testfile >/dev/null
docker run --rm --volume /wd:/wd busybox \
grep -q "^test$" /wd/testfile

echo "Same as above but for a file within the volume"
"${docker_args[@]}" --volume "${fixtures_dir}:/wd" "${image_id}" \
docker run --rm --volume /wd/testfile:/wd/testfile ubuntu:latest grep "^test$" /wd/testfile >/dev/null
docker run --rm --volume /wd/testfile:/wd/testfile busybox \
grep -q "^test$" /wd/testfile

echo "Check if mounting a volume which contains another volume adds all proper volumes"
"${docker_args[@]}" --volume "${fixtures_dir}/testfile:/test/testfile" "${image_id}" \
docker run --rm --volume /test:/wd ubuntu:latest grep "^test$" /wd/testfile >/dev/null
docker run --rm --volume /test:/wd busybox \
grep -q "^test$" /wd/testfile

echo "With --mount"
"${docker_args[@]}" --volume "${fixtures_dir}/testfile:/test/testfile" "${image_id}" \
docker run --rm --mount type=bind,source=/test,destination=/wd ubuntu:latest grep "^test$" /wd/testfile >/dev/null
docker run --rm --mount type=bind,source=/test,destination=/wd busybox \
grep -q "^test$" /wd/testfile

echo "With --mount shuffling order"
"${docker_args[@]}" --volume "${fixtures_dir}/testfile:/test/testfile" "${image_id}" \
docker run --rm --mount destination=/wd,source=/test,type=bind ubuntu:latest grep "^test$" /wd/testfile >/dev/null
docker run --rm --mount destination=/wd,source=/test,type=bind busybox \
grep -q "^test$" /wd/testfile

echo "Same as above but for multiple files under different volumes"
"${docker_args[@]}" --volume "${fixtures_dir}/testfile:/test/testfile" --volume "${fixtures_dir}/testfile:/test/testfile2" "${image_id}" \
docker run --rm --volume /test:/wd ubuntu:latest bash -c 'grep "^test$" /wd/testfile && grep "^test$" /wd/testfile2 && grep "^test$" /wd/only-inside-container' >/dev/null
docker run --rm --volume /test:/wd busybox \
sh -c 'grep -q "^test$" /wd/testfile && grep -q "^test$" /wd/testfile2 && grep -q "^test$" /wd/only-inside-container'

echo "Same test as above but with a read only volume"
"${docker_args[@]}" --volume "${fixtures_dir}/testfile:/test/testfile" --volume "${fixtures_dir}/testfile:/test/testfile2" "${image_id}" \
docker run --rm --volume /test:/wd:ro ubuntu:latest bash -c 'grep "^test$" /wd/testfile && grep "^test$" /wd/testfile2 && grep "^test$" /wd/only-inside-container' >/dev/null
docker run --rm --volume /test:/wd:ro busybox \
sh -c 'grep -q "^test$" /wd/testfile && grep -q "^test$" /wd/testfile2 && grep -q "^test$" /wd/only-inside-container'

echo "Same as above but with a volume that matches the parent first"
"${docker_args[@]}" --volume "${fixtures_dir}:/folder" --volume "${fixtures_dir}/testfile:/test/testfile" --volume "${fixtures_dir}/testfile:/test/testfile2" "${image_id}" \
docker run --rm --volume /folder:/test --volume /test:/wd:ro ubuntu:latest bash -c 'grep "^test$" /wd/testfile && grep "^test$" /wd/testfile2 && grep "^test$" /wd/only-inside-container' >/dev/null
docker run --rm --volume /folder:/test --volume /test:/wd:ro busybox \
sh -c 'grep -q "^test$" /wd/testfile && grep -q "^test$" /wd/testfile2 && grep -q "^test$" /wd/only-inside-container'

echo "With named volume"
volume_name=$(docker volume create --opt type=none --opt device="${fixtures_dir}" --opt o=bind)
trap 'docker volume rm -f "${volume_name}" >/dev/null' EXIT
# this confirms the volume works in the parent container prior to the shim
"${docker_args[@]}" --volume "${volume_name}:/wd" "${image_id}" \
grep "^test$" /wd/testfile >/dev/null
grep -q "^test$" /wd/testfile
"${docker_args[@]}" --volume "${volume_name}:/wd" "${image_id}" \
docker run --rm --volume /wd:/wd ubuntu:latest grep "^test$" /wd/testfile >/dev/null
docker run --rm --volume /wd:/wd busybox \
grep -q "^test$" /wd/testfile
docker volume rm -f "${volume_name}" >/dev/null
done