Skip to content

Commit c7e1236

Browse files
committed
Added initial structure
1 parent 2d8c852 commit c7e1236

File tree

9 files changed

+283
-0
lines changed

9 files changed

+283
-0
lines changed

.devcontainer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// For format details, see https://containers.dev/implementors/json_reference/
2+
{
3+
"name": "Ubuntu Developer Container",
4+
"build": {
5+
"dockerfile": "Dockerfile"
6+
},
7+
"remoteEnv": {
8+
// Allow X11 apps to run inside the container
9+
"DISPLAY": "${localEnv:DISPLAY}",
10+
},
11+
// Create the config folder for the bash-config feature
12+
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config",
13+
"runArgs": [
14+
// Allow the container to access the host X11 display and EPICS CA
15+
"--net=host",
16+
// Make sure SELinux does not disable with access to host filesystems like tmp
17+
"--security-opt=label=disable"
18+
],
19+
// Populate the user's terminal config folder with default config if it is blank
20+
"onCreateCommand": "/root/terminal-config/ensure-user-terminal-config.sh",
21+
"mounts": [
22+
// Mount in the user terminal config folder so it can be edited
23+
{
24+
"source": "${localEnv:HOME}/.config/terminal-config",
25+
"target": "/user-terminal-config",
26+
"type": "bind"
27+
},
28+
// Keep a persistent cross container cache
29+
{
30+
"source": "${localEnv:HOME}/.cache",
31+
"target": "/root/.cache",
32+
"type": "bind"
33+
}
34+
],
35+
// Mount the parent as /workspaces so we can pip install peers as editable
36+
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
37+
}

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '*'
9+
pull_request:
10+
11+
jobs:
12+
13+
build_container:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
# Need this to get version number from last tag
21+
fetch-depth: 0
22+
23+
- name: Set up Docker Buildx
24+
id: buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Log in to GitHub Docker Registry
28+
if: github.event_name != 'pull_request'
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Build and export to Docker local cache
36+
uses: docker/build-push-action@v6
37+
env:
38+
DOCKER_BUILD_RECORD_UPLOAD: false
39+
with:
40+
context: .
41+
# Need load and tags so we can test it below
42+
load: true
43+
tags: tag_for_testing
44+
45+
- name: Test cli works in cached runtime image
46+
run: docker run --rm tag_for_testing uvx pycowsay 'hello ubuntu-devcontainer!'
47+
48+
- name: Create tags for publishing image
49+
id: meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ghcr.io/${{ github.repository }}
53+
tags: |
54+
type=ref,event=tag
55+
type=raw,value=latest
56+
57+
- name: Create tags for publishing debug image
58+
id: debug-meta
59+
uses: docker/metadata-action@v5
60+
with:
61+
images: ghcr.io/${{ github.repository }}
62+
tags: |
63+
type=ref,event=tag,suffix=-debug
64+
type=raw,value=latest-debug
65+
66+
- name: Push cached image to container registry
67+
if: github.ref_type == 'tag'
68+
uses: docker/build-push-action@v6
69+
env:
70+
DOCKER_BUILD_RECORD_UPLOAD: false
71+
# This does not build the image again, it will find the image in the
72+
# Docker cache and publish it
73+
with:
74+
context: .
75+
push: true
76+
tags: ${{ steps.meta.outputs.tags }}
77+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# The devcontainer should use the developer target and run as root with podman
2+
# or docker with user namespaces.
3+
FROM ubuntu:noble-20250714
4+
5+
# Add any system dependencies for the developer/build environment here
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
build-essential \
8+
ca-certificates \
9+
curl \
10+
git \
11+
graphviz \
12+
man \
13+
ssh-client
14+
15+
# Copy in the default bash configuration
16+
COPY terminal-config /root/terminal-config
17+
ENV USER_TERMINAL_CONFIG=/user-terminal-config
18+
19+
# Make sure that $USER_TERMINAL_CONFIG exists so we can link to it
20+
# and add hooks to all the files we reference
21+
# This can be overridden by the user mounting a different folder over the top
22+
RUN /root/terminal-config/ensure-user-terminal-config.sh && \
23+
ln -fs $USER_TERMINAL_CONFIG/inputrc /root/.inputrc && \
24+
echo 'source ${USER_TERMINAL_CONFIG}/bashrc' >> /root/.bashrc && \
25+
echo 'source ${USER_TERMINAL_CONFIG}/zshrc' >> /root/.zshrc
26+
27+
# Install uv using the official image
28+
# See https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
29+
COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /uvx /bin/

