Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
7 changes: 5 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
FROM mcr.microsoft.com/devcontainers/base:noble

# VS Code commit ID for devcontainer compatibility, argument supplied at build time via devcontainer.json
ARG VSCODE_COMMIT
# VS Code commit ID for devcontainer compatibility. Can be overridden at build time via build args.
# Default chosen for current stable VS Code Server version used in this repository.
ARG VSCODE_COMMIT=f220831ea2d946c0dcb0f3eaa480eb435a2c1260

ENV VSCODE_COMMIT=${VSCODE_COMMIT}

# Copy and run VS Code installation files
COPY ./vscode-init /opt/vscode-init
Expand Down
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Python Development Environment",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "Dockerfile",
"args": {
"VSCODE_COMMIT": "f220831ea2d946c0dcb0f3eaa480eb435a2c1260"
"VSCODE_COMMIT": "${localEnv:VSCODE_COMMIT}"
}
},

Expand Down
44 changes: 32 additions & 12 deletions .github/workflows/build-devcontainer.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
name: Build and Publish Dev Container

on:
push:
branches:
- main
paths:
- '.devcontainer/**'
- '.github/workflows/build-devcontainer.yml'
pull_request:
branches:
- main
paths:
- '.devcontainer/**'
- '.github/workflows/build-devcontainer.yml'
workflow_dispatch:
inputs:
vscode_commit:
description: 'VS Code commit hash to use (defaults to Dockerfile ARG default if not provided)'
required: false
type: string

env:
REGISTRY: ghcr.io
Expand All @@ -27,20 +26,38 @@ jobs:
packages: write # For publishing container images
pull-requests: write # For PR comments from security scan
actions: write # For uploading artifacts from security scan

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Read VSCODE_COMMIT from devcontainer.json
- name: Resolve VSCODE_COMMIT (input override > Dockerfile default)
id: vscode-commit
run: |
VSCODE_COMMIT=$(grep 'VSCODE_COMMIT' .devcontainer/devcontainer.json | tr -d '"' | cut -d " " -f 2)
# If user provided an input, trust it. Otherwise parse Dockerfile ARG default.
if [ -n "${{ github.event.inputs.vscode_commit }}" ]; then
VSCODE_COMMIT="${{ github.event.inputs.vscode_commit }}"
SOURCE="workflow_input"
else
# Extract default from ARG line: ARG VSCODE_COMMIT=<hash>
VSCODE_COMMIT=$(grep -E '^ARG VSCODE_COMMIT=' .devcontainer/Dockerfile | head -n1 | cut -d= -f2-)
if [ -z "$VSCODE_COMMIT" ]; then
echo "❌ Could not find default VSCODE_COMMIT in Dockerfile" >&2
exit 1
fi
SOURCE="dockerfile_default"
fi
# Basic validation (40 hex chars)
if ! echo "$VSCODE_COMMIT" | grep -Eq '^[0-9a-f]{40}$'; then
echo "❌ VSCODE_COMMIT '$VSCODE_COMMIT' is not a 40-char hex commit hash" >&2
exit 1
fi
VSCODE_SHORT=${VSCODE_COMMIT:0:7}
echo "Resolved VSCODE_COMMIT=$VSCODE_COMMIT (source=$SOURCE)"
echo "vscode_commit=$VSCODE_COMMIT" >> $GITHUB_OUTPUT
echo "vscode_short=$VSCODE_SHORT" >> $GITHUB_OUTPUT
echo "Full VSCODE_COMMIT: $VSCODE_COMMIT"
echo "Short VSCODE_COMMIT: $VSCODE_SHORT"
echo "source=$SOURCE" >> $GITHUB_OUTPUT
echo "Short: $VSCODE_SHORT"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down Expand Up @@ -76,6 +93,8 @@ jobs:

- name: Build and publish dev container
uses: devcontainers/ci@v0.3
env:
VSCODE_COMMIT: ${{ steps.vscode-commit.outputs.vscode_commit }}
with:
imageName: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
imageTag: ${{ steps.tags.outputs.tags }}
Expand Down Expand Up @@ -151,6 +170,7 @@ jobs:
echo "📝 Labels: ${{ steps.meta.outputs.labels }}"
echo "🔧 VSCode Commit: ${{ steps.vscode-commit.outputs.vscode_commit }}"
echo "📋 Short Commit: ${{ steps.vscode-commit.outputs.vscode_short }}"
echo "🗂️ Source: ${{ steps.vscode-commit.outputs.source }}"
echo ""
echo "To use this dev container:"
echo "1. Reference it in your devcontainer.json:"
Expand Down
66 changes: 44 additions & 22 deletions DEVCONTAINER.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dev Container for Python Development
# Dev Container for Python & R Development

This repository contains a development container configuration optimized for Python development, along with automated workflows to build and publish the container image to GitHub Container Registry (GHCR).
This repository contains a development container configuration optimized for Python (and first-class R) development, along with automated workflows to build and publish the container image to GitHub Container Registry (GHCR). For high-level usage see `README.md`; this document focuses on implementation details.

## 📦 Published Container

Expand All @@ -13,11 +13,14 @@ The dev container is automatically built and published with multiple tags:
- `main` - Latest build from main branch
- `main-<commit-sha>` - Specific commit builds from main branch
- `pr-<number>` - Pull request builds for testing
- `vscode-<vscode-commit-sha>` - Builds with specific VS Code Server versions
- `vscode-<vscode-commit-sha>-<commit-sha>` - Combination of VS Code Server and container commit

