Skip to content
Closed
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
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
],
// Mount the parent as /workspaces so we can pip install peers as editable
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/devcontainer_rc"
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/devcontainer_rc",
"remoteUser": "root"
}
27 changes: 8 additions & 19 deletions .devcontainer/features/bash-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@

## Defaults

When this feature is first called, onCreateCommand.sh is created and called in `devcontainer-feature`.
This creates and installs a default bash terminal configuration from `feature_settings_rc` which contains opinionated default BASH terminal settings such as:
* A minimalist, blue bash prompt.
* Eternal, shared history between containers using this feature.

## Customisation

The user can specify their own terminal preferences in `$CONFIG_STAGING/bashrc`, which defaults to `/devcontainer_staging/bashrc`.
Then the container is rebuilt, if `bashrc` already exists it won't be overwritten, preserving changes. If the container has been built once already, the existing bashrc must be deleted in order for your changes to be applied.
The default, opinionated configuration is defined in
`$HOME/.config/bash-config/bash-config-rc` and includes the following:

- Persistent history across all devcontainers that use this feature
- The MS devcontainer bash prompt with git branch and status
- history search with up/down arrows (.inputrc)
- ctrl-left or right arrow for word navigation (.inputrc)

## Customisation

creates staging folder in container
creates onCreateCommand.sh in the staging folder
inputrc and bashrc are also created in the staging folder, containing incremental history searching and user customisations respectively
feature_settings_rc is created in the staging fodler, which contains a PS1 setup and opinionated terminal features
"onCreateCommand" is then exectuted inside the container during finalisation of container setup.
- This copies the contents of feature_settings_rc into devcontainer_rc
- then copies bashrc and inputrc into the container, unless they exist already to prevent overwriting user edits
- then adds root permissions.
A symbolic link to /root/ is created The items in the CONFIG_FOLDER
our bashrc is called by /root/.bashrc
Can be customized by editing `$HOME/.config/bash-config/bashrc`
12 changes: 12 additions & 0 deletions .devcontainer/features/bash-config/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# This bashrc will be source from /root/.bashrc upon launch of every terminal
# in a devcontainer that uses the bash-config feature from
# https://github.com/DiamondLightSource/devcontainer-features

# This file is initialized by bash-config, but you are then free to edit it

# execute default, opinionated settings - delete this line to remove defaults
source $CONFIG_FOLDER/feature_settings_rc

# add your personal custom settings below
5 changes: 3 additions & 2 deletions .devcontainer/features/bash-config/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "Lightweight and configurable BASH eternal history",
//ID *must* match parent folder name *exactly*
"id": "bash-config",
"version": "1.0.0",
// a default beta version that is replaced by CI when doing tagged releases
"version": "0.0.1-b1",
"description": "Lightweight BASH setup with eternal history and PS1 tweaks. Fully configurable.",
"documentationURL": "https://github.com/DiamondRC/devcontainer-features/refs/heads/main/.devcontainer/features/bash-config/README.md",
"containerEnv": {
Expand All @@ -17,4 +18,4 @@
}
],
"onCreateCommand": "bash /devcontainer_staging/onCreateCommand.sh"
}
}
14 changes: 14 additions & 0 deletions .devcontainer/features/bash-config/feature_settings_rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# default opinioned bash configuration

# set the prompt
export PS1="\[\033[1;34m\]\W \[\033[0m\]# "

# enable enternal shared history
export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=-1
export HISTFILESIZE=-1
export SAVEHIST=-1
export HISTFILE=$CONFIG_FOLDER/.bash_eternal_history
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
10 changes: 10 additions & 0 deletions .devcontainer/features/bash-config/inputrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Readline configuration for bash shell.

# Incremental history searching with up and down arrows (C-P and C-N for old
# style navigation).
"\e[A": history-search-backward
"\e[B": history-search-forward

# Control left and right for word movement
"\e[5C": forward-word
"\e[5D": backward-word
80 changes: 17 additions & 63 deletions .devcontainer/features/bash-config/install.sh
Original file line number Diff line number Diff line change
@@ -1,71 +1,25 @@
#!/bin/bash
set -e

echo "Activating feature 'terminal-history'"
echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}"

mkdir -p $CONFIG_STAGING

# -------------------------------------------------------------------------------
cat > $CONFIG_STAGING/onCreateCommand.sh \
<< EOF
#!/bin/bash

# copy in the opinionated default settings from the feature
cp $CONFIG_STAGING/feature_settings_rc $CONFIG_FOLDER/feature_settings_rc

# copy in the user editable settings unless they already exist
if [[ ! -f $CONFIG_FOLDER/bashrc ]] ; then
cp $CONFIG_STAGING/bashrc $CONFIG_FOLDER
cp $CONFIG_STAGING/inputrc $CONFIG_FOLDER
fi

