diff --git a/Makefile b/Makefile index 744437e79f..8e03a180b9 100644 --- a/Makefile +++ b/Makefile @@ -90,12 +90,16 @@ mock: mockgen -source=pkg/handlers/interface.go -destination=pkg/handlers/mock/mock.go mockgen -source=pkg/operator/client/client_interface.go -destination=pkg/operator/client/mock/mock.go +.PHONY: dev-deps +dev-deps: + @dev/scripts/dev-deps.sh + .PHONY: dev -dev: +dev: dev-deps @dev/scripts/dev.sh .PHONY: %-up -%-up: +%-up: dev-deps @dev/scripts/up.sh $* .PHONY: %-down @@ -103,7 +107,7 @@ dev: @dev/scripts/down.sh $* .PHONY: %-up-ec -%-up-ec: +%-up-ec: dev-deps @dev/scripts/up-ec.sh $* .PHONY: %-down-ec diff --git a/README.md b/README.md index 1fcfae0d99..33a5da6a72 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ cosign verify-blob --key sbom/key.pub --signature sbom/kots-sbom.tgz.sig sbom/ko - MacOS - Docker Desktop with Kubernetes enabled -- jq +- Homebrew ### Running the Development Environment diff --git a/dev/patches/kotsadm-up.yaml b/dev/patches/kotsadm-up.yaml index ea0958a1e7..167c7c417e 100644 --- a/dev/patches/kotsadm-up.yaml +++ b/dev/patches/kotsadm-up.yaml @@ -4,8 +4,19 @@ spec: volumes: - name: dev hostPath: - path: __PROJECT_DIR__ + path: {{ .Env.PROJECT_DIR }} type: Directory +{{- if .Env.EC_NODE }} + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - {{ .Env.EC_NODE }} +{{- end }} containers: - name: kotsadm image: kotsadm-api-dev diff --git a/dev/patches/kotsadm-web-up.yaml b/dev/patches/kotsadm-web-up.yaml index 0595d2f135..b1c28eb971 100644 --- a/dev/patches/kotsadm-web-up.yaml +++ b/dev/patches/kotsadm-web-up.yaml @@ -1,14 +1,25 @@ spec: template: spec: +{{- if .Env.EC_NODE }} + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - {{ .Env.EC_NODE }} +{{- end }} volumes: - name: dev hostPath: - path: __PROJECT_DIR__/web + path: {{ .Env.PROJECT_DIR }}/web type: Directory - name: yarncache hostPath: - path: __PROJECT_DIR__/dev/.yarncache + path: {{ .Env.PROJECT_DIR }}/dev/.yarncache type: Directory containers: - name: kotsadm-web diff --git a/dev/patches/kurl-proxy-up.yaml b/dev/patches/kurl-proxy-up.yaml index c924d4fb0c..1d2bd1659a 100644 --- a/dev/patches/kurl-proxy-up.yaml +++ b/dev/patches/kurl-proxy-up.yaml @@ -4,12 +4,23 @@ spec: volumes: - name: dev hostPath: - path: __PROJECT_DIR__ + path: {{ .Env.PROJECT_DIR }} type: Directory - name: assets hostPath: - path: __PROJECT_DIR__/kurl_proxy/assets + path: {{ .Env.PROJECT_DIR }}/kurl_proxy/assets type: Directory +{{- if .Env.EC_NODE }} + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - {{ .Env.EC_NODE }} +{{- end }} containers: - name: proxy image: kurl-proxy-dev diff --git a/dev/scripts/common.sh b/dev/scripts/common.sh index 700790fb1d..77649b2fe3 100644 --- a/dev/scripts/common.sh +++ b/dev/scripts/common.sh @@ -68,12 +68,12 @@ function restart() { # the mounted directories from the macOS host filesystem into the Docker Desktop VM. # This is required for using HostPath volumes in Kubernetes. function render() { - sed "s|__PROJECT_DIR__|/host_mnt$(pwd)|g" "$1" + PROJECT_DIR="/host_mnt$(pwd)" gomplate --missing-key zero -f "$1" } # The embedded-cluster container mounts the KOTS project at /replicatedhq/kots function ec_render() { - sed "s|__PROJECT_DIR__|/replicatedhq/kots|g" "$1" + EC_NODE=$(ec_node) PROJECT_DIR="/replicatedhq/kots" gomplate --missing-key zero -f "$1" } # Get the embedded cluster node name diff --git a/dev/scripts/dev-deps.sh b/dev/scripts/dev-deps.sh new file mode 100755 index 0000000000..2a66c83ad4 --- /dev/null +++ b/dev/scripts/dev-deps.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +function is_not_in_path() { + if ! command -v "$1" > /dev/null; then + echo "$1 is not installed" + return 0 + fi + return 1 +} + +function check_gomplate() { + if is_not_in_path gomplate; then + echo "gomplate is not installed. Installing it now." + go install github.com/hairyhenderson/gomplate/v4/cmd/gomplate@latest + fi +} + +function check_jq() { + if is_not_in_path jq; then + echo "jq is not installed. Attempting to install it using brew." + if is_not_in_path brew; then + echo "brew is not installed. Please install jq manually." + return + fi + brew install jq + fi +} + +check_gomplate +check_jq