-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Campbell
committed
Jun 14, 2024
1 parent
f0b9bc5
commit 858c39d
Showing
4 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/bin/bash | ||
# | ||
# Tests and validates the k3s-on-host devcontainer feature works as expected | ||
# | ||
# Example Usage: | ||
# | ||
# "bash ./test/test.sh" | ||
|
||
set -e | ||
|
||
WORKING_DIR="$(git rev-parse --show-toplevel)" | ||
|
||
|
||
################################### | ||
# Clean the current environment by removing k3s and purging docker | ||
################################### | ||
function reset_environment() { | ||
|
||
if [[ -f "/usr/local/bin/k3s-uninstall.sh" ]]; then | ||
echo "Uninstalling k3s" | ||
sudo /usr/local/bin/k3s-uninstall.sh | ||
fi | ||
|
||
if docker ps -q | grep -q .; then | ||
echo "Preexisting containers found. Stopping and removing all containers" | ||
sudo docker stop $(docker ps -a -q) | ||
fi | ||
|
||
echo "Pruning docker" | ||
sudo docker system prune --all --volumes --force | ||
|
||
} | ||
|
||
################################### | ||
# Install the devcontainer cli so we can build the feature | ||
################################### | ||
function install_devcontainer_cli() { | ||
sudo apt install npm | ||
sudo npm cache clean -f | ||
sudo npm install -g n | ||
sudo n stable | ||
sudo npm install -g @devcontainers/cli | ||
} | ||
|
||
################################### | ||
# Deploy without cridockerd | ||
################################### | ||
function test_without_cridockerd() { | ||
sudo devcontainer build --workspace-folder "${WORKING_DIR}" --config "${WORKING_DIR}/test/without-cridockerd/devcontainer.json" | ||
sudo devcontainer up --workspace-folder "${WORKING_DIR}" --remove-existing-container \ | ||
--workspace-mount-consistency cached \ | ||
--id-label devcontainer.local_folder="${WORKING_DIR}" \ | ||
--id-label devcontainer.config_file="${WORKING_DIR}/test/without-cridockerd/devcontainer.json" \ | ||
--config "${WORKING_DIR}/test/without-cridockerd/devcontainer.json" \ | ||
--default-user-env-probe loginInteractiveShell \ | ||
--build-no-cache \ | ||
--remove-existing-container \ | ||
--mount type=volume,source=vscode,target=/vscode,external=true \ | ||
--update-remote-user-uid-default on \ | ||
--mount-workspace-git-root true | ||
|
||
sudo kubectl get namespace/default | ||
} | ||
|
||
################################### | ||
# Deploy with cridockerd | ||
################################### | ||
function test_with_cridockerd() { | ||
sudo devcontainer build --workspace-folder "${WORKING_DIR}" --config "${WORKING_DIR}/test/with-cridockerd/devcontainer.json" | ||
sudo devcontainer up --workspace-folder "${WORKING_DIR}" --remove-existing-container \ | ||
--workspace-mount-consistency cached \ | ||
--id-label devcontainer.local_folder="${WORKING_DIR}" \ | ||
--id-label devcontainer.config_file="${WORKING_DIR}/test/with-cridockerd/devcontainer.json" \ | ||
--config "${WORKING_DIR}/test/with-cridockerd/devcontainer.json" \ | ||
--default-user-env-probe loginInteractiveShell \ | ||
--build-no-cache \ | ||
--remove-existing-container \ | ||
--mount type=volume,source=vscode,target=/vscode,external=true \ | ||
--update-remote-user-uid-default on \ | ||
--mount-workspace-git-root true | ||
|
||
sudo kubectl get namespace/default | ||
} | ||
|
||
function main() { | ||
reset_environment | ||
install_devcontainer_cli | ||
|
||
test_without_cridockerd | ||
reset_environment | ||
test_with_cridockerd | ||
reset_environment | ||
|
||
echo "All tests passed" | ||
} | ||
|
||
|
||
main | ||
|
||
|
||
set +e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "k3s-on-host", | ||
"image": "mcr.microsoft.com/devcontainers/base:ubuntu22.04", | ||
"runArgs": [ | ||
"--name", | ||
"k3s-on-host" | ||
], | ||
"features": { | ||
"ghcr.io/devcontainers/features/docker-outside-of-docker": {}, | ||
"../../.devcontainer/./features/k3s-on-host": { | ||
} | ||
}, | ||
"remoteUser": "root" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "k3s-on-host", | ||
"image": "mcr.microsoft.com/devcontainers/base:ubuntu22.04", | ||
"runArgs": [ | ||
"--name", | ||
"k3s-on-host" | ||
], | ||
"features": { | ||
"ghcr.io/devcontainers/features/docker-outside-of-docker": {}, | ||
"../../.devcontainer/./features/k3s-on-host": { | ||
"criDockerd": "false" | ||
} | ||
}, | ||
"remoteUser": "root" | ||
} |