From 07123686680c4ac3675edd59a2e005c93a9ef16a Mon Sep 17 00:00:00 2001 From: Willie Date: Mon, 2 Mar 2026 09:27:50 +0800 Subject: [PATCH] feat(devc): add `make devc` shortcut to enter devcontainer from terminal Adds scripts/devcontainer_shell.sh that detects a running devcontainer and opens an interactive shell (or runs a one-off command). Registered as `make devc` / `mise run devc`. Also consolidates README recent updates to one entry per minor series and updates the devcontainer skill with the new entry point. --- .skillshare/skills/devcontainer/SKILL.md | 13 +++++++++- Makefile | 6 ++++- README.md | 3 +-- mise.toml | 5 ++++ scripts/devcontainer_shell.sh | 30 ++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100755 scripts/devcontainer_shell.sh diff --git a/.skillshare/skills/devcontainer/SKILL.md b/.skillshare/skills/devcontainer/SKILL.md index 9a1d752bd..e8fa963ab 100644 --- a/.skillshare/skills/devcontainer/SKILL.md +++ b/.skillshare/skills/devcontainer/SKILL.md @@ -55,7 +55,18 @@ Source code is bind-mounted into the container at `/workspace`. The `ss` wrapper This also applies to `go test` — tests always compile against the latest source. The Web UI backend uses `air` for hot-reload (same zero-rebuild experience). -## Step 0: Ensure Devcontainer is Running +## Entering the Devcontainer + +The quickest way to get an interactive shell inside the devcontainer: + +```bash +make devc # interactive bash shell +./scripts/devcontainer_shell.sh make test # run a command directly +``` + +The script auto-detects whether the container is running and prints setup instructions if it isn't. + +### Programmatic access (for `docker exec` workflows) ```bash CONTAINER=$(docker compose -f .devcontainer/docker-compose.yml ps -q skillshare-devcontainer 2>/dev/null) diff --git a/Makefile b/Makefile index 2bf1c3b9a..aa2aa5225 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: help build build-meta build-windows run test test-unit test-int test-docker test-docker-online test-redteam test-redteam-signal test-redteam-rules-signal playground playground-down dev-docker dev-docker-down docker-build docker-build-multiarch lint fmt fmt-check check install clean ui-install ui-build ui-dev build-all +.PHONY: help build build-meta build-windows run test test-unit test-int test-docker test-docker-online test-redteam test-redteam-signal test-redteam-rules-signal playground playground-down devc dev-docker dev-docker-down docker-build docker-build-multiarch lint fmt fmt-check check install clean ui-install ui-build ui-dev build-all help: @echo "Common tasks:" @@ -14,6 +14,7 @@ help: @echo " make test-redteam-rules-signal # verify red team test fails when critical builtin rules are disabled" @echo " make playground # start playground + enter shell (one step)" @echo " make playground-down # stop and remove playground" + @echo " make devc # enter running devcontainer shell" @echo " make lint # go vet" @echo " make fmt # format Go files" @echo " make check # fmt-check + lint + test" @@ -72,6 +73,9 @@ playground: playground-down: ./scripts/sandbox_playground_down.sh +devc: + ./scripts/devcontainer_shell.sh + dev-docker: docker compose -f docker-compose.sandbox.yml --profile dev watch diff --git a/README.md b/README.md index 27ad6cbaf..95811b825 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,7 @@ > [!NOTE] > **Recent Updates** -> - **[0.16.7](https://github.com/runkids/skillshare/releases/tag/v0.16.7)**: Dotfiles manager compatibility — sync preserves external symlinks on source and target directories (stow, chezmoi, yadm). -> - **[0.16.*](https://github.com/runkids/skillshare/releases/tag/v0.16.6)**: Performance overhaul, interactive TUI for diff/restore/trash, file-level diff, glob matching, Homebrew-aware upgrade. +> - **[0.16.*](https://github.com/runkids/skillshare/releases/tag/v0.16.7)**: Performance overhaul, interactive TUI for diff/restore/trash, file-level diff, glob matching, Homebrew-aware upgrade, dotfiles manager compatibility. > - Full history: [All Releases](https://github.com/runkids/skillshare/releases) ## Why skillshare diff --git a/mise.toml b/mise.toml index 21abab314..26781aa52 100644 --- a/mise.toml +++ b/mise.toml @@ -16,6 +16,7 @@ echo " mise run test:docker:online # docker online install/update tests" echo " mise run test:redteam # red team supply-chain security tests" echo " mise run playground # start playground + enter shell (one step)" echo " mise run playground:down # stop and remove playground" +echo " mise run devc # enter running devcontainer shell" echo " mise run lint # go vet" echo " mise run fmt # format Go files" echo " mise run check # fmt:check + lint + test" @@ -85,6 +86,10 @@ run = """ description = "Stop and remove playground container" run = "./scripts/sandbox_playground_down.sh" +[tasks.devc] +description = "Enter running devcontainer shell" +run = "./scripts/devcontainer_shell.sh" + [tasks."dev:docker"] description = "Go API in Docker + auto-rebuild (pair with: cd ui && pnpm run dev)" run = "docker compose -f docker-compose.sandbox.yml --profile dev watch" diff --git a/scripts/devcontainer_shell.sh b/scripts/devcontainer_shell.sh new file mode 100755 index 000000000..6044db304 --- /dev/null +++ b/scripts/devcontainer_shell.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Enter the running devcontainer or execute a command inside it. +# Usage: +# ./scripts/devcontainer_shell.sh # interactive shell +# ./scripts/devcontainer_shell.sh make test # run a command +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +# Reuse require_docker from sandbox common, then override COMPOSE_FILE. +source "$SCRIPT_DIR/_sandbox_common.sh" +require_docker + +COMPOSE_FILE="$PROJECT_ROOT/.devcontainer/docker-compose.yml" +SERVICE="skillshare-devcontainer" + +if [[ -z "$(docker compose -f "$COMPOSE_FILE" ps -q "$SERVICE" 2>/dev/null || true)" ]]; then + echo "Devcontainer is not running." >&2 + echo "Start it with one of:" >&2 + echo " 1. VS Code → 'Reopen in Container'" >&2 + echo " 2. docker compose -f .devcontainer/docker-compose.yml up -d" >&2 + exit 1 +fi + +if [[ $# -gt 0 ]]; then + docker compose -f "$COMPOSE_FILE" exec -w /workspace "$SERVICE" bash -c "$*" +else + docker compose -f "$COMPOSE_FILE" exec -w /workspace "$SERVICE" bash +fi