# hook in the config to the root account
ln -s $CONFIG_FOLDER/inputrc /root/.inputrc
echo "source $CONFIG_FOLDER/bashrc" >> /root/.bashrc
EOF

# -------------------------------------------------------------------------------
cat > $CONFIG_STAGING/inputrc \
<< EOF
# Readline configuration for bash shell.

# Incremental history searching with up and down arrows (C-P and C-N for old
# style navigation).
"\e[A": history-search-backward
"\e[B": history-search-forward

# Control left and right for word movement
"\e[5C": forward-word
"\e[5D": backward-word
EOF

# -------------------------------------------------------------------------------
cat > $CONFIG_STAGING/bashrc \
<< EOF
#!/bin/bash
# abort on error
set -e

# execute default opinionated settings - delete this line to remove defaults
source $CONFIG_FOLDER/feature_settings_rc
# discover where the install.sh and peers have been extracted to
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# add your personal custom settings below
EOF

# -------------------------------------------------------------------------------
cat > $CONFIG_STAGING/feature_settings_rc \
<< EOF
#!/bin/bash
echo "Activating feature 'terminal-history'"
echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}"

# default opinioned bash configuration
# This script is run at container build time.
#
# Here we place all the configuration files in a staging area.
#
# Then at container runtime, when the hosts' config folder is mounted in, we
# can copy from the staging area to the mounted host folder
#
# The runtime copy to host folder is performed once oby onCreateCommand.sh

# set the prompt
export PS1="\[\033[1;34m\]\W \[\033[0m\]# "
mkdir -p "$CONFIG_STAGING"
cp -r "$this_dir"/* "$CONFIG_STAGING"
echo $this_dir > "$CONFIG_STAGING/this_dir"

# enable enternal shared history
export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=-1
export HISTFILESIZE=-1
export SAVEHIST=-1
export HISTFILE=$CONFIG_FOLDER/.bash_eternal_history
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
EOF
16 changes: 16 additions & 0 deletions .devcontainer/features/bash-config/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# this script is run once inside the developer container at creation time

# copy in the opinionated default settings from the feature
cp $CONFIG_STAGING/feature_settings_rc $CONFIG_FOLDER/feature_settings_rc

# copy in the user editable settings unless they already exist
if [[ ! -f $CONFIG_FOLDER/bashrc ]] ; then
cp $CONFIG_STAGING/bashrc $CONFIG_FOLDER
cp $CONFIG_STAGING/inputrc $CONFIG_FOLDER
fi

# hook in the config to the root account
ln -s $CONFIG_FOLDER/inputrc /root/.inputrc
echo "source $CONFIG_FOLDER/bashrc" >> /root/.bashrc
16 changes: 14 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: "Release dev container features & Generate Documentation"
on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -13,13 +15,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: patch in version tag
# patch the version tag if the version is a valid semver. If not the
# default to the
run: |
if [[ ${{ github.ref_name }} =~ ^[0-9]+\.[0-9]+.+ ]] ; then
sed -i s/0\.0\.0-b1/${{ github.ref_name }}/ $(find .devcontainer -name devcontainer-feature.json)
# dump the modified json for debugging
cat $(find .devcontainer -name devcontainer-feature.json)
fi

- name: "Publish Features"
uses: devcontainers/action@v1
with:
publish-features: "true"
base-path-to-features: "./src"
generate-docs: "true"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
35 changes: 2 additions & 33 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: "CI - Test Features"
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
test-autogenerated:
Expand All @@ -13,7 +10,7 @@ jobs:
strategy:
matrix:
features:
- terminal-history
- bash-config
baseImage:
- debian:latest
- ubuntu:latest
Expand All @@ -24,35 +21,7 @@ jobs:
run: |
npm install -g @devcontainers/cli
mkdir -p ~/.config/devcontainer_rc

- name: "Generating tests for '${{ matrix.features }}' against '${{ matrix.baseImage }}'"
run: devcontainer features test --skip-scenarios -f ${{ matrix.features }} -i ${{ matrix.baseImage }} .

# test-scenarios:
# runs-on: ubuntu-latest
# continue-on-error: true
# strategy:
# matrix:
# features:
# - color
# - hello
# steps:
# - uses: actions/checkout@v4
#
# - name: "Install latest devcontainer CLI"
# run: npm install -g @devcontainers/cli
#
# - name: "Generating tests for '${{ matrix.features }}' scenarios"
# run: devcontainer features test -f ${{ matrix.features }} --skip-autogenerated --skip-duplicated .
#
# test-global:
# runs-on: ubuntu-latest
# continue-on-error: true
# steps:
# - uses: actions/checkout@v4
#
# - name: "Install latest devcontainer CLI"
# run: npm install -g @devcontainers/cli
#
# - name: "Testing global scenarios"
# run: devcontainer features test --global-scenarios-only .
Loading