Skip to content

Commit 8b9c707

Browse files
authored
feat: add image variant with vscode specific settings (#314)
* feat: add image variant with vscode specific settings * chore: fix sign command for vscode container * chore(devcontainer.json): remove unnecessary properties for this container * chore: externalize metadata and extend contents * ci: add checkout step to build-push * chore: quote label data * chore: simplify devcontainer-metadata-vscode.json * chore: add back one extension * chore: add more plug-ins * chore: try to fix array escaping * chore: use jq tostring to convert json to label * chore: debug json magic * chore: escape, quote, unescape, doule escape... for victory * chore: hard-code metadata for now, I give up * chore: single quote content of label to prevent shell interpolation * chore: running out of ideas * chore: why can't you leave my quotes alone * ci: final victory * chore: add vscode settings * chore: change path to compile_commands * chore: update vscode plugin versions * chore: update documentation * docs: minor update on merge logic for devcontainer.metadata
1 parent 4da5f6b commit 8b9c707

6 files changed

Lines changed: 148 additions & 34 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" },
4+
"customizations": {
5+
"vscode": {
6+
"extensions": [
7+
"llvm-vs-code-extensions.vscode-clangd@0.1.26",
8+
"marus25.cortex-debug@1.12.1",
9+
"matepek.vscode-catch2-test-adapter@4.8.3",
10+
"mhutchie.git-graph@1.30.0",
11+
"ms-vscode.cmake-tools@1.17.15",
12+
"ms-vscode.cpptools@1.18.5",
13+
"ms-vsliveshare.vsliveshare@1.0.5905",
14+
"SonarSource.sonarlint-vscode@4.3.0",
15+
"xaver.clang-format@1.9.0"
16+
]
17+
},
18+
"settings": {
19+
"C_Cpp.intelliSenseEngine": "disabled",
20+
"C_Cpp.formatting": "clangFormat",
21+
"clangd.arguments": [
22+
"--query-driver=/opt/**/arm-none-eabi-*",
23+
"--compile-commands-dir=${userHome}/.amp"
24+
],
25+
"cmake.copyCompileCommands": "${userHome}/.amp/compile_commands.json",
26+
"cmake.options.statusBarVisibility": "compact",
27+
"cortex-debug.gdbPath": "gdb-multiarch",
28+
"cortex-debug.objdumpPath": "arm-none-eabi-objdump",
29+
"sonarlint.pathToCompileCommands": "${userHome}/.amp/compile_commands.json"
30+
}
31+
}
32+
}
33+
]

.devcontainer/devcontainer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"dockerfile": "Dockerfile",
44
"context": ".."
55
},
6-
"runArgs": ["--add-host=host.docker.internal:host-gateway"],
7-
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" },
86
"mounts": [
97
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
108
],

