Skip to content

Commit

Permalink
Chore: devcontainer cleanups, update python version (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman authored Jul 30, 2024
2 parents ee91ff7 + 6008fc1 commit 2f75d95
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 54 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.10
ARG PYTHON_VERSION=3.11

FROM python:${PYTHON_VERSION}

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
Expand All @@ -15,7 +17,7 @@ USER $USER
WORKDIR /home/$USER/src

# update PATH for local pip installs
ENV PATH "$PATH:/home/$USER/.local/bin"
ENV PATH="$PATH:/home/$USER/.local/bin"

# upgrade pip
RUN python -m pip install --upgrade pip
Expand Down
38 changes: 21 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
{
"name": "compilerla/template-devcontainer",
"dockerComposeFile": ["compose.yml"],
"dockerComposeFile": ["../compose.yml"],
"service": "dev",
"runServices": ["dev", "docs"],
"workspaceFolder": "/home/compiler/src",
"postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"bpruitt-goddard.mermaid-markdown-syntax-highlighting",
"DavidAnson.vscode-markdownlint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"mhutchie.git-graph"
]
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"bpruitt-goddard.mermaid-markdown-syntax-highlighting",
"DavidAnson.vscode-markdownlint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"mhutchie.git-graph"
]
}
}
36 changes: 20 additions & 16 deletions .devcontainer/devcontainer.pre-built.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
"name": "compilerla/template-devcontainer-pre-built",
"image": "ghcr.io/compilerla/template-devcontainer:main",
"postAttachCommand": "pre-commit install --overwrite",
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"bpruitt-goddard.mermaid-markdown-syntax-highlighting",
"DavidAnson.vscode-markdownlint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"mhutchie.git-graph"
]
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"bpruitt-goddard.mermaid-markdown-syntax-highlighting",
"DavidAnson.vscode-markdownlint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"mhutchie.git-graph"
]
}
}
1 change: 1 addition & 0 deletions .devcontainer/postAttach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
set -eux

# initialize pre-commit
git config --global --add safe.directory /home/$USER/src
pre-commit install --overwrite
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# default to engineering team
* @compilerla/engineering
19 changes: 14 additions & 5 deletions .github/workflows/publish-devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,41 @@ defaults:
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

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

