Skip to content

Commit 08ed78e

Browse files
committed
Copy in a fake /etc/ "overlay" to account for missing /etc/ files
1 parent b33cd38 commit 08ed78e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

docker-sbuild/docker-image-to-sbuild-schroot

+20-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ defer 'rm -rf %q' "$dir"
5959
rm -rf /var/lib/apt/lists/*; \
6060
fi
6161
COPY .tar-excludes /
62+
COPY tianon-fake-etc/ /tianon-fake-etc/
6263
EOF
6364
cat > "$dir/.tar-excludes" <<-'EOF'
6465
./.docker*
@@ -69,16 +70,31 @@ cat > "$dir/.tar-excludes" <<-'EOF'
6970
./proc/**
7071
./sys/**
7172
EOF
73+
74+
# we need to re-inject /etc/hosts into the end result!
75+
# (otherwise things like https://github.com/kubernetes/kube-openapi/blob/f0e62f92d13f418e2732b21c952fd17cab771c75/pkg/validation/validate/jsonschema_test.go#L109 result in "panic: listen tcp: lookup localhost on 172.17.0.1:53: no such host")
76+
mkdir "$dir/tianon-fake-etc"
77+
echo 'from-docker' > "$dir/tianon-fake-etc/hostname"
78+
cat > "$dir/tianon-fake-etc/hosts" <<-'EOF'
79+
127.0.0.1 localhost
80+
127.0.1.1 from-docker
81+
::1 localhost ip6-localhost ip6-loopback
82+
ff02::1 ip6-allnodes
83+
ff02::2 ip6-allrouters
84+
EOF
85+
cat > "$dir/tianon-fake-etc/resolv.conf" <<-'EOF'
86+
# https://1.1.1.1 (privacy-focused, highly-available DNS service)
87+
nameserver 1.1.1.1
88+
nameserver 1.0.0.1
89+
EOF
90+
7291
docker build "${buildArgs[@]}" --iidfile "$dir/image.txt" "$dir"
7392
img="$(< "$dir/image.txt")"
7493
#defer 'docker rmi %q > /dev/null' "$img"
7594

76-
# TODO we need to re-inject /etc/hosts into the end result!
77-
# (otherwise things like https://github.com/kubernetes/kube-openapi/blob/f0e62f92d13f418e2732b21c952fd17cab771c75/pkg/validation/validate/jsonschema_test.go#L109 result in "panic: listen tcp: lookup localhost on 172.17.0.1:53: no such host")
78-
7995
# since we already assumed the current Docker host can successfully run the image's binaries, we'll use that here
8096
timestamp="$(docker image inspect --format='{{ .Created }}' "$img")"
81-
docker run --rm --log-driver none --entrypoint bash --env timestamp="$timestamp" "$img" -Eeuo pipefail -c 'tar --create --directory=/ --one-file-system --exclude-from=/.tar-excludes --clamp-mtime --mtime="$timestamp" . ./dev' > "$tar"
97+
docker run --rm --log-driver none --entrypoint bash --env timestamp="$timestamp" "$img" -Eeuo pipefail -c 'tar --create --directory=/ --one-file-system --exclude-from=/.tar-excludes --clamp-mtime --mtime="$timestamp" --transform="s/tianon-fake-etc/etc/g" . ./dev' > "$tar"
8298
tar --list --file "$tar" > /dev/null # very crude "is this tar OK" test
8399

84100
printf '%q created (FROM %q)\n' "$tar" "$from"

0 commit comments

Comments
 (0)