terminal-config/bashrc-default

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# default opinioned bash configuration to be sourced from user's bashrc
4+
5+
# enable enternal shared history
6+
export HISTCONTROL=ignoreboth:erasedups
7+
export HISTSIZE=-1
8+
export HISTFILESIZE=-1
9+
export SAVEHIST=-1
10+
export HISTFILE=$USER_TERMINAL_CONFIG/.bash_eternal_history
11+
export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
12+
13+
# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/dst.zsh-theme
14+
# from https://github.com/devcontainers/features/blob/main/src/common-utils/scripts/bash_theme_snippet.sh
15+
__bash_prompt() {
16+
local userpart='`export XIT=$? \
17+
&& echo -n "\u " \
18+
&& [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`'
19+
local gitbranch='`\
20+
export BRANCH="$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null)"; \
21+
if [ "${BRANCH:-}" != "" ]; then \
22+
echo -n "\[\033[0;36m\](\[\033[1;32m\]${BRANCH:-}" \
23+
&& if git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \
24+
echo -n " \[\033[1;33m\]✗"; \
25+
fi \
26+
&& echo -n "\[\033[0;36m\]) "; \
27+
fi`'
28+
local removecolor='\[\033[0m\]'
29+
local lightblue='\[\033[1;34m\]'
30+
local cyan='\[\033[0;36m\]'
31+
PS1="${lightblue}${userpart} ${cyan}\w ${gitbranch}${removecolor}\n\$ "
32+
unset -f __bash_prompt
33+
}
34+
__bash_prompt
35+
export PROMPT_DIRTRIM=4
36+
37+
# Set the default git editor if not already set
38+
# from https://github.com/devcontainers/features/blob/f8e7e275b7ba2808e14a035afd753b83be68e2d9/src/common-utils/scripts/rc_snippet.sh
39+
if [ -z "$(git config --get core.editor)" ] && [ -z "${GIT_EDITOR}" ]; then
40+
if [ "${TERM_PROGRAM}" = "vscode" ]; then
41+
if [[ -n $(command -v code-insiders) && -z $(command -v code) ]]; then
42+
export GIT_EDITOR="code-insiders --wait"
43+
else
44+
export GIT_EDITOR="code --wait"
45+
fi
46+
fi
47+
fi
48+
49+
# colorize ls output
50+
export LS_OPTIONS='--color=auto'
51+
eval "$(dircolors)"
52+
alias ls='ls $LS_OPTIONS'
53+
alias ll='ls $LS_OPTIONS -l'
54+
55+
# enable bash completion for git
56+
source /usr/share/bash-completion/completions/git

terminal-config/bashrc-template

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# This bashrc will be source from /root/.bashrc upon launch of every terminal
4+
# in a devcontainer that uses the bash-config feature from
5+
# https://github.com/DiamondLightSource/devcontainer-features
6+
7+
# This file is initialized by bash-config, but you are then free to edit it
8+
9+
# execute default, opinionated settings - delete this line to remove defaults
10+
source ~/terminal-config/bashrc-default
11+
12+
if [ ! -f ~/one-time ]; then
13+
# add your personal one time only (container creation) commands here
14+
touch ~/one-time
15+
fi
16+
17+
# add your personal settings for every shell below
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+
# If the files aren't in the user's terminal config then copy from the template
5+
mkdir -p $USER_TERMINAL_CONFIG
6+
for file in bashrc inputrc zshrc; do
7+
if [ ! -f $USER_TERMINAL_CONFIG/$file ]; then
8+
cp /root/terminal-config/$file-template $USER_TERMINAL_CONFIG/$file
9+
fi
10+
done

terminal-config/inputrc-template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Readline configuration for bash shell.
2+
3+
# Incremental history searching with up and down arrows (C-P and C-N for old
4+
# style navigation).
5+
"\e[A": history-search-backward
6+
"\e[B": history-search-forward
7+
8+
# Control left and right for word movement
9+
"\e[5C": forward-word
10+
"\e[5D": backward-word

terminal-config/zshrc-default

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/zsh
2+
3+
# This zshrc will be source from /root/.zshrc upon launch of every terminal
4+
# in a devcontainer that uses the bash-config feature from
5+
# https://github.com/DiamondLightSource/devcontainer-features
6+
7+
# This file is initialized by vscode feature bash-config,
8+
# but you are then free to edit it
9+
10+
# set up eternal history for zsh
11+
HISTCONTROL=ignoreboth:erasedups
12+
HISTSIZE=10000000
13+
SAVEHIST=$HISTSIZE
14+
HISTFILE=$CONFIG_FOLDER/.zsh_eternal_history
15+
setopt BANG_HIST # Treat the '!' character specially during expansion.
16+
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
17+
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
18+
setopt SHARE_HISTORY # Share history between all sessions.
19+
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
20+
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
21+
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
22+
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
23+
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
24+
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
25+
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
26+
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
27+
#setopt HIST_BEEP # Beep when accessing nonexistent history.
28+
29+
# set a theme compatible with vscode terminals
30+
ZSH_THEME="dst"

terminal-config/zshrc-template

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/zsh
2+
3+
# This zshrc will be source from /root/.zshrc upon launch of every terminal
4+
# in a devcontainer that uses the bash-config feature from
5+
# https://github.com/DiamondLightSource/devcontainer-features
6+
7+
# This file is initialized by bash-config, but you are then free to edit it
8+
9+
# execute default, opinionated settings - delete this line to remove defaults
10+
source ~/terminal-config/zshrc-default
11+
12+
if [ ! -f ~/one-time ]; then
13+
# add your personal one time only (container creation) commands here
14+
touch ~/one-time
15+
fi
16+
17+
# add your personal settings for every shell below

0 commit comments

Comments
 (0)