Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GitHub codespaces and minor cleanup #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
/.tarballs
debug/

# .cache is used to store transient data (bash history) in devcontainers.
.cache/

Manifest
smartctl_exporter
*.exe
File renamed without changes.
20 changes: 20 additions & 0 deletions scripts/modify-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# 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.
# .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
File renamed without changes.