aboutsummaryrefslogtreecommitdiff
path: root/src/docker-from-docker
diff options
context:
space:
mode:
authoreitsupi <50911393+eitsupi@users.noreply.github.com>2022-10-11 01:33:01 +0300
committerGitHub <noreply@github.com>2022-10-11 01:33:01 +0300
commita8cb375d460840bbf8c91599d16fc87d9ee8b996 (patch)
tree73dd647775325582c17a452816457f5cec82004d /src/docker-from-docker
parent065b5ec9e19d4f289a070c3d5337696fd2394dc0 (diff)
Ensure remove apt-update cache at the beginning and end of the scripts (#210)
* remove apt lists * bump versions
Diffstat (limited to 'src/docker-from-docker')
-rw-r--r--src/docker-from-docker/devcontainer-feature.json2
-rwxr-xr-xsrc/docker-from-docker/install.sh30
2 files changed, 19 insertions, 13 deletions
diff --git a/src/docker-from-docker/devcontainer-feature.json b/src/docker-from-docker/devcontainer-feature.json
index 119ef3a..866f176 100644
--- a/src/docker-from-docker/devcontainer-feature.json
+++ b/src/docker-from-docker/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "docker-from-docker",
- "version": "1.0.4",
+ "version": "1.0.5",
"name": "Docker (Docker-from-Docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-from-docker",
"descripton": "Re-use the host docker socket, adding the Docker CLI to a container. Feature invokes a script to enable using a forwarded Docker socket within a container to run Docker commands.",
diff --git a/src/docker-from-docker/install.sh b/src/docker-from-docker/install.sh
index 312e283..d128ab9 100755
--- a/src/docker-from-docker/install.sh
+++ b/src/docker-from-docker/install.sh
@@ -22,6 +22,9 @@ DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal hirsute
set -e
+# Clean up
+rm -rf /var/lib/apt/lists/*
+
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
@@ -61,8 +64,10 @@ get_common_setting() {
apt_get_update()
{
- echo "Running apt-get update..."
- apt-get update -y
+ if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
+ echo "Running apt-get update..."
+ apt-get update -y
+ fi
}
# Checks if packages are installed and installs them if not
@@ -113,8 +118,7 @@ export DEBIAN_FRONTEND=noninteractive
# Install dependencies
check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
if ! type git > /dev/null 2>&1; then
- apt_get_update
- apt-get -y install git
+ check_packages git
fi
# Source /etc/os-release to get OS info
@@ -206,10 +210,7 @@ else
fi
if [ "${TARGET_COMPOSE_ARCH}" != "x86_64" ]; then
# Use pip to get a version that runns on this architecture
- if ! dpkg -s python3-minimal python3-pip libffi-dev python3-venv > /dev/null 2>&1; then
- apt_get_update
- apt-get -y install python3-minimal python3-pip libffi-dev python3-venv
- fi
+ check_packages python3-minimal python3-pip libffi-dev python3-venv
export PIPX_HOME=/usr/local/pipx
mkdir -p ${PIPX_HOME}
export PIPX_BIN_DIR=/usr/local/bin
@@ -255,6 +256,8 @@ fi
# If init file already exists, exit
if [ -f "/usr/local/share/docker-init.sh" ]; then
+ # Clean up
+ rm -rf /var/lib/apt/lists/*
exit 0
fi
echo "docker-init doesnt exist, adding..."
@@ -269,6 +272,8 @@ fi
if [ "${ENABLE_NONROOT_DOCKER}" = "false" ] || [ "${USERNAME}" = "root" ]; then
echo -e '#!/usr/bin/env bash\nexec "$@"' > /usr/local/share/docker-init.sh
chmod +x /usr/local/share/docker-init.sh
+ # Clean up
+ rm -rf /var/lib/apt/lists/*
exit 0
fi
@@ -281,10 +286,7 @@ DOCKER_GID="$(grep -oP '^docker:x:\K[^:]+' /etc/group)"
# If enabling non-root access and specified user is found, setup socat and add script
chown -h "${USERNAME}":root "${TARGET_SOCKET}"
-if ! dpkg -s socat > /dev/null 2>&1; then
- apt_get_update
- apt-get -y install socat
-fi
+check_packages socat
tee /usr/local/share/docker-init.sh > /dev/null \
<< EOF
#!/usr/bin/env bash
@@ -346,4 +348,8 @@ exec "\$@"
EOF
chmod +x /usr/local/share/docker-init.sh
chown ${USERNAME}:root /usr/local/share/docker-init.sh
+
+# Clean up
+rm -rf /var/lib/apt/lists/*
+
echo "Done!"