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

Refactor postAttachCommand #2312

Merged
merged 3 commits into from
Jan 30, 2024
Merged
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
7 changes: 2 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
// To access grafana
"appPort": "3000:3000",

// Persist zsh history settings below
// overwrite HISTFILE to store history file in the named volume defined below
// also setting INC_APPEND_HISTORY to immediately flush command history to the file to keep history when rebuilding the devcontainer
"postStartCommand": "echo 'export HISTFILE=/commandhistory/.zsh_history' >> /root/.zshrc && echo 'setopt INC_APPEND_HISTORY' >> /root/.zshrc",
// define named volume to store zsh history file
"mounts": ["source=zshhistory-named-volume,target=/commandhistory,type=volume"],
"postAttachCommand": "mkdir -p /etc/server && ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml"

"postAttachCommand": ["/bin/bash", ".devcontainer/postAttachCommand.sh"]
}
35 changes: 35 additions & 0 deletions .devcontainer/postAttachCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash -eu
#
# This script is executed as postAttachCommand in devcontainer.json
# This script does...
# - create symbolic link of config.yaml for easier development
# - add command history setting to .zshrc to persist history
#

echo "creating symbolic link of config ZSHRC..."

LINK_TARGET="$(pwd)/cmd/agent/core/ngt/sample.yaml"
LINK_SRC="/etc/server/config.yaml"

mkdir -p /etc/server

if [ ! -e "$LINK_SRC" ]; then
ln -s "$LINK_TARGET" "$LINK_SRC"
echo "created symbolic link: $LINK_SRC -> $LINK_TARGET"
else
echo "$LINK_SRC already exists"
fi


echo "adding history setting to .zshrc..."

LINE1="export HISTFILE=/commandhistory/.zsh_history"
LINE2="setopt INC_APPEND_HISTORY"

ZSHRC="/root/.zshrc"

# write only if those lines don't exist
grep -qxF "$LINE1" "$ZSHRC" || echo "$LINE1" >> "$ZSHRC"
grep -qxF "$LINE2" "$ZSHRC" || echo "$LINE2" >> "$ZSHRC"

echo "added history setting to .zshrc"
Loading