diff --git a/README.md b/README.md index 7a8d20d..86e6554 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,12 @@ I make no guarantee that features here won't break with updates etc, but I use [ If you want to create your own features, see -| Feature | Description | -| ------------------------------------------------------------ | ----------------------------------------------------------------- | -| [azure-cli-persistence](src/azure-cli-persistence/README.md) | Preserve `~/.azure` folder across instances (avoids extra logins) | -| [add-host](src/add-host/README.md) | Add a host name/ip to the dev container hosts file | -| [dev-tunnels](src/dev-tunnels/README.md) | Set up the `devtunnel` CLI for working with Dev Tunnels | -| [railway-cli](src/railway-cli/README.md) | Set up the `railway` CLI for working with [Railway](https://railway.com) projects | -| [shell-history](src/shell-history/README.md) | Preserve shell history across dev container instances/rebuilds | +| Feature | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------- | +| [azure-cli-persistence](src/azure-cli-persistence/README.md) | Preserve `~/.azure` folder across instances (avoids extra logins) | +| [add-host](src/add-host/README.md) | Add a host name/ip to the dev container hosts file | +| [dev-tunnels](src/dev-tunnels/README.md) | Set up the `devtunnel` CLI for working with Dev Tunnels | +| [github-copilot-cli](src/github-copilot-cli/README.md) | Set up the `GitHub Copilot` CLI for working with [GitHub Copilot](https://github.com/features/copilot) and persist config | +| [railway-cli](src/railway-cli/README.md) | Set up the `railway` CLI for working with [Railway](https://railway.com) projects | +| [shell-history](src/shell-history/README.md) | Preserve shell history across dev container instances/rebuilds | diff --git a/src/github-copilot-cli/NOTES.md b/src/github-copilot-cli/NOTES.md new file mode 100644 index 0000000..aad713a --- /dev/null +++ b/src/github-copilot-cli/NOTES.md @@ -0,0 +1,6 @@ + +## Changelog + +| Version | Notes | +| ------- | ------------------------------------------------------------ | +| 0.0.1 | Initial version | \ No newline at end of file diff --git a/src/github-copilot-cli/README.md b/src/github-copilot-cli/README.md new file mode 100644 index 0000000..6571876 --- /dev/null +++ b/src/github-copilot-cli/README.md @@ -0,0 +1,29 @@ + +# GitHub Copilot CLI (github-copilot-cli) + +Set up the `GitHub Copilot` CLI for working with [GitHub Copilot](https://github.com/features/copilot) and persist configuration across container instances. + +## Example Usage + +```json + "features": { + "ghcr.io/stuartleeks/dev-container-features/github-copilot-cli:0": {} + } +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| + + + +## Changelog + +| Version | Notes | +| ------- | ------------------------------------------------------------ | +| 0.0.1 | Initial version | + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/stuartleeks/dev-container-features/blob/main/src/github-copilot-cli/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ diff --git a/src/github-copilot-cli/devcontainer-feature.json b/src/github-copilot-cli/devcontainer-feature.json new file mode 100644 index 0000000..7786f9e --- /dev/null +++ b/src/github-copilot-cli/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "name": "GitHub CLI (with persistence)", + "id": "github-copilot-cli", + "version": "0.0.1", + "description": "Install GitHub CLI and configure it to store configuration in a mounted volume to preserve across container builds", + "options": {}, + "containerEnv": { + "COPILOT_HOME": "/dc/github-copilot-cli" + }, + "mounts": [ + { + "source": "${devcontainerId}-github-copilot-cli", + "target": "/dc/github-copilot-cli", + "type": "volume" + } + ], + "onCreateCommand": { + "github-copilot-cli": "/usr/local/share/stuartleeks-devcontainer-features/github-copilot-cli/scripts/oncreate.sh" + } +} \ No newline at end of file diff --git a/src/github-copilot-cli/install.sh b/src/github-copilot-cli/install.sh new file mode 100644 index 0000000..8544f98 --- /dev/null +++ b/src/github-copilot-cli/install.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/github-copilot-cli" +LIFECYCLE_SCRIPTS_DIR="$FEATURE_DIR/scripts" +LOG_FILE="$FEATURE_DIR/log.txt" + +set -e + +mkdir -p "${FEATURE_DIR}" + +echo "" > "$LOG_FILE" +log() { + echo "$1" + echo "$1" >> "$LOG_FILE" +} + +log "Activating feature 'github-copilot-cli'" +log "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" + +log "Installing GitHub Copilot CLI..." +curl -fsSL https://gh.io/copilot-install | bash +log "GitHub Copilot CLI installed" + +if [ -f oncreate.sh ]; then + mkdir -p "${LIFECYCLE_SCRIPTS_DIR}" + cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh" +fi \ No newline at end of file diff --git a/src/github-copilot-cli/oncreate.sh b/src/github-copilot-cli/oncreate.sh new file mode 100644 index 0000000..ea70917 --- /dev/null +++ b/src/github-copilot-cli/oncreate.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -e + +# NOTES +# `install.sh` +# - installs GitHub Copilot CLI via https://gh.io/copilot-install +# +# `oncreate.sh` +# - fixes permissions on the mounted volume so the user can write to it +# (COPILOT_HOME is set to /dc/github-copilot-cli via containerEnv in devcontainer-feature.json) + +FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/github-copilot-cli" +LOG_FILE="$FEATURE_DIR/log.txt" + +log() { + echo "$1" + echo "$1" >> "$LOG_FILE" +} + +if command -v sudo > /dev/null; then + SUDO="sudo" +else + SUDO="" +fi + +$SUDO chown -R "$(id -u):$(id -g)" "$LOG_FILE" + +log "In OnCreate script" +if [ -f "$FEATURE_DIR/markers/oncreate" ]; then + log "Feature 'github-copilot-cli' oncreate actions already run, skipping" + exit 0 +fi + +if [ ! -w "/dc/github-copilot-cli" ]; then + log "Fixing permissions of '/dc/github-copilot-cli'..." + $SUDO chown -R "$(id -u):$(id -g)" "/dc/github-copilot-cli" + log "Done!" +else + log "Permissions of '/dc/github-copilot-cli' are OK!" +fi + +log "Adding marker file to indicate oncreate actions have been run" +$SUDO mkdir -p "$FEATURE_DIR/markers" +$SUDO touch "$FEATURE_DIR/markers/oncreate" + +log "Done" + diff --git a/test-project/.devcontainer/devcontainer.json b/test-project/.devcontainer/devcontainer.json index b323bfe..e61cf98 100644 --- a/test-project/.devcontainer/devcontainer.json +++ b/test-project/.devcontainer/devcontainer.json @@ -20,5 +20,7 @@ "ghcr.io/azure/azure-dev/azd:0": {}, "./src/azd-cli-persistence": {}, // "./src/dev-tunnels" : {} + // "./src/railway-cli": {} + "./src/github-copilot-cli": {} } }