Skip to content

Commit

Permalink
build: Add devcontainer (#117)
Browse files Browse the repository at this point in the history
Signed-off-by: Mriyam Tamuli <[email protected]>
  • Loading branch information
mbtamuli authored Jan 21, 2024
1 parent a2e26ec commit 46df7e8
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// For format details, see https://containers.dev
{
"name": "csi-driver-image dev container",
"image": "ghcr.io/warm-metal/csi-driver-image/devcontainer:latest",

// Setup the go environment and mount into the dev container at the expected location
"workspaceFolder": "/go/src/github.com/warm-metal/csi-driver-image",
"workspaceMount": "source=${localWorkspaceFolder},target=/go/src/github.com/warm-metal/csi-driver-image,type=bind,consistency=cached",

// Copy over welcome message
"postCreateCommand": "sudo cp .devcontainer/welcome.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt"
}
7 changes: 7 additions & 0 deletions .devcontainer/welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
👋 Welcome to your development environment for CSI Driver Image!

This debian dev container image contains all tools needed for development.

Get started right away! 🚀

Check out the guide in docs/running-locally.md
40 changes: 40 additions & 0 deletions .github/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// For format details, see https://containers.dev
{
"name": "csi-driver-image dev container",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",

"otherPortsAttributes": {
"onAutoForward": "silent"
},

"features": {
"ghcr.io/devcontainers/features/go:1": {
"version": "1.19"
},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
"version": "latest",
"helm": "latest",
"minikube": "none"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"dockerDashComposeVersion": "v2"
},
"ghcr.io/devcontainers-contrib/features/kind:1": {}
},

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "zsh"
}
}
},
"extensions": [
"golang.go"
]
}
}
}
39 changes: 39 additions & 0 deletions .github/workflows/devcontainer-build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Dev Container Build and Push Image

on:
push:
branches:
master
paths:
- .github/workflows/devcontainer-build-and-push.yml
- '.github/.devcontainer/**'
pull_request:
paths:
- .github/workflows/devcontainer-build-and-push.yml
- '.github/.devcontainer/**'

permissions:
contents: read
packages: write

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pre-build dev container image
uses: devcontainers/[email protected]
with:
subFolder: .github
imageName: ghcr.io/${{ github.repository }}/devcontainer
cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
push: always
49 changes: 49 additions & 0 deletions docs/running-locally.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Running Locally

You have two options:

1. Use the [Dev Container](#development-container). This is the recommended approach. This can be used with VSCode, the `devcontainer` CLI, or GitHub Codespaces.
1. Install the [requirements](#requirements) on your computer manually.

## Development Container

The development container contains all the tools necessary to work with csi-driver-image.

You can use the development container in a few different ways:

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.
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.
1. [GitHub Codespaces](https://github.com/codespaces). You can start editing as soon as VSCode is open.

Once you have entered the container, continue to [Developing Locally](#developing-locally).

## Requirements

To build on your own machine without using the Dev Container you will need:

* A local clone of this repository.
* [Go](https://golang.org/dl/)
* 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/))
* [`helm`](https://helm.sh/docs/intro/install/)

## Developing locally

_**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`_

1. First, make sure you can connect to the Kubernetes cluster by following the quickstart guide of your chosen local Kubernetes cluster provider.
```
$ kubectl get nodes
```
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.

1. Install the csi-driver-image using the helm chart.
```
helm upgrade --install wm-csi \
charts/warm-metal-csi-driver \
--wait
```

1. You can submit an example for testing using `kubectl`:
```bash
kubectl create -f sample/ephemeral-volume.yaml
```

0 comments on commit 46df7e8

Please sign in to comment.