- name: Docker Login to GitHub Container Registry
- name: Docker Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Build, tag, and push image to GitHub Container Registry
- name: Build, tag, and push image to GHCR [python ${{ matrix.python-version }}]
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: GIT-SHA=${{ github.sha }}
build-args: |
GIT-SHA=${{ github.sha }}
PYTHON_VERSION=${{ matrix.python-version }}
cache-from: type=gha,scope=compilerla
cache-to: type=gha,scope=compilerla,mode=max
context: .
file: .devcontainer/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
ghcr.io/${{ github.repository }}:${{ github.sha }}
${{ matrix.python-version == '3.11' && format('ghcr.io/{0}:main', github.repository) || format('ghcr.io/{0}:main_{1}', github.repository, matrix.python-version) }}
${{ matrix.python-version == '3.11' && format('ghcr.io/{0}:{1}', github.repository, github.sha) || format('ghcr.io/{0}:{1}_{2}', github.repository, github.sha, matrix.python-version) }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ A [template repository][template-repo] with a minimal [VS Code devcontainer][dev

Read the full documentation online: <https://compilerla.github.io/template-devcontainer>

## Why?

Read more in our blog post: [How to support a platform-agnostic engineering team with VS Code Dev Containers](https://compiler.la/blog/2024/devcontainer-platform-agnostic-team).

## Features

- Base Docker image `python:3.10` includes support for common dev tooling like `git`, `curl`, `pip`, and `pre-commit`
- Base Docker image `python:3.11` includes support for common dev tooling like `git`, `curl`, `pip`, and `pre-commit`
- Includes VS Code extensions like [`GitLens`][gitlens] and [`Prettier`][prettier] and good default settings for the editor
- The [`pre-commit` configuration][pre-commit-config] includes a number of useful [`pre-commit-hooks`][pre-commit-hooks] and
Compiler's [`conventional-pre-commit`][conventional-pre-commit] hook
Expand Down
8 changes: 4 additions & 4 deletions .devcontainer/compose.yml → compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: compilerla/template-devcontainer
name: template-devcontainer

services:
dev:
build:
context: ..
context: .
dockerfile: .devcontainer/Dockerfile
image: compilerla/template-devcontainer:main
volumes:
- ../:/home/compiler/src
- ./:/home/compiler/src

docs:
image: compilerla/template-devcontainer:main
Expand All @@ -16,4 +16,4 @@ services:
ports:
- "8000"
volumes:
- ../:/home/compiler/src
- ./:/home/compiler/src
6 changes: 4 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Docs are built using [`mkdocs`](https://www.mkdocs.org/). This site is built usi

In no particular order, here are some reasons Compiler likes to use devcontainers as part of our software engineering workflow:

_Read more in our blog post: [How to support a platform-agnostic engineering team with VS Code Dev Containers](https://compiler.la/blog/2024/devcontainer-platform-agnostic-team)_.

| Reason | More |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Cross-platform** | With only VS Code and Docker as dependencies, devcontainers allow developers on Linux, Mac, and Windows to work in a consistent environment, no matter the project's stack |
Expand All @@ -37,7 +39,7 @@ Some of our recent work built on the devcontainer pattern includes:
- [`cal-itp/benefits`](https://github.com/cal-itp/benefits) (Python/Django web app)
- [`cal-itp/eligibility-api`](https://github.com/cal-itp/eligibility-api) (Python API library)
- [`cal-itp/eligibility-server`](https://github.com/cal-itp/eligibility-server) (Python/Flask API server)
- [`cal-itp/hashfields`](https://github.com/cal-itp/hashfields) (.NET core CLI tool)
- [`cal-itp/hashfields`](https://github.com/cal-itp/hashfields) (Python CLI tool)
- [`cal-itp/mobility-marketplace`](https://github.com/cal-itp/mobility-marketplace) (Jekyll static site)
- [`compilerla/compiler.la`](https://github.com/compilerla/compiler.la) (Jekyll static site)
- [`compilerla/conventional-pre-commit`](https://github.com/compilerla/conventional-pre-commit) (Python pre-commit hook)
- [`compilerla/intake-html-table`](https://github.com/compilerla/intake-html-table) (Python intake plugin)
2 changes: 1 addition & 1 deletion docs/features/devcontainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The devcontainer's image is called `compilerla/template-devcontainer`.

### Base

The image is based on [`python:3.10`](https://hub.docker.com/_/python), to ease installation of common tooling like
The image is based on [`python:3.11`](https://hub.docker.com/_/python), to ease installation of common tooling like
[`mkdocs`](docs.md) and [`pre-commit`](pre-commit.md).

### Setup
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mdx_truly_sane_lists
mkdocs
mkdocs-awesome-pages-plugin
mkdocs-macros-plugin
Expand Down
14 changes: 10 additions & 4 deletions docs/usage/reference-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
- **GHCR Packages:** [`compilerla/template-devcontainer`](https://github.com/compilerla/template-devcontainer/pkgs/container/template-devcontainer)
- **Minimal devcontainer.json:** [`devcontainer.pre-built.json`](https://github.com/compilerla/template-devcontainer/blob/main/.devcontainer/devcontainer.pre-built.json)

`template-devcontainer` maintains a [GitHub Actions](https://github.com/features/actions) workflow that publishes the Docker
image to [GitHub Container Registry (GHCR)](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
`template-devcontainer` maintains a [GitHub Actions](https://github.com/features/actions) workflow that publishes Docker
images to [GitHub Container Registry (GHCR)](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).

The publish is triggered for every push to the `main` branch, and the image tag `:main` always represents the latest commit on
that branch.
The publish is triggered for every push to the `main` branch, and multiple image tags are created:

- `main` uses the default Python version of 3.11
- `main_3.10` uses Python 3.10
- `main_3.12` uses Python 3.12

There are also corresponding tags for the git SHA of the commit on `main` that triggered the build
(e.g. `sha`, `sha_3.10`, and `sha_3.12`).

This makes the pre-built devcontainer image available for use in other projects, potentially decreasing startup and onboarding
time even further.
Expand Down
3 changes: 1 addition & 2 deletions docs/usage/run-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

### Docker

Docker is required; the easiest way to get Docker is by downloading and installing [Docker Desktop](https://www.docker.com/products/docker-desktop/)
for Linux, Mac (including M2!), and Windows.
Docker is required; the easiest way to get Docker is by downloading and installing [Docker Desktop](https://www.docker.com/products/docker-desktop/) for Linux, Mac (including Apple Silicon!) and Windows.

### VS Code

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ markdown_extensions:
- attr_list
- codehilite:
linenums: true
- mdx_truly_sane_lists
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
Expand Down

0 comments on commit 2f75d95

Please sign in to comment.