Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Add Dev Container #991

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/devcontainers/go:1.22-bullseye

# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y

# add cert authority for ssl
RUN mkdir -p /registry/certs && \
openssl req -newkey rsa:4096 -nodes -sha256 -keyout /registry/certs/ociregistry.key -addext "subjectAltName = DNS:localhost" -x509 -days 365 -out /registry/certs/ociregistry.crt -subj "/C=DE/ST=Baden-Wuertemberg/L=Walldorf/O=SAP-LOCAL-DEV/OU=ocm/CN=localhost"
RUN cp /registry/certs/ociregistry.crt /usr/local/share/ca-certificates && \
update-ca-certificates


RUN go install github.com/gardener/landscapercli/landscaper-cli@latest
RUN curl -s https://ocm.software/install.sh | sudo bash
11 changes: 11 additions & 0 deletions .devcontainer/context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: landscaper.gardener.cloud/v1alpha1
kind: Context
metadata:
name: default-context
namespace: default

repositoryContext:
baseUrl: localhost:443
type: ociRegistry

useOCM: true
96 changes: 96 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Existing Dockerfile",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "Dockerfile"
},

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"moby": true,
"azureDnsAutoDetection": true,
"installDockerBuildx": true,
"version": "latest",
"dockerDashComposeVersion": "v2"
},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
"version": "latest",
"helm": "latest",
"minikube": "latest"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line to run commands after the container is created.
"postCreateCommand": "bash .devcontainer/scripts/post-create.sh",
"postStartCommand": "bash .devcontainer/scripts/post-start.sh",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "DCON: Landscaper Minikube debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/landscaper-controller/main.go",
"args": [
"--config=${workspaceFolder}/.devcontainer/landscaper-config.yaml",
"--deployers=container,helm,mock,manifest",
],
"env": {
"KUBECONFIG": "/home/vscode/.kube/kubeconfig--minikube-local.yaml"
},
},
{
"name": "DCON: HelmDeployer Minikube debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/helm-deployer-controller/main.go",
"args": [
"--config=${workspaceFolder}/.devcontainer/landscaper-config.yaml",
],
"env": {
"KUBECONFIG": "/home/vscode/.kube/kubeconfig--minikube-local.yaml"
},
},
{
"name": "DCON: ManifestDeployer Minikube debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/manifest-deployer-controller/main.go",
"args": [
"--config=${workspaceFolder}/.devcontainer/landscaper-config.yaml",
],
"env": {
"KUBECONFIG": "/home/vscode/.kube/kubeconfig--minikube-local.yaml"
},
},
],
"compounds": []
}
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker",
"golang.go"
]
}
},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
22 changes: 22 additions & 0 deletions .devcontainer/landscaper-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
deployers:
- container
- helm
- manifest
- mock

deployerManagement:
disable: false
agent:
disable: false

useOCMLib: true

# deployItemTimeouts:
# pickup: 10s
# abort: 10s
# progressingDefault: 1m

crdManagement:
deployCrd: true
forceUpdate: true

32 changes: 32 additions & 0 deletions .devcontainer/sample-installation/blueprint/blueprint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: landscaper.gardener.cloud/v1alpha1
kind: Blueprint
jsonSchema: "https://json-schema.org/draft/2019-09/schema"

imports:
- name: cluster
type: target
targetType: landscaper.gardener.cloud/kubernetes-cluster

deployExecutions:
- name: default
type: GoTemplate
template: |
deployItems:
- name: default-deploy-item
type: landscaper.gardener.cloud/helm

target:
import: cluster

config:
apiVersion: helm.deployer.landscaper.gardener.cloud/v1alpha1
kind: ProviderConfiguration
name: hello-world
namespace: example
createNamespace: true

chart:
ref: eu.gcr.io/gardener-project/landscaper/examples/charts/hello-world:1.0.0

values:
testData: hello
15 changes: 15 additions & 0 deletions .devcontainer/sample-installation/components.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
components:
- name: registry.local/sample/component
version: v1.0.0
provider:
name: internal
resources:
- name: blueprint
type: landscaper.gardener.cloud/blueprint
# the available input types can be found in the help of the command line tool through
# ocm add resources --help
input:
type: dir
path: ./blueprint
compress: true
mediaType: application/vnd.gardener.landscaper.blueprint.v1+tar+gzip
25 changes: 25 additions & 0 deletions .devcontainer/sample-installation/installation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: landscaper.gardener.cloud/v1alpha1
kind: Installation
metadata:
name: sample
namespace: default
annotations:
landscaper.gardener.cloud/operation: reconcile

spec:
context: default-context

componentDescriptor:
ref:
componentName: registry.local/sample/component
version: v1.0.0

blueprint:
ref:
resourceName: blueprint

# Set values for the import parameters of the blueprint
imports:
targets:
- name: cluster # name of an import parameter of the blueprint
target: minikube-from-host # name of the Target custom resource containing the kubeconfig of the target cluster
24 changes: 24 additions & 0 deletions .devcontainer/scripts/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -e

# run once on post-create and it will be always restarted automatically when the container restarts
echo "Start or create registry"
docker start registry || docker run -d -p 443:443 --restart always --name registry \
-v /registry/certs/:/certs \
-e REGISTRY_HTTP_ADDR=:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/ociregistry.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/ociregistry.key \
registry:2

echo "Start minikube"
minikube start

# apply CRDs to minikube
echo "Apply landscaper CRDs to minikube cluster"
kubectl apply -f /workspaces/landscaper/.crd/

# create sample ocm componentversion and add it to registry
echo "Create and push a sample componentversion with blueprint"
ocm add components --create --file /workspaces/landscaper/.devcontainer/sample-installation/sample-component /workspaces/landscaper/.devcontainer/sample-installation/components.yaml
ocm transfer ctf /workspaces/landscaper/.devcontainer/sample-installation/sample-component OCIRegistry::localhost:443
21 changes: 21 additions & 0 deletions .devcontainer/scripts/post-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -e

# TODO check if this is necessary or if it will be automatically started
if [ $( docker ps -a -f name=minikube | wc -l ) -eq 2 ]; then
echo "minikube already started"
else
echo "minikube not started yet, creating..."
minikube start
fi

echo "Exporting minikube config to yaml file"
kubectl config view --raw > ~/.kube/kubeconfig--minikube-local.yaml

echo "Build minikube target and apply to cluster"
# creates a target.landscaper.gardener.cloud by combining the target.yaml with an indended minikube kubeconfig. Uses <() as process substitution to use command output as a file for kubectl
kubectl apply -f <(cat .devcontainer/target-template.yaml; cat ~/.kube/kubeconfig--minikube-local.yaml | sed 's/^/ /')

echo "Apply context to cluster"
kubectl apply -f /workspaces/landscaper/.devcontainer/context.yaml
9 changes: 9 additions & 0 deletions .devcontainer/target-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: landscaper.gardener.cloud/v1alpha1
kind: Target
metadata:
name: minikube-from-host
namespace: default
spec:
type: landscaper.gardener.cloud/kubernetes-cluster
config:
kubeconfig: |
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly