Skip to content
Snippets Groups Projects
Commit a1323d03 authored by nimrod's avatar nimrod
Browse files

Merge branch 'gosu'

parents 9ab847ec 0cb39d8b
No related branches found
No related tags found
No related merge requests found
ARG image ARG image
FROM ${image} FROM ${image}
RUN if command -v apt-get; \ RUN apk add --update --no-cache openssl || true && \
then \ wget https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64 || \
apt-get update && apt-get install -y sudo; \ curl -fsSL https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64 -o gosu-amd64 && \
elif command -v yum; \ install -o root -g root -m 755 gosu-amd64 /usr/local/bin/gosu && \
then \ rm gosu-amd64 && \
yum install -y sudo; \ wget https://www.shore.co.il/blog/static/runas || \
elif command -v apk; \ curl -fsSL https://www.shore.co.il/blog/static/runas -o runas && \
then \ install -o root -g root -m 755 runas /entrypoint && \
apk add --update --no-cache sudo; \ rm runas
elif command -v dnf; \ ENTRYPOINT [ "/entrypoint" ]
then \
dnf install -y sudo; \
fi
ARG userland
ADD [ "https://www.shore.co.il/blog/static/runas-${userland}", "/entrypoint" ]
ENTRYPOINT [ "/bin/sh", "/entrypoint" ]
VOLUME /data VOLUME /data
WORKDIR /data WORKDIR /data
ENV HOME /data ENV HOME /data
#!/usr/bin/env bats #!/usr/bin/env bats
_test () { _test_root () {
name="${1:-$BATS_TEST_DESCRIPTION}" name="${1:-$BATS_TEST_DESCRIPTION}"
tag="${2:-latest}" tag="${2:-latest}"
userland="${3:-gnu}" docker build -t "runas-$name" --build-arg "image=$name:$tag" ./
docker build -t "runas-$name" --build-arg "image=$name:$tag" --build-arg "userland=$userland" ./ docker run --rm -v "$BATS_TEST_DIRNAME:/data" "runas-$name" touch "$name.root"
docker run --rm -v "$BATS_TEST_DIRNAME:/data" "runas-$name" touch "$name.touch" test "$(id -u)" = "$(stat -c '%u' $name.root)"
test "$(id -u)" = "$(stat -c '%u' $name.touch)" test "$(id -g)" = "$(stat -c '%g' $name.root)"
test "$(id -g)" = "$(stat -c '%g' $name.touch)" }
_test_user () {
name="${1:-$BATS_TEST_DESCRIPTION}"
tag="${2:-latest}"
user="$(id -u)"
group="$(id -g)"
docker build -t "runas-$name" --build-arg "image=$name:$tag" ./
docker run -u "$user:$group" --rm -v "$BATS_TEST_DIRNAME:/data" "runas-$name" touch "$name.user"
test "$user" = "$(stat -c '%u' $name.user)"
test "$user" = "$(stat -c '%g' $name.user)"
} }
teardown () { teardown () {
...@@ -15,8 +25,13 @@ teardown () { ...@@ -15,8 +25,13 @@ teardown () {
rm -f *.touch rm -f *.touch
} }
@test "ubuntu" { _test; } @test "ubuntu" { _test_root buildpack-deps bionic; }
@test "debian" { _test debian stable-slim; } @test "debian" { _test_root buildpack-deps stretch; }
@test "centos" { _test; } @test "centos" { _test_root; }
@test "fedora" { _test; } @test "fedora" { _test_root; }
@test "alpine" { _test alpine latest busybox; } @test "alpine" { _test_root; }
@test "ubuntu" { _test_user buildpack-deps bionic; }
@test "debian" { _test_user buildpack-deps stretch; }
@test "centos" { _test_user; }
@test "fedora" { _test_user; }
@test "alpine" { _test_user; }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment