Skip to content

Commit ec3994a

Browse files
authored
Initial Eclipse S-CORE Development Container (#1)
1 parent 0a86442 commit ec3994a

23 files changed

+715
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"features": {
3+
"ghcr.io/devcontainers-extra/features/pre-commit:2": {
4+
"version": "2.0.18",
5+
"resolved": "ghcr.io/devcontainers-extra/features/pre-commit@sha256:6e0bb2ce80caca1d94f44dab5d0653d88a1c00984e590adb7c6bce012d0ade6e",
6+
"integrity": "sha256:6e0bb2ce80caca1d94f44dab5d0653d88a1c00984e590adb7c6bce012d0ade6e"
7+
},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
9+
"version": "2.12.2",
10+
"resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:842d2ed40827dc91b95ef727771e170b0e52272404f00dba063cee94eafac4bb",
11+
"integrity": "sha256:842d2ed40827dc91b95ef727771e170b0e52272404f00dba063cee94eafac4bb"
12+
},
13+
"ghcr.io/devcontainers/features/git-lfs:1": {
14+
"version": "1.2.5",
15+
"resolved": "ghcr.io/devcontainers/features/git-lfs@sha256:71c2b371cf12ab7fcec47cf17369c6f59156100dad9abf9e4c593049d789de72",
16+
"integrity": "sha256:71c2b371cf12ab7fcec47cf17369c6f59156100dad9abf9e4c593049d789de72"
17+
},
18+
"ghcr.io/devcontainers/features/git:1": {
19+
"version": "1.3.4",
20+
"resolved": "ghcr.io/devcontainers/features/git@sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a",
21+
"integrity": "sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a"
22+
}
23+
}
24+
}

.devcontainer/devcontainer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
3+
"features": {
4+
"ghcr.io/devcontainers/features/git:1": {},
5+
"ghcr.io/devcontainers/features/git-lfs:1": {},
6+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
7+
"ghcr.io/devcontainers-extra/features/pre-commit:2": {
8+
"version": "4.2.0"
9+
}
10+
},
11+
"postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/post_create_command.sh",
12+
"customizations": {
13+
"vscode": {
14+
"extensions": [
15+
"mads-hartmann.bash-ide-vscode",
16+
"dbaeumer.vscode-eslint",
17+
"EditorConfig.EditorConfig"
18+
],
19+
"settings": {
20+
"files.insertFinalNewline": true
21+
}
22+
}
23+
}
24+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
npm install -g @devcontainers/cli
3+
pre-commit install

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @opajonk @lurtz

.github/workflows/ci.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Validate DevContainer'
2+
description: 'This workflow is checking that updates do not break stuff. If on main branch, publish to latest tag.'
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
name: 'Check, Build, Test, Publish DevContainer'
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
id-token: write
21+
22+
steps:
23+
- name: Checkout (GitHub)
24+
uses: actions/checkout@v3
25+
26+
- name: Login to GitHub Container Registry
27+
uses: docker/login-action@v2
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GHCR_TOKEN }}
32+
33+
- name: Check, Build, Test, Publish
34+
uses: devcontainers/ci@v0.3
35+
with:
36+
cacheFrom: ghcr.io/eclipse-score/devcontainer
37+
imageName: ghcr.io/eclipse-score/devcontainer
38+
# publish latest from main branch; tags are handled in release workflow
39+
imageTag: latest
40+
refFilterForPush: 'refs/heads/main'
41+
runCmd: |
42+
# Check
43+
pre-commit run --show-diff-on-failure --color=always --all-files || exit -1
44+
45+
# Build
46+
./scripts/build.sh
47+
48+
# Test
49+
./scripts/test.sh