### Choosing the Right Tag

- **For production/stable use**: `ghcr.io/smartdatafoundry/devcontainer:latest`
- **For reproducible builds**: `ghcr.io/smartdatafoundry/devcontainer:main-abc1234`
- **For reproducible builds**: `ghcr.io/smartdatafoundry/devcontainer:vscode-<vscode-commit-sha>-<commit-sha>`
- **For specific VS Code Server versions**: `ghcr.io/smartdatafoundry/devcontainer:vscode-<vscode-commit-sha>`
- **For testing PR changes**: `ghcr.io/smartdatafoundry/devcontainer:pr-123`

## 🚀 Quick Start
Expand Down Expand Up @@ -63,30 +66,47 @@ docker run --rm -it -v $(pwd):/workspace ghcr.io/smartdatafoundry/devcontainer:l

This dev container includes:

- **Base**: Ubuntu Noble (24.04) via Microsoft's `mcr.microsoft.com/devcontainers/base:noble`
- **Python**: System Python with pip and development tools (via devcontainer feature)
- **Git**: Latest version with configuration support
- **Shell**: Zsh with Oh My Zsh configuration (via common-utils feature)
- **Quarto**: For document publishing and data science workflows (latest version)
- **Marimo**: Markdown presentation tool, alternative to Jupyter Notebooks (latest version)
- **VS Code Server**: Pre-installed for immediate development
- **VS Code Extensions**:
- Continue (AI assistant)
- Black formatter for Python
- Jupyter support
- Markdown All in One
- Rainbow CSV
* **Base**: Ubuntu Noble (24.04) via Microsoft's `mcr.microsoft.com/devcontainers/base:noble`
* **Python**: System Python with pip and development tools (via feature)
* **R**: Installed via Rocker devcontainer feature (languageserver, httpgd, rmarkdown, renv, devtools, radian, vscDebugger)
* **Git**: Latest stable
* **Shell**: Zsh + Oh My Zsh (via common-utils feature)
* **Quarto**: Latest (document publishing)
* **Marimo**: Alternative interactive notebook/presentation tool
* **VS Code Server**: Pre-installed (pin via tag families)
* **VS Code Extensions**: Curated list (see `.devcontainer/vscode-init/extensions-to-install.txt`)

## 🔄 Automated Builds

The container is automatically built and published using GitHub Actions:
The container is built using GitHub Actions with controlled publishing:

### Build Workflow (`build-devcontainer.yml`)
- **Triggers**: Push to main branch, PRs, manual dispatch
- **Features**: Single platform (linux/amd64), intelligent caching, comprehensive validation tests
- **Publishing**: Multi-tag publishing with `latest`, `main`, `main-<sha>`, and `pr-<number>` tags
- **PR Triggers**: Pull requests automatically build test images (`pr-<number>` tags) using default VS Code Server commit
- **Manual Dispatch**: Production builds require manual trigger with VS Code Server commit hash
- **Required Input**: VS Code Server commit hash for reproducible builds
- **Publishing**: Multi-tag publishing with `latest`, `main`, `vscode-<vscode-commit>`, and SHA-based tags
- **Features**: Single platform (linux/amd64), intelligent caching, comprehensive validation tests, security scanning
- **Testing**: Validates Python, Git, Zsh, and Quarto installations

### VS Code Server Version Control
- Default VS Code Server commit is declared once in the Dockerfile via: `ARG VSCODE_COMMIT=<hash>`
- Manual workflow dispatch can override this by providing the `vscode_commit` input
- The workflow extracts the Dockerfile default automatically if no input is provided
- The commit hash is embedded in container tags: `vscode-<short>` and `vscode-<short>-<branch-sha>`

Local override examples:

```bash
# Use Dockerfile default
devcontainer build --workspace-folder .

# Override for build
export VSCODE_COMMIT=0f0d87fa9e96c856c5212fc86db137ac0d783365
devcontainer build --workspace-folder .
```

This keeps maintenance simple: update the default by editing a single line in `Dockerfile` with support for overrides when needed via workflow inputs.

## 📁 Repository Structure

```
Expand All @@ -106,7 +126,7 @@ The container is automatically built and published using GitHub Actions:
├── docs/ # Additional documentation
├── DEVCONTAINER.md # Detailed documentation
├── README.md # Overview and quick start
└── SDF_TRE_SETUP.md # SDF TRE setup guide
└── SDF_TRE_SETUP.md # SDF TRE setup guide
```

## 🔧 Customization
Expand Down Expand Up @@ -143,6 +163,8 @@ The build system creates multiple tags from a single build:
- `main`: Latest commit from main branch
- `main-<sha>`: Specific commit SHA for reproducible builds
- `pr-<number>`: Pull request builds for testing changes
- `vscode-<vscode-commit-sha>`: Builds with specific VS Code Server versions
- `vscode-<vscode-commit-sha>-<branch-sha>`: Complete version specification

## 🧪 Testing

Expand Down Expand Up @@ -171,7 +193,7 @@ The GitHub Action will automatically test your changes when you submit a PR.

## 📝 License

This project is open source and available under the [MIT License](LICENSE).
Licensed under [MIT](LICENSE).

---

Expand Down
Loading