.github/workflows/build-push.yml

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,23 @@ jobs:
2929
# with sigstore/fulcio when running outside of PRs.
3030
id-token: write
3131
steps:
32+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
33+
with:
34+
persist-credentials: false
3235
- uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0
3336
if: ${{ github.event_name != 'merge_group' }}
37+
- uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
38+
- uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
39+
with:
40+
version: v0.12.1
41+
- uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
42+
if: ${{ github.event_name != 'merge_group' }}
43+
with:
44+
registry: ${{ env.REGISTRY }}
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
3447
- uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
35-
id: meta
48+
id: metadata-base
3649
env:
3750
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
3851
with:
@@ -45,43 +58,68 @@ jobs:
4558
type=semver,pattern={{version}}
4659
type=semver,pattern={{major}}.{{minor}}
4760
type=semver,pattern={{major}}
48-
- uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
49-
- uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
61+
- uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
62+
id: build-and-push-base
5063
with:
51-
version: v0.12.0
52-
- uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
53-
if: ${{ github.event_name != 'merge_group' }}
64+
file: .devcontainer/Dockerfile
65+
platforms: linux/amd64,linux/arm64
66+
push: ${{ github.event_name != 'merge_group' }}
67+
tags: ${{ steps.metadata-base.outputs.tags }}
68+
labels: ${{ steps.metadata-base.outputs.labels }}
69+
annotations: ${{ steps.metadata-base.outputs.annotations }}
70+
sbom: true
71+
provenance: true
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
- uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
75+
id: metadata-vscode
76+
env:
77+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
5478
with:
55-
registry: ${{ env.REGISTRY }}
56-
username: ${{ github.actor }}
57-
password: ${{ secrets.GITHUB_TOKEN }}
79+
images: ${{ env.REGISTRY }}/${{ github.repository }}-vscode
80+
# Generate Docker tags based on the following events/attributes
81+
tags: |
82+
type=raw,value=latest,enable={{is_default_branch}}
83+
type=ref,event=pr
84+
type=semver,pattern={{raw}}
85+
type=semver,pattern={{version}}
86+
type=semver,pattern={{major}}.{{minor}}
87+
type=semver,pattern={{major}}
88+
# Generate image LABEL for devcontainer.metadata
89+
# the sed expression is a workaround for quotes being eaten in arrays (e.g. ["x", "y", "z"] -> ["x",y,"z"])
90+
- run: echo "metadata=$(jq -cj '.' .devcontainer/devcontainer-metadata-vscode.json | sed 's/,"/, "/g')" >> "$GITHUB_OUTPUT"
91+
id: devcontainer-metadata
5892
- uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
59-
id: build-and-push
93+
id: build-and-push-vscode
6094
with:
6195
file: .devcontainer/Dockerfile
6296
platforms: linux/amd64,linux/arm64
6397
push: ${{ github.event_name != 'merge_group' }}
64-
tags: ${{ steps.meta.outputs.tags }}
65-
labels: ${{ steps.meta.outputs.labels }}
66-
annotations: ${{ steps.meta.outputs.annotations }}
98+
tags: ${{ steps.metadata-vscode.outputs.tags }}
99+
labels: |
100+
${{ steps.metadata-vscode.outputs.labels }}
101+
devcontainer.metadata=${{ steps.devcontainer-metadata.outputs.metadata }}
102+
annotations: ${{ steps.metadata-vscode.outputs.annotations }}
67103
sbom: true
68104
provenance: true
69105
cache-from: type=gha
70-
cache-to: type=gha,mode=max
71106
- uses: anchore/sbom-action@b6a39da80722a2cb0ef5d197531764a89b5d48c3 # v0.15.8
72-
if: ${{ steps.build-and-push.outputs.digest != '' && github.event_name != 'merge_group' }}
107+
if: ${{ steps.build-and-push-base.outputs.digest != '' && github.event_name != 'merge_group' }}
73108
with:
74-
image: ${{ env.REGISTRY }}/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }}
109+
image: ${{ env.REGISTRY }}/${{ github.repository }}@${{ steps.build-and-push-base.outputs.digest }}
75110
dependency-snapshot: true
76111
- uses: actions/dependency-review-action@be8bc500ee15e96754d2a6f2d34be14e945a46f3 # v4.1.2
77112
if: ${{ github.event_name == 'pull_request' }}
78113
with:
79114
comment-summary-in-pr: on-failure
80115
fail-on-severity: critical
81-
- name: Sign the image with GitHub OIDC token
116+
- name: Sign the images with GitHub OIDC token
82117
if: ${{ github.event_name != 'merge_group' }}
83118
# This step uses the GitHub OIDC identity token to provision an ephemeral certificate
84119
# against the sigstore community Fulcio instance.
85120
env:
86-
DIGEST: ${{ steps.build-and-push.outputs.digest }}
87-
run: cosign sign --yes --recursive "${{ env.REGISTRY }}/${{ github.repository }}@${DIGEST}"
121+
DIGEST_BASE: ${{ steps.build-and-push-base.outputs.digest }}
122+
DIGEST_VSCODE: ${{ steps.build-and-push-vscode.outputs.digest }}
123+
run: |
124+
cosign sign --yes --recursive "${{ env.REGISTRY }}/${{ github.repository }}@${DIGEST_BASE}"
125+
cosign sign --yes --recursive "${{ env.REGISTRY }}/${{ github.repository }}-vscode@${DIGEST_VSCODE}"

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
# While the docker/build-push-action works from the Git context, we still need
2424
# the checkout step for running our tests.
2525
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
26+
with:
27+
persist-credentials: false
2628
- uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
2729
- uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
2830
with:

.github/workflows/cleanup-pr-image.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ jobs:
2323
username: ${{ github.actor }}
2424
password: ${{ secrets.GITHUB_TOKEN }}
2525
- run: cosign clean -f --type=signature "${{ env.REGISTRY }}/${{ github.repository }}:pr-${{ github.event.pull_request.number }}"
26+
- run: cosign clean -f --type=signature "${{ env.REGISTRY }}/${{ github.repository }}-vscode:pr-${{ github.event.pull_request.number }}"
2627
- uses: bots-house/ghcr-delete-image-action@3827559c68cb4dcdf54d813ea9853be6d468d3a4 # v1.1.0
2728
with:
2829
owner: ${{ github.repository_owner }}
2930
name: ${{ github.event.repository.name }}
3031
token: ${{ secrets.GITHUB_TOKEN }}
3132
tag: pr-${{ github.event.pull_request.number }}
33+
- uses: bots-house/ghcr-delete-image-action@3827559c68cb4dcdf54d813ea9853be6d468d3a4 # v1.1.0
34+
with:
35+
owner: ${{ github.repository_owner }}
36+
name: ${{ github.event.repository.name }}-vscode
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
tag: pr-${{ github.event.pull_request.number }}

README.md

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,95 @@ This repository is under active development; see [pulse](https://github.com/phil
1414

1515
## Description
1616

17+
### Image variants
18+
19+
Two devcontainers are published towards the [GitHub Container Registry](https://ghcr.io/):
20+
21+
- [amp-devcontainer](https://github.com/orgs/philips-software/packages/container/package/amp-devcontainer); the base container including all tools mentioned below
22+
- [amp-devcontainer-vscode](https://github.com/orgs/philips-software/packages/container/package/amp-devcontainer-vscode); as above, but including a full [Visual Studio Code](https://code.visualstudio.com/) configuration that is compatible with [GitHub Codespaces](https://github.com/features/codespaces)
23+
24+
### amp-devcontainer
25+
1726
The amp-devcontainer built from this repository contains compilers and tools to facilitate modern (embedded) C++ development.
1827
The amp-devcontainer includes support for host- and cross-compilation using gcc, arm-gcc and clang compilers.
1928
Next to the compilers there is support for code-coverage measurement, mutation testing (using [mull](https://github.com/mull-project/mull)), fuzzing (using [libfuzzer](https://www.llvm.org/docs/LibFuzzer.html)) and static analysis (clang-format, clang-tidy, clangd, include-what-you-use).
2029
The default build system is set up to use CMake, Ninja and CCache.
2130

2231
For the full list of all included tools and tool versions see the [Dependency Graph](https://github.com/philips-software/amp-devcontainer/network/dependencies), the SBOM published with a [release](https://github.com/philips-software/amp-devcontainer/releases), or the SBOM attached to the image.
2332

24-
## Build & Test
33+
### amp-devcontainer-vscode
2534

26-
The container can be built and tested locally by importing this repository in VS Code with the `Dev Containers` (ms-vscode-remote.remote-containers) plug-in installed. As a prerequisite Docker needs to be installed on the host system. As an alternative a GitHub Codespace can be started.
35+
The amp-devcontainer-vscode is a, slightly more, opinionated variant that can be used in Visual Studio Code or GitHub Codespaces without any additional configuration. All included tools are set-up and necessary plug-ins will be installed at container start. This behavior is implemented by appending devcontainer metadata to an image label according to the [specifications](https://containers.dev/implementors/reference/#labels). It is possible to override, amend or change the options following this [merge logic](https://containers.dev/implementors/spec/#merge-logic).
2736

28-
A test task is available to run the included `bats` tests. Choose `Tasks: Run Test Task` from the command pallette.
37+
## Usage
2938

30-
## Verify image signature
39+
### Verify image signature
3140

32-
The container image is signed with [SigStore](https://www.sigstore.dev/) [Cosign](https://docs.sigstore.dev/signing/quickstart/) using a keyless signing method.
41+
The container images are signed with [SigStore](https://www.sigstore.dev/) [Cosign](https://docs.sigstore.dev/signing/quickstart/) using a keyless signing method.
3342

3443
The signature can be verified with the following command (using Docker), verifying that the image is actually signed by the GitHub CI system:
3544

45+
> amp-devcontainer
46+
3647
```sh
3748
docker run --rm gcr.io/projectsigstore/cosign verify ghcr.io/philips-software/amp-devcontainer --certificate-oidc-issuer https://token.actions.githubusercontent.com --certificate-identity-regexp https://github.com/philips-software/amp-devcontainer
3849
```
3950

40-
## Usage
51+
> amp-devcontainer-vscode
52+
53+
```sh
54+
docker run --rm gcr.io/projectsigstore/cosign verify ghcr.io/philips-software/amp-devcontainer-vscode --certificate-oidc-issuer https://token.actions.githubusercontent.com --certificate-identity-regexp https://github.com/philips-software/amp-devcontainer
55+
```
56+
57+
The resulting containers can be used in a `.devcontainer.json` file or in a `.devcontainer` folder.
4158

42-
The resulting container can be used in a `.devcontainer` folder. While the example uses the `latest` tag, it is recommended to pin to a specific version. Or better yet, a specific SHA.
59+
> [!NOTE]
60+
> While the following examples use the `latest` tag, it is recommended to pin to a specific version. Or better yet, a specific SHA.
4361
44-
> .devcontainer/devcontainer.json
62+
### amp-devcontainer
63+
64+
> .devcontainer/devcontainer.json or .devcontainer.json
4565
4666
```json
4767
{
4868
"image": "ghcr.io/philips-software/amp-devcontainer:latest"
4969
}
5070
```
5171

72+
### amp-devcontainer-vscode
73+
74+
> .devcontainer/devcontainer.json or .devcontainer.json
75+
76+
```json
77+
{
78+
"image": "ghcr.io/philips-software/amp-devcontainer-vscode:latest"
79+
}
80+
```
81+
5282
## Community
5383

54-
This project uses the [CODE_OF_CONDUCT](./CODE_OF_CONDUCT.md) to define expected conduct in our community. Instances of
84+
This project uses a [code of conduct](./CODE_OF_CONDUCT.md) to define expected conduct in our community. Instances of
5585
abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project [CODEOWNER](./.github/CODEOWNERS)
5686

5787
## Changelog
5888

59-
See [CHANGELOG](./CHANGELOG.md) for more info on what's been changed.
89+
See the [changelog](./CHANGELOG.md) for more info on what's been changed.
6090

6191
## Contributing
6292

63-
See [CONTRIBUTING](./CONTRIBUTING.md)
93+
This project uses [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html) and [Conventional Commits 1.0.0](https://www.conventionalcommits.org/en/v1.0.0/) please see the [contributing](./CONTRIBUTING.md) guideline for more information.
94+
95+
### Build & Test
96+
97+
The container can be built and tested locally by importing this repository in VS Code with the [`Remote Containers`](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) plug-in installed. As a prerequisite Docker needs to be installed on the host system. Alternatively a GitHub Codespace can be started.
98+
99+
A test task is available to run the included `bats` tests. Choose `Tasks: Run Test Task` from the command pallette.
64100

65101
## Reporting vulnerabilities
66102

67103
If you find a vulnerability, please report it to us!
68-
See [SECURITY.md](./SECURITY.md) for more information.
104+
See [security](./SECURITY.md) for more information.
69105

70106
## Licenses
71107

72-
See [LICENSE](./LICENSE)
108+
See [license](./LICENSE)

0 commit comments

Comments
 (0)