Skip to content

Commit

Permalink
feat(devcontainer): ✨ Devcontainer configuration file for
Browse files Browse the repository at this point in the history
kubebuilder

Add Go templates for scaffolding DevContainer related configuration
files in a new Kubebuilder project.

refactor(dev-container): Add separate post-create.sh script.

refactor(dev-container): Use separate shell post create shell script in the container.

fix(dev-container): Remove redudant /bin/bash field.

:seedling: Bump github.com/onsi/ginkgo/v2 from 2.19.0 to 2.19.1

Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.19.0 to 2.19.1.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](onsi/ginkgo@v2.19.0...v2.19.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

:seedling: Bump github.com/onsi/gomega from 1.33.1 to 1.34.1

Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.33.1 to 1.34.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](onsi/gomega@v1.33.1...v1.34.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

fix: typo in designs template

Signed-off-by: Gabriele Quaresima <[email protected]>

refactor(.devcontainer/Dockerfile): Use Go to install Kind binary.

fix(.devcontainer): 🐛 Paas host network & update post-install script path.

Use Host network to connect with the Host OS's Docker network. Also, execute the post-install.sh script from .devcontainer sub-directory, not the root.

refactor(.devcontainer): Change go's version to 1.22.0.

refactor(.devcontainer/Dockefile): Download Kubebuilder binary directly.

refactor(.devcontainer/post-install.sh) Remove Makefile command.

refactor(.devcontainer): Add check for verifying the existing Kind cluster.

refactor(.devcontainer): Remove debug flag from post-install.sh

fix(.devcontainer): Change interpreter from sh to bash in post-install.sh.

refactor(templates): Add template for generating .devcontainer settings.

⚠️  (cleanup/fix): ImplementWebhooks method should only be used by the e2e tests and should be under its package (kubernetes-sigs#4065)

(cleanup/fix): ImplementWebhooks method should only be used by the e2e tests and should be under its package

(cleanup): cleanup tests for plugin/util functions

pkg/plugin/utils: add tests to cover funcs

🐛 (go/v4): add missing cancel context to controller's suite-test (kubernetes-sigs#4067)

fix: add missing cancel context to controller's suite-test

Upgrade the muilt-version sample to the latest

:seedling: Bump github.com/onsi/ginkgo/v2 from 2.19.1 to 2.20.0

Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.19.1 to 2.20.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](onsi/ginkgo@v2.19.1...v2.20.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

📖  docs:samples:cronjob: change makefile to generate the CRD without description to allow apply CRDs (kubernetes-sigs#4075)

docs:samples:cronjob: fix makefile to generate the CRD with less description

🌱 Cleanup hack generate docs by removing code duplication (kubernetes-sigs#4076)

(cleanup) hack docs

fix(devcontainer.go): Resolve golangci-lint related issues.

fix(devcontainer.go): Use bash command instead of '.' due to permission issuses.

chore: Remove testDev Container files.

docs(devcontainer): Generate documentation.

test(devcontainer): Add a GH Action for testing dev-container build.

test(devcontainer): Downgrade GH Runner to 20.04 Ubuntu.

refactor(templates): Remove commented settings, and fix licencse year.

ci(devcontainer): Remove commented code.

sparkles: Add support to k8s 1.31 and upgrade dependencies (kubernetes-sigs#4080)

Add support to k8s 1.31

Upgrade controller-gen used to generate the docs from 0.15.0 to 0.16.1

docs: improve and make clear info about setup envtest and its binaries

✨ upgrade kustomize from v5.4.2 to v5.4.3 (kubernetes-sigs#4084)

upgrade kustomize from v5.4.2 to v5.4.3

refactor(devcontainer): Remove Dockerfile template.

docs(devcontainer): Update test data files.

ci(devcontainer): Run CI workflow on everpy PR, and push.

chore: Fix linting typo.

docs(devcontainer): Update test data files.

ci(devcontainer): Run CI workflow on everpy PR, and push.

chore: Fix linting typo.

fix(devcontainer): Add license details in post-install.sh.

ci(devcontainer): Update runner image.

docs(devcontainer): Regenerate docs with license details.

✨ (go/v4): Remove hard-coded license details from the script template. (#1)

* Refactor:  remove hard-coded license details from the script.

* docs(devcontainer): Regenerate devcontainer docs to reflect binary links with latest tags.
  • Loading branch information
TAM360 committed Aug 18, 2024
1 parent c7cde51 commit 570eb09
Show file tree
Hide file tree
Showing 18 changed files with 470 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/workflows/test-devcontainer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test DevContainer Image

on:
push:
pull_request:

jobs:
test-devcontainer:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Go 1.22.x
uses: actions/setup-go@v5
with:
go-version: "1.22.x"

- name: Setup NodeJS 20.x
uses: actions/setup-node@v4
with:
node-version: "20.x"

- name: Setup Devcontainer CLI
run: |
npm install -g @devcontainers/cli
- name: Build and Validate DevContainer
run: |
cd testdata/project-v4
OUTPUT=$(devcontainer up --workspace-folder=./)
STATUS=$(echo "$OUTPUT" | jq -r '.outcome')
if [[ "$STATUS" == "success" ]]; then
echo "Devcontainer setup was successful."
exit 0
else
echo "Devcontainer setup failed."
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Kubebuilder DevContainer",
"image": "golang:1.22",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},

"runArgs": ["--network=host"],

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
]
}
},

"onCreateCommand": "bash .devcontainer/post-install.sh"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -x

curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind

curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
chmod +x kubebuilder
mv kubebuilder /usr/local/bin/

KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

kind version
kubebuilder version
docker --version
go version
kubectl version --client
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Kubebuilder DevContainer",
"image": "golang:1.22",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},

"runArgs": ["--network=host"],

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
]
}
},

"onCreateCommand": "bash .devcontainer/post-install.sh"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -x

curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind

curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
chmod +x kubebuilder
mv kubebuilder /usr/local/bin/

KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

kind version
kubebuilder version
docker --version
go version
kubectl version --client
2 changes: 2 additions & 0 deletions pkg/plugins/golang/v4/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@ func (s *initScaffolder) Scaffold() error {
&e2e.Test{},
&e2e.SuiteTest{},
&utils.Utils{},
&templates.DevContainer{},
&templates.DevContainerPostInstallScript{},
)
}
104 changes: 104 additions & 0 deletions pkg/plugins/golang/v4/scaffolds/internal/templates/devcontainer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package templates

import (
"sigs.k8s.io/kubebuilder/v4/pkg/machinery"
)

const devContainerTemplate = `{
"name": "Kubebuilder DevContainer",
"image": "golang:1.22",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},
"runArgs": ["--network=host"],
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
]
}
},
"onCreateCommand": "bash .devcontainer/post-install.sh"
}
`

const postInstallScript = `#!/bin/bash
set -x
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
chmod +x kubebuilder
mv kubebuilder /usr/local/bin/
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl
kind version
kubebuilder version
docker --version
go version
kubectl version --client
`

var _ machinery.Template = &DevContainer{}
var _ machinery.Template = &DevContainerPostInstallScript{}

// DevCotaniner scaffoldds a `devcontainer.json` configurations file for
// creating Kubebuilder & Kind based DevContainer.
type DevContainer struct {
machinery.TemplateMixin
}

type DevContainerPostInstallScript struct {
machinery.TemplateMixin
}

func (f *DevContainer) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = ".devcontainer/devcontainer.json"
}

f.TemplateBody = devContainerTemplate

return nil
}

func (f *DevContainerPostInstallScript) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = ".devcontainer/post-install.sh"
}

f.TemplateBody = postInstallScript

return nil
}
2 changes: 1 addition & 1 deletion test/check-license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -o pipefail
source $(dirname "$0")/common.sh

echo "Checking for license header..."
allfiles=$(listFiles|grep -v ./internal/bindata/...)
allfiles=$(listFiles | grep -v -e './internal/bindata/...' -e '.devcontainer/post-install.sh')
licRes=""
for file in $allfiles; do
if ! head -n4 "${file}" | grep -Eq "(Copyright|generated|GENERATED|Licensed)" ; then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Kubebuilder DevContainer",
"image": "golang:1.22",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},

"runArgs": ["--network=host"],

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
]
}
},

"onCreateCommand": "bash .devcontainer/post-install.sh"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -x

curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind

curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
chmod +x kubebuilder
mv kubebuilder /usr/local/bin/

KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

kind version
kubebuilder version
docker --version
go version
kubectl version --client
25 changes: 25 additions & 0 deletions testdata/project-v4-multigroup/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Kubebuilder DevContainer",
"image": "golang:1.22",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},

"runArgs": ["--network=host"],

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
]
}
},

"onCreateCommand": "bash .devcontainer/post-install.sh"
}

21 changes: 21 additions & 0 deletions testdata/project-v4-multigroup/.devcontainer/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -x

curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind

curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
chmod +x kubebuilder
mv kubebuilder /usr/local/bin/

KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

kind version
kubebuilder version
docker --version
go version
kubectl version --client
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Kubebuilder DevContainer",
"image": "golang:1.22",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},

"runArgs": ["--network=host"],

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
]
}
},

"onCreateCommand": "bash .devcontainer/post-install.sh"
}

Loading

0 comments on commit 570eb09

Please sign in to comment.