Skip to content

Commit e293ab7

Browse files
authored
Add personal-setup feature (#1)
This feature installs my desired packages (including `rcm`), and mounts and sets up my dotfiles folders on devcontainer creation. - Add `personal-setup` feature and tests - Add GitHub Actions workflows - Add mise configuration for tools and tasks
1 parent d430336 commit e293ab7

File tree

10 files changed

+246
-0
lines changed

10 files changed

+246
-0
lines changed

.github/workflows/release.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Release"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
name: "Release to GHCR"
11+
if: ${{ github.ref == 'refs/heads/main' }}
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@v6
19+
20+
- name: "Publish features"
21+
uses: devcontainers/action@v1
22+
with:
23+
publish-features: "true"
24+
base-path-to-features: "./src"
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Test"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
docs:
12+
name: "Ensure documentation has been generated"
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v6
16+
17+
- name: "Install devcontainer CLI"
18+
run: npm install -g @devcontainers/cli
19+
20+
- name: "Generate docs"
21+
run: devcontainer features generate-docs -p src -n csutter/devcontainer-features
22+
23+
- name: "Verify docs are up to date"
24+
run: git diff --quiet -- */**/README.md
25+
26+
shellcheck:
27+
name: Shellcheck
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v6
31+
32+
- name: Run ShellCheck
33+
uses: ludeeus/action-shellcheck@2.0.0
34+
35+
test:
36+
name: "Test ${{ matrix.feature }} on ${{ matrix.baseImage }}"
37+
runs-on: ubuntu-latest
38+
continue-on-error: true
39+
strategy:
40+
matrix:
41+
feature:
42+
- personal-setup
43+
baseImage:
44+
# Vanilla distribution images
45+
- docker.io/library/debian:latest
46+
- docker.io/library/ubuntu:latest
47+
- quay.io/fedora/fedora-toolbox:latest
48+
# Microsoft devcontainer base image
49+
- mcr.microsoft.com/devcontainers/base:ubuntu
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
# The personal-setup feature requires my dotfiles folders to be present in the expected
54+
# location, so clone the public repo to simulate this, and fake the private repo mount.
55+
- name: "Prepare demo dotfiles mounts"
56+
run: |
57+
mkdir -p $HOME/src/csutter
58+
mkdir $HOME/src/csutter/dotfiles-private
59+
git clone https://github.com/csutter/dotfiles.git $HOME/src/csutter/dotfiles
60+
61+
- name: "Install devcontainer CLI"
62+
run: npm install -g @devcontainers/cli
63+
64+
- name: "Test feature: ${{ matrix.feature }} on ${{ matrix.baseImage }}"
65+
run: devcontainer features test --features ${{ matrix.feature }} --base-image ${{ matrix.baseImage }}

.shellcheckrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Don't follow external sources
2+
disable=SC1091

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# devcontainer-features
22
Feature definitions for my containerised development environments
3+
4+
> [!CAUTION]
5+
> This repository contains assorted devcontainer features meant to be used by _me_ personally:
6+
> * as default features for all (own and third party) devcontainers I run, or
7+
> * as features in specific devcontainers for my own personal projects
8+
>
9+
> You may or may not get much mileage out of using them directly, and any or all features may not be
10+
> stable, continue to provide the same functionality in the long run, always be available on
11+
> `ghcr.io`, or even work on anyone else's machine!
12+
>
13+
> I therefore recommend that you use this repository as inspiration for your own features, and do
14+
> not rely on them directly.
15+
16+
## Features
17+
* [`personal-setup`](src/personal-setup/): Sets up tooling and dotfiles for any arbitrary devcontainer

mise.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[tools]
2+
node = "24"
3+
"npm:@devcontainers/cli" = "0.80"
4+
"github:koalaman/shellcheck" = "v0.11.0"
5+
6+
[tasks.docs]
7+
description = "Generate documentation for all features"
8+
# Note: The `generate-docs` command documentation wrongly suggests -p should be the root of the
9+
# repo, but it should be the src/ directory.
10+
run = "devcontainer features generate-docs -p src -n csutter/devcontainer-features"
11+
12+
[tasks.lint-shell]
13+
description = "Lint all shell scripts using ShellCheck"
14+
run = "find . -name '*.sh' -print0 | xargs -0 shellcheck"
15+
16+
[tasks.test]
17+
description = "Run tests for all features"
18+
run = [
19+
"devcontainer features test -i docker.io/library/debian:latest",
20+
"devcontainer features test -i docker.io/library/ubuntu:latest",
21+
"devcontainer features test -i quay.io/fedora/fedora-toolbox:latest",
22+
"devcontainer features test -i mcr.microsoft.com/devcontainers/base:ubuntu",
23+
]

src/personal-setup/NOTES.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
I have a set of preferred tools that I want available in any devcontainer, as well as several
2+
dotfiles repositories to configure my desired development environment.
3+
4+
I've previously (ab)used the _Dev Containers_ extension's built in dotfiles support, but it:
5+
- doesn't allow multiple dotfiles repositories (a key use case for me)
6+
- relies on an install script in the repository (which feels like an unsuitable concern for a
7+
repository of configuration files)
8+
- clones the repository from origin every time (which requires SSH agent confirmation and needs
9+
"human in the loop" during setup, and means changes on the host don't get picked up until push and
10+
a full container rebuild)
11+
12+
This feature:
13+
- Installs a set of packages in the container (including `rcm` for dotfiles management)
14+
- Mounts my dotfiles repositories into the container
15+
- Installs the dotfiles (with appropriate tags)
16+
17+
This feature is intended to be configured as part of my personal user settings as a default feature
18+
for all devcontainers (through `dev.containers.defaultFeatures`). It's obviously specific to me,
19+
and coupled to my canonical directory layout and dotfiles repositories.

src/personal-setup/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# Personal Setup (personal-setup)
3+
4+
Sets up my desired software and configuration for any devcontainer environment.
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/csutter/devcontainer-features/personal-setup:1": {}
11+
}
12+
```
13+
14+
15+
16+
I have a set of preferred tools that I want available in any devcontainer, as well as several
17+
dotfiles repositories to configure my desired development environment.
18+
19+
I've previously (ab)used the _Dev Containers_ extension's built in dotfiles support, but it:
20+
- doesn't allow multiple dotfiles repositories (a key use case for me)
21+
- relies on an install script in the repository (which feels like an unsuitable concern for a
22+
repository of configuration files)
23+
- clones the repository from origin every time (which requires SSH agent confirmation and needs
24+
"human in the loop" during setup, and means changes on the host don't get picked up until push and
25+
a full container rebuild)
26+
27+
This feature:
28+
- Installs a set of packages in the container (including `rcm` for dotfiles management)
29+
- Mounts my dotfiles repositories into the container
30+
- Installs the dotfiles (with appropriate tags)
31+
32+
This feature is intended to be configured as part of my personal user settings as a default feature
33+
for all devcontainers (through `dev.containers.defaultFeatures`). It's obviously specific to me,
34+
and coupled to my canonical directory layout and dotfiles repositories.
35+
36+
37+
---
38+
39+
_Note: This file was auto-generated from the [devcontainer-feature.json](devcontainer-feature.json). Add additional notes to a `NOTES.md`._
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"id": "personal-setup",
3+
"version": "1.0.0",
4+
"name": "Personal Setup",
5+
"description": "Sets up my desired software and configuration for any devcontainer environment.",
6+
"mounts": [
7+
{
8+
"type": "bind",
9+
"source": "${localEnv:HOME}/src/csutter/dotfiles",
10+
"target": "/mnt/dotfiles"
11+
},
12+
{
13+
"type": "bind",
14+
"source": "${localEnv:HOME}/src/csutter/dotfiles-private",
15+
"target": "/mnt/dotfiles-private"
16+
}
17+
],
18+
"containerEnv": {
19+
"RCRC": "/mnt/dotfiles/tag-devcontainer/rcrc"
20+
},
21+
"postCreateCommand": "rcup -vf"
22+
}

src/personal-setup/install.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/bash
2+
set -e
3+
4+
if [ -f /etc/os-release ]; then
5+
. /etc/os-release
6+
else
7+
echo "Error: Cannot detect distribution (no /etc/os-release)"
8+
exit 1
9+
fi
10+
11+
echo "Installing packages for distribution: $ID"
12+
case "$ID" in
13+
debian|ubuntu)
14+
apt-get update
15+
apt-get install -y rcm
16+
;;
17+
fedora)
18+
dnf install -y rcm
19+
;;
20+
*)
21+
echo "Error: Unsupported distribution: $ID"
22+
echo "This feature supports: debian, ubuntu, fedora"
23+
exit 1
24+
;;
25+
esac

test/personal-setup/test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "rcm is available" bash -c "which rcup"
7+
# Use a dotfile that should _always_ be present on any system
8+
check "dotfiles are installed" bash -c "test -f $HOME/.config/fish/config.fish"
9+
10+
reportResults

0 commit comments

Comments
 (0)