From 53a6b28243c514a4d2ef169991d25a6bf7156a21 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 4 Apr 2024 09:58:27 -0300 Subject: [PATCH 1/2] Add test for SSHD in devcontainer --- .../dind-devcontainer/devcontainer.json | 20 ++++++++++++++++ devcontainer/test.sh | 23 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 devcontainer/test-fixtures/dind-devcontainer/devcontainer.json diff --git a/devcontainer/test-fixtures/dind-devcontainer/devcontainer.json b/devcontainer/test-fixtures/dind-devcontainer/devcontainer.json new file mode 100644 index 0000000..094eb96 --- /dev/null +++ b/devcontainer/test-fixtures/dind-devcontainer/devcontainer.json @@ -0,0 +1,20 @@ +{ + "build": { + "context": "../../..", + "dockerfile": "../../../Dockerfile", + "target": "devcontainer" + }, + "overrideCommand": false, + "privileged": true, + "mounts": [ + // This allows sharing the build cache when running in GitHub Actions + "source=${localEnv:HOME}/.docker/buildx,target=/home/devcontainer/.docker/buildx,type=bind" + ], + "containerEnv": { + "SSHD_ENABLED": "true", + "SSHD_PORT": "2222", + "NODE_NAME": "localhost" + }, + "runArgs": ["--publish=2222:22"], + "postCreateCommand": [".devcontainer/post_create.sh"] +} diff --git a/devcontainer/test.sh b/devcontainer/test.sh index 8afced2..db5d094 100755 --- a/devcontainer/test.sh +++ b/devcontainer/test.sh @@ -10,7 +10,11 @@ cd "${script_dir}/.." devcontainer build --workspace-folder . -container_id=$(devcontainer up --workspace-folder . | tee /dev/stderr | jq -r .containerId) +container_id=$( + devcontainer up --workspace-folder . | + tee /dev/stderr | + jq -r .containerId +) trap 'docker rm -f "${container_id}"' EXIT @@ -20,3 +24,20 @@ devcontainer exec --workspace-folder . printenv | sort | tee /dev/stderr | grep # check if dond shim is setup correctly devcontainer exec --workspace-folder . bash -c 'DOND_SHIM_PRINT_COMMAND=true docker version' | tee /dev/stderr | grep -q '^docker.orig version$' + +docker rm -f "${container_id}" + +container_id=$( + devcontainer up --workspace-folder . --config devcontainer/test-fixtures/dind-devcontainer/devcontainer.json | + tee /dev/stderr | + jq -r .containerId +) + +devcontainer exec --workspace-folder . --config devcontainer/test-fixtures/dind-devcontainer/devcontainer.json \ + docker version + +devcontainer exec --workspace-folder . --config devcontainer/test-fixtures/dind-devcontainer/devcontainer.json \ + env IGNORE_FAILURE=false /ssh-command/get.sh + +ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR ssh://devcontainer@localhost:2222 \ + docker version From c9ccb4dbf741fdc555b821fa8dfe878696380054 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 4 Apr 2024 10:16:11 -0300 Subject: [PATCH 2/2] Remove not needed volume --- .../test-fixtures/dind-devcontainer/devcontainer.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/devcontainer/test-fixtures/dind-devcontainer/devcontainer.json b/devcontainer/test-fixtures/dind-devcontainer/devcontainer.json index 094eb96..b65076b 100644 --- a/devcontainer/test-fixtures/dind-devcontainer/devcontainer.json +++ b/devcontainer/test-fixtures/dind-devcontainer/devcontainer.json @@ -6,10 +6,6 @@ }, "overrideCommand": false, "privileged": true, - "mounts": [ - // This allows sharing the build cache when running in GitHub Actions - "source=${localEnv:HOME}/.docker/buildx,target=/home/devcontainer/.docker/buildx,type=bind" - ], "containerEnv": { "SSHD_ENABLED": "true", "SSHD_PORT": "2222",