Skip to content

Commit 46df7e8

Browse files
authored
build: Add devcontainer (#117)
Signed-off-by: Mriyam Tamuli <[email protected]>
1 parent a2e26ec commit 46df7e8

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// For format details, see https://containers.dev
2+
{
3+
"name": "csi-driver-image dev container",
4+
"image": "ghcr.io/warm-metal/csi-driver-image/devcontainer:latest",
5+
6+
// Setup the go environment and mount into the dev container at the expected location
7+
"workspaceFolder": "/go/src/github.com/warm-metal/csi-driver-image",
8+
"workspaceMount": "source=${localWorkspaceFolder},target=/go/src/github.com/warm-metal/csi-driver-image,type=bind,consistency=cached",
9+
10+
// Copy over welcome message
11+
"postCreateCommand": "sudo cp .devcontainer/welcome.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt"
12+
}

.devcontainer/welcome.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
👋 Welcome to your development environment for CSI Driver Image!
2+
3+
This debian dev container image contains all tools needed for development.
4+
5+
Get started right away! 🚀
6+
7+
Check out the guide in docs/running-locally.md
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// For format details, see https://containers.dev
2+
{
3+
"name": "csi-driver-image dev container",
4+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
5+
6+
"otherPortsAttributes": {
7+
"onAutoForward": "silent"
8+
},
9+
10+
"features": {
11+
"ghcr.io/devcontainers/features/go:1": {
12+
"version": "1.19"
13+
},
14+
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
15+
"version": "latest",
16+
"helm": "latest",
17+
"minikube": "none"
18+
},
19+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
20+
"dockerDashComposeVersion": "v2"
21+
},
22+
"ghcr.io/devcontainers-contrib/features/kind:1": {}
23+
},
24+
25+
"customizations": {
26+
"vscode": {
27+
"settings": {
28+
"terminal.integrated.defaultProfile.linux": "zsh",
29+
"terminal.integrated.profiles.linux": {
30+
"zsh": {
31+
"path": "zsh"
32+
}
33+
}
34+
},
35+
"extensions": [
36+
"golang.go"
37+
]
38+
}
39+
}
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Dev Container Build and Push Image
2+
3+
on:
4+
push:
5+
branches:
6+
master
7+
paths:
8+
- .github/workflows/devcontainer-build-and-push.yml
9+
- '.github/.devcontainer/**'
10+
pull_request:
11+
paths:
12+
- .github/workflows/devcontainer-build-and-push.yml
13+
- '.github/.devcontainer/**'
14+
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
jobs:
20+
build-and-push-image:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Log in to the GitHub Container registry
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.repository_owner }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Pre-build dev container image
34+
uses: devcontainers/[email protected]
35+
with:
36+
subFolder: .github
37+
imageName: ghcr.io/${{ github.repository }}/devcontainer
38+
cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
39+
push: always

docs/running-locally.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Running Locally
2+
3+
You have two options:
4+
5+
1. Use the [Dev Container](#development-container). This is the recommended approach. This can be used with VSCode, the `devcontainer` CLI, or GitHub Codespaces.
6+
1. Install the [requirements](#requirements) on your computer manually.
7+
8+
## Development Container
9+
10+
The development container contains all the tools necessary to work with csi-driver-image.
11+
12+
You can use the development container in a few different ways:
13+
14+
1. [Visual Studio Code](https://code.visualstudio.com/) with [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). Open the local clone of `csi-driver-image` folder in VSCode and it should offer to use the development container automatically.
15+
1. [`devcontainer` CLI](https://github.com/devcontainers/cli). Once installed, the local clone of `csi-driver-image` folder and run `devcontainer up --workspace-folder .` followed by `devcontainer exec --workspace-folder . /bin/bash` to get a shell where you can build the code. You can use any editor outside the container to edit code; any changes will be mirrored inside the container.
16+
1. [GitHub Codespaces](https://github.com/codespaces). You can start editing as soon as VSCode is open.
17+
18+
Once you have entered the container, continue to [Developing Locally](#developing-locally).
19+
20+
## Requirements
21+
22+
To build on your own machine without using the Dev Container you will need:
23+
24+
* A local clone of this repository.
25+
* [Go](https://golang.org/dl/)
26+
* A local Kubernetes cluster ([`k3d`](https://k3d.io/#quick-start), [`kind`](https://kind.sigs.k8s.io/docs/user/quick-start/#installation), or [`minikube`](https://minikube.sigs.k8s.io/docs/start/))
27+
* [`helm`](https://helm.sh/docs/intro/install/)
28+
29+
## Developing locally
30+
31+
_**Note:** Unless specified otherwise, you need to run all commands after changing your working directory to this repository - `cd /path/to/csi-driver-image-repository`_
32+
33+
1. First, make sure you can connect to the Kubernetes cluster by following the quickstart guide of your chosen local Kubernetes cluster provider.
34+
```
35+
$ kubectl get nodes
36+
```
37+
Make sure you don't see any errors in your terminal. If do get error(s), please check the quickstart guide or the local Kubernetes cluster provider's documentation on how to get started.
38+
39+
1. Install the csi-driver-image using the helm chart.
40+
```
41+
helm upgrade --install wm-csi \
42+
charts/warm-metal-csi-driver \
43+
--wait
44+
```
45+
46+
1. You can submit an example for testing using `kubectl`:
47+
```bash
48+
kubectl create -f sample/ephemeral-volume.yaml
49+
```

0 commit comments

Comments
 (0)