From 715f3a465c33e72b1c3e8badd558b3b153a1166b Mon Sep 17 00:00:00 2001 From: David Randall Date: Tue, 21 Nov 2023 01:05:13 +0000 Subject: [PATCH 1/4] Add: Devcontainer support Signed-off-by: David Randall --- .devcontainer/devcontainer.json | 38 +++++++++++++++++++++++++++++++++ .gitignore | 3 +++ scripts/modify-environment.sh | 20 +++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 scripts/modify-environment.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..6591822 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,38 @@ +{ + "name": "Default dev container", + "image": "mcr.microsoft.com/devcontainers/go:1.20", + // GitHub's devcontainers are in increments of 2 core/8GB memory. Specifying less will use the minimum. + // https://docs.github.com/en/billing/managing-billing-for-github-codespaces/about-billing-for-github-codespaces#pricing-for-paid-usage + "hostRequirements": { + "cpus": 1, + "memory": "4gb" + }, + "waitFor": "onCreateCommand", + "updateContentCommand": { + "install": "sudo apt-get update && sudo apt-get install --no-install-recommends -y smartmontools vim", + // Modify the environment to provide better developer experience. + "modify-environment": "${PWD}/scripts/modify-environment.sh" + }, + "postCreateCommand": { + }, + "customizations": { + "codespaces": { + // Open files upon start + "openFiles": [ + "metrics.go", + "smartctl.go" + ] + }, + "vscode": { + // VS Code extensions to install + "extensions": [ + "streetsidesoftware.code-spell-checker", + "timonwong.shellcheck", + "golang.Go" + ], + "settings": { + "shellcheck.customArgs": ["-x"] + } + } + } +} diff --git a/.gitignore b/.gitignore index 930cf26..2533db1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ /.tarballs debug/ +# .cache is used to store transient data (bash history) in devcontainers. +.cache/ + Manifest smartctl_exporter *.exe diff --git a/scripts/modify-environment.sh b/scripts/modify-environment.sh new file mode 100644 index 0000000..d8050b2 --- /dev/null +++ b/scripts/modify-environment.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script modifies the environemnt, namely ~/.bashrc, to preserve the bash history. + +# The workspace in the devcontainer is preserved across rebuilds. +# Use .cache to keep history and local scripts. +# .cache is excluded from git (i.e. in .gitignore) +mkdir -p "${PWD}/.cache/" + +# Preserve history +[[ ! -L "${HOME}/.bash_history" ]] && ln -sf "${PWD}/.cache/bash_history" "${HOME}/.bash_history" +[[ ! -f "${PWD}/.cache/bash_history" ]] && touch "${PWD}/.cache/bash_history" + +# Write history after every command to preserve it across rebuilds. +if ! grep -q '^### CUSTOM: Preserve Bash History ###$' "${HOME}/.bashrc"; then + cat >> "${HOME}/.bashrc" <<'EOT' +### CUSTOM: Preserve Bash History ### +PROMPT_COMMAND="history -a; ${PROMPT_COMMAND}" +EOT +fi From c06e503392cd5a3f5d3369f0b2f6ac7bb46c31ba Mon Sep 17 00:00:00 2001 From: David Randall Date: Tue, 21 Nov 2023 01:08:45 +0000 Subject: [PATCH 2/4] Add: Devcontainer support Signed-off-by: David Randall --- scripts/modify-environment.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/modify-environment.sh diff --git a/scripts/modify-environment.sh b/scripts/modify-environment.sh old mode 100644 new mode 100755 From b44edca7baed88ed07060672ed92412702907d6c Mon Sep 17 00:00:00 2001 From: David Randall Date: Tue, 21 Nov 2023 20:05:02 -0500 Subject: [PATCH 3/4] Add support for GitHub codespaces and minor cleanup Chg: Add support for GitHub codespaces (devcontainers) Chg: Minor cleanup Signed-off-by: David Randall --- collect-smartctl-json.sh => scripts/collect-smartctl-json.sh | 0 redact_fake_json.py => scripts/redact_fake_json.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename collect-smartctl-json.sh => scripts/collect-smartctl-json.sh (100%) rename redact_fake_json.py => scripts/redact_fake_json.py (100%) diff --git a/collect-smartctl-json.sh b/scripts/collect-smartctl-json.sh similarity index 100% rename from collect-smartctl-json.sh rename to scripts/collect-smartctl-json.sh diff --git a/redact_fake_json.py b/scripts/redact_fake_json.py similarity index 100% rename from redact_fake_json.py rename to scripts/redact_fake_json.py From 09277dd33d3df05195de79400180abccf3a641a1 Mon Sep 17 00:00:00 2001 From: David Randall Date: Tue, 21 Nov 2023 20:31:07 -0500 Subject: [PATCH 4/4] Fix: Spelling Signed-off-by: David Randall --- scripts/modify-environment.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/modify-environment.sh b/scripts/modify-environment.sh index d8050b2..100d7c0 100755 --- a/scripts/modify-environment.sh +++ b/scripts/modify-environment.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# This script modifies the environemnt, namely ~/.bashrc, to preserve the bash history. +# This script modifies the environment, namely ~/.bashrc, to preserve the bash history. # The workspace in the devcontainer is preserved across rebuilds. # Use .cache to keep history and local scripts.