Skip to content

Commit 5a9ac26

Browse files
committed
Add devcontainer
Unified the development environment with a devcontainer. This will allow faster onboarding and a more consistent development environment.
1 parent 2adeba0 commit 5a9ac26

File tree

6 files changed

+160
-1
lines changed

6 files changed

+160
-1
lines changed

.devcontainer/devcontainer.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"image": "mcr.microsoft.com/vscode/devcontainers/go:1.22",
3+
"customizations": {
4+
"vscode": {
5+
"extensions": [
6+
"golang.go",
7+
"editorconfig.editorconfig",
8+
"ms-azuretools.vscode-bicep",
9+
"ms-vscode.azurecli",
10+
"arjun.swagger-viewer"
11+
],
12+
13+
"settings": {
14+
"gopls": {
15+
"ui.semanticTokens": true
16+
},
17+
"go.lintTool": "golangci-lint"
18+
}
19+
}
20+
},
21+
22+
"features": {
23+
"ghcr.io/devcontainers/features/node:1": {
24+
"version": "latest"
25+
},
26+
"ghcr.io/devcontainers/features/azure-cli:1": {
27+
"version": "latest",
28+
"installBicep": true,
29+
"extensions": "providerhub"
30+
}
31+
},
32+
33+
"remoteUser": "vscode",
34+
35+
"mounts": [
36+
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached"
37+
],
38+
39+
"postCreateCommand": "./.devcontainer/postCreate.sh"
40+
}

.devcontainer/motd

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
█████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗██████╗
2+
██╔══██╗██╔══██╗██╔═══██╗ ██║ ██║██╔════╝██╔══██╗
3+
███████║██████╔╝██║ ██║█████╗███████║██║ ██████╔╝
4+
██╔══██║██╔══██╗██║ ██║╚════╝██╔══██║██║ ██╔═══╝
5+
██║ ██║██║ ██║╚██████╔╝ ██║ ██║╚██████╗██║
6+
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝
7+
8+
9+
Welcome to the devcontainer!
10+
11+
To start working with azure-cli, you need to login to Azure account.
12+
$ az login --use-device-code
13+
14+
To start working on typespec API, install the tsp extension
15+
$ tsp code install

.devcontainer/postCreate.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Configure this to fit your username and email
4+
# This is done by mounting the user .gitconfig file into the container
5+
# Command can be found in the devcontainer.json file almost at the end
6+
# "mounts": [ ...
7+
8+
# This sets the git editor to the VS Code editor
9+
git config --global core.editor "code --wait"
10+
11+
# Source git completions and add them to bashrc
12+
source /usr/share/bash-completion/completions/git
13+
echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc
14+
15+
# Install the typespec
16+
# pinned to the last working version combination
17+
npm install -g @typespec/[email protected]
18+
npm install \
19+
@typespec/[email protected] \
20+
@typespec/[email protected] \
21+
@typespec/[email protected] \
22+
@typespec/[email protected] \
23+
@typespec/[email protected] \
24+
@azure-tools/[email protected] \
25+
@azure-tools/[email protected] \
26+
@azure-tools/[email protected]
27+
28+
29+
# Install the golang-lint
30+
# binary will be $(go env GOPATH)/bin/golangci-lint
31+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
32+
33+
golangci-lint --version
34+
35+
# Setup the welcome screen
36+
echo "cat .devcontainer/motd" >> ~/.bashrc
37+
echo "cat .devcontainer/motd" >> ~/.zshrc

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[*.tsp]
2+
trim_trailing_whitespace = true
3+
tab_width = 2
4+
indent_size = 2
5+
indent_style = space
6+
7+
[*.md]
8+
trim_trailing_whitespace = true
9+
tab_width = 4
10+
indent_size = 4
11+
indent_style = space

.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
localsecrets
3+
secrets
4+
node_modules
5+
/.vscode
6+
/*.crt
7+
/*.key
8+
/*kubeconfig
9+
/*.pem
10+
.DS_Store
11+
env
12+
13+
# no need to track, used only for typespec
14+
# version is pinned in devcontainer.json
15+
package.json
16+
package-lock.json

README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# ARO-HCP
1+
# ARO-HCP
2+
3+
# Description
4+
The RP for the ARO-HCP project.
5+
6+
7+
## Development setup
8+
9+
The setup is based on VSCode Remote Containers. See [here](https://code.visualstudio.com/docs/remote/containers) for more information.
10+
11+
The predefined container is in `.devcontainer` with a custom `postCreate.sh`.
12+
To use it, please install the [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension in VSCode.
13+
14+
The VSCode will have the following extensions installed:
15+
- [golang.go](https://marketplace.visualstudio.com/items?itemName=golang.Go)
16+
- [editorconfig.editorconfig](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig)
17+
- [ms-azuretools.vscode-bicep](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep)
18+
- [ms-vscode.azurecli](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azurecli)
19+
- [arjun.swagger-viewer](https://marketplace.visualstudio.com/items?itemName=Arjun.swagger-viewer)
20+
21+
During the container setup, it also install golangci-lint, which is defacto standard for linting go.
22+
23+
On top of that, is sets up the Bicep CLI and the Azure CLI with Bicep extension
24+
to simplify development of infra code.
25+
26+
Finally, the container also contains the nodejs and sets up the typespec which is needed for the ARM contract development, as it is now mandatory to have the typespec in the ARM templates. When the container is created, there will be `package.json` and `package-lock.json` files in the root of the project, which are articaft of the typespec installation. They are ignored for the git, as all version pinning happens in the `devcontainer.json` file.
27+
To enable the typespec extensions, which is not yet part of official extensions, once the vscode opens and the devcontainer is ready, you need to run the following command
28+
```bash
29+
tsp code install
30+
```
31+
32+
33+
34+
**Most importantly**, the container is set up to use the same user as the host machine, so you can use the same git config and ssh keys.
35+
It is implemented as host mount in the `.devcontainer/devcontainer.json` file.
36+
37+
```json
38+
"mounts": [
39+
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached"
40+
],
41+
```

0 commit comments

Comments
 (0)