.github/workflows/release.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: 'Validate & Publish DevContainer'
2+
description: 'This workflow is checking that for releases, updates do not break stuff and publishes the released container.'
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
build:
10+
name: 'Check, Build, Test, Publish DevContainer'
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
id-token: write
16+
17+
steps:
18+
- name: Checkout (GitHub)
19+
uses: actions/checkout@v3
20+
21+
- name: Login to GitHub Container Registry
22+
uses: docker/login-action@v2
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GHCR_TOKEN }}
27+
28+
- name: Check, Build, Test, Publish
29+
uses: devcontainers/ci@v0.3
30+
with:
31+
imageName: ghcr.io/eclipse-score/devcontainer
32+
cacheFrom: ghcr.io/eclipse-score/devcontainer
33+
imageTag: ${{ github.ref_name }}
34+
runCmd: |
35+
# Check
36+
pre-commit run --show-diff-on-failure --color=always --all-files || exit -1
37+
38+
# Build
39+
./scripts/build.sh
40+
41+
# Test
42+
./scripts/test.sh

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Exported image files shall never be committed.
2+
/export.img

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # v5.0.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
exclude: "devcontainer-lock.json"
8+
- id: trailing-whitespace
9+
- id: check-shebang-scripts-are-executable
10+
- id: check-executables-have-shebangs

README.md

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,132 @@
1-
# devcontainer
2-
Common Devcontainer for Eclipse S-CORE
1+
# Common DevContainer for Eclipse S-CORE
2+
This repository contains the common [development container](https://containers.dev) for [Eclipse S-CORE](https://github.com/eclipse-score).
3+
It contains all tools required to develop (modify, build, ...) Eclipse S-CORE.
4+
All tool version are well-defined, and all tools are pre-configured to work as expected for Eclipse S-CORE development.
5+
The container is [pre-built](https://containers.dev/guide/prebuild) in GitHub Actions as part of this repository, tested, published, and ready for use.
6+
7+
Using the pre-built container in an Eclipse S-CORE repository is described in the [Usage](#usage) section.
8+
9+
Modifying the content of the container is explained in the [Development](#development) section.
10+
11+
## Usage
12+
13+
> **NOTE:** There are several development environments which support development containers; most notably [Visual Studio Code](https://code.visualstudio.com), but also [IntelliJ IDEA](https://www.jetbrains.com/idea) and others.
14+
> See [here](https://containers.dev/supporting) for a more complete list.
15+
> In the following, we assume that [Visual Studio Code](https://code.visualstudio.com) and its Dev Containers extension is used.
16+
The [Dev Containers extension homepage](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) has a description how to get up to speed on Windows, macOS and Linux operating systems.
17+
From here on, we assume that such a development container setup is installed and running.
18+
19+
### First-Time Setup
20+
21+
Add a file called `.devcontainer/devcontainer.json` to your repository.
22+
It should contain the following:
23+
24+
````json
25+
{
26+
"name": "eclipse-s-core",
27+
"image": "ghcr.io/eclipse-score/devcontainer:<version>",
28+
"initializeCommand": "mkdir -p ${localEnv:HOME}/.cache/bazel"
29+
}
30+
````
31+
32+
The `<version>` must be a [valid, published release](https://github.com/eclipse-score/devcontainer/tags).
33+
You can also use `latest` as `<version>` to automatically follow the `main` branch - but be aware that this can result in undesired updates.
34+
The `initializeCommand` is required to ensure the default Bazel cache directory exists on your host system.
35+
36+
To start using the container, click the **Reopen in Container** button when prompted by Visual Studio Code:
37+
38+
![Reopen in Container](resources/reopen_in_container.png)
39+
40+
Alternatively, you can press <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>p</kbd> and run from there "Dev Containers: Reopen in Container".
41+
42+
The first time you do this, the container will be downloaded.
43+
This may take some time.
44+
Afterwards, Visual Studio Code should show this in the lower left corner of your window:
45+
46+
![Dev container success](resources/devcontainer_success.png)
47+
48+
### Inside the Container
49+
50+
Open a Terminal, and - for example - type `bazel build ...` to execute the default build of the repository.
51+
52+
After you have build the code, create [compilation databases](https://clang.llvm.org/docs/JSONCompilationDatabase.html) via Visual Studio Code [Task](https://code.visualstudio.com/docs/debugtest/tasks):
53+
54+
- C++: <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>p</kbd> -> `Tasks: Run Task` -> `Update compile_commands.json`
55+
- Rust: <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>p</kbd> -> `Tasks: Run Task` -> `Generate rust-project.json`
56+
57+
These databases are used by Visual Studio Code to support code navigation and auto-completion with the help of [language servers](https://microsoft.github.io/language-server-protocol/).
58+
59+
Congratulations, you are now a dev container enthusiast 😊.
60+
61+
## Development
62+
63+
> **NOTE:** This is about the development *of the DevContainer*, not about development of Eclipse S-CORE *using* the DevContainer.
64+
65+
The [Eclipse S-CORE](https://github.com/eclipse-score) development container is developed using - a development container!
66+
That means, the usage is similarly simple:
67+
68+
````
69+
git clone https://github.com/eclipse-score/devcontainer.git
70+
code devcontainer
71+
````
72+
and "Reopen in Container".
73+
74+
### Repository Structure
75+
Ordered by importance:
76+
77+
* `src/s-core-devcontainer/` contains the sources for the Eclipse S-CORE DevContainer.
78+
It uses pre-existing [DevContainer features](https://containers.dev/implementors/features/) to provide some standard tools like Git, LLVM, and others.
79+
In addition, it uses a so-called "local" feature (cf. `src/s-core-devcontainer/.devcontainer/s-core-local`) for the remaining tools and configuration.
80+
* `scripts/` contains scripts to build and test the container.
81+
* `.devcontainer/` contains the definition of the DevContainer for **this** repository, i.e. the "devcontainer devcontainer".
82+
There should rarely be a need to modify this.
83+
* `.github/` contains the regular GitHub setup, with code owners and CI.
84+
* `resources/` contains a few screenshots.
85+
86+
### Modify, Build, Test, Use
87+
88+
It is very simple to develop the development container.
89+
You can change files related to the container and then simply run the `scripts/*`.
90+
They are used by the CI, but especially the build and test scripts can be run also locally out of the box:
91+
````console
92+
$ ./scripts/build.sh
93+
[... build output..]
94+
{"outcome":"success","imageName":["vsc-s-core-devcontainer-209943ec6ff795f57b20cdf85a70c904d1e3b4a329d1e01c79f0ffea615c6e40-features"]}
95+
96+
$ ./scripts/test.sh
97+
[... test output...]
98+
💯 All passed!
99+
````
100+
You can now also use this freshly built development container locally on your machine, e.g. to test the container as part of an Eclipse S-CORE module.
101+
For this you must understand that you have the following situation:
102+
```
103+
+---------------------------------+
104+
| Development Container A |
105+
| +---------------------------+ |
106+
| | S-CORE DevContainer image | |
107+
| +---------------------------+ |
108+
+---------------------------------+
109+
```
110+
`Development Container A` is the one you are running right now to develop the `S-CORE DevContainer` .
111+
So in order to execute `S-CORE DevContainer` on your host (and test it as part of an S-CORE module), you need to
112+
113+
* export this newly built S-CORE DevContainer image
114+
* import the image on your host machine
115+
* use the image name in the `.devcontainer/devcontainer.json` of the targeted S-CORE module
116+
117+
Concretely, this can be done as follows:
118+
119+
* Run `docker save <imageName> > export.img` in `Development Container A`.
120+
For example, given above build output, this would be `docker save vsc-s-core-devcontainer-209943ec6ff795f57b20cdf85a70c904d1e3b4a329d1e01c79f0ffea615c6e40-features > export.img`
121+
* On your **host machine** (!!), open a console and run `docker load < /path/to/export.img`.
122+
* In the working copy of the targeted S-CORE module, edit the file `.devcontainer/devcontainer.json` and change the `"image": "..."` entry to `"image": "<imageName>"`.
123+
Given above build output, this would be `"image": "vsc-s-core-devcontainer-209943ec6ff795f57b20cdf85a70c904d1e3b4a329d1e01c79f0ffea615c6e40-features"`.
124+
The Visual Studio Code instance related to the targeted S-CORE module will now ask you to rebuild the DevContainer.
125+
Do so, and you have a running instance of `S-CORE DevContainer` related to the targeted S-CORE module.
126+
127+
### Version Pinning
128+
129+
The `S-CORE DevContainer` pins feature and tool versions.
130+
For tools that are not part of a trusted distribution (i.e. downloaded directly), it also pins the SHA256 hash.
131+
While not being the most convenient choice for tool updates, this makes our supply chain much more secure.
132+
Additionally, there are no "surprise updates" which unexpectedly break things.

resources/devcontainer_success.png

2.65 KB
Loading

0 commit comments

Comments
 (0)