diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..04dc2e0d4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.idea +bin diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 20ca199c1..1d18a3e4d --- a/Makefile +++ b/Makefile @@ -20,12 +20,12 @@ install-serverless-latest-release:## Install serverless from latest release make -C ${OPERATOR_ROOT} check-serverless-installation .PHONY: install-serverless-local-sources -install-serverless-local-sources: ## Install serverless from local sources +install-serverless-local-sources: ## Install serverless from local sources. $(eval IMG_VERSION=local-$(shell date +'%Y%m%d-%H%M%S')) IMG_VERSION=${IMG_VERSION} ./hack/build_all.sh $(eval IMG=europe-docker.pkg.dev/kyma-project/dev/serverless-operator:${IMG_VERSION}) - IMG_DIRECTORY="dev" IMG_VERSION=${IMG_VERSION} IMG=${IMG} make -C ${OPERATOR_ROOT} docker-build-local + IMG_DIRECTORY="kyma-project" IMG_VERSION=${IMG_VERSION} IMG=${IMG} make -C ${OPERATOR_ROOT} docker-build-local k3d image import "${IMG}" -c kyma IMG=${IMG} make install-serverless-custom-operator diff --git a/README.md b/README.md index e4d4f3e36..1d083fb3b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down - [Docker](https://www.docker.com/) - [kubectl](https://kubernetes.io/docs/tasks/tools/) - [Kubebuilder](https://book.kubebuilder.io/) +- [yq](https://mikefarah.gitbook.io/yq) ## Installation in the k3d Cluster Using Make Targets @@ -50,7 +51,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down git clone https://github.com/kyma-project/serverless.git && cd serverless/ ``` -2. Build Serverless Operator locally and run it in the k3d cluster. +2. Create a new k3d cluster and run Serverless from the main branch: ```bash make run-main @@ -58,7 +59,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down > **NOTE:** To clean up the k3d cluster, use the `make delete-k3d` make target. -> **NOTE:** If you have k3d already running you can use `install-*` target to install Serverless in different flavors. +> **NOTE:** If you have k3d already running, you can use the `install-*` targets to install Serverless in different flavors. ## Using Serverless Operator diff --git a/config/serverless/charts/docker-registry/templates/deployment.yaml b/config/serverless/charts/docker-registry/templates/deployment.yaml index 2ee14955f..2a1410efe 100644 --- a/config/serverless/charts/docker-registry/templates/deployment.yaml +++ b/config/serverless/charts/docker-registry/templates/deployment.yaml @@ -47,7 +47,7 @@ spec: hostIPC: false # Optional. The default is false if the entry is not there. initContainers: - name: generate-htpasswd - image: "{{ include "imageurl" (dict "reg" .Values.global.containerRegistry "img" .Values.global.images.registry) }}" + image: "{{ include "imageurl" (dict "reg" .Values.global.tpiContainerRegistry "img" .Values.global.images.registry) }}" {{- if .Values.initContainers.securityContext }} securityContext: {{- include "tplValue" ( dict "value" .Values.initContainers.securityContext "context" . ) | nindent 12 }} @@ -75,7 +75,7 @@ spec: containers: - name: {{ .Chart.Name }} - image: "{{ include "imageurl" (dict "reg" .Values.global.containerRegistry "img" .Values.global.images.registry) }}" + image: "{{ include "imageurl" (dict "reg" .Values.global.tpiContainerRegistry "img" .Values.global.images.registry) }}" imagePullPolicy: {{ .Values.image.pullPolicy }} {{- if .Values.containers.securityContext }} securityContext: diff --git a/config/serverless/templates/deployment.yaml b/config/serverless/templates/deployment.yaml index a505f82df..7e318ef14 100644 --- a/config/serverless/templates/deployment.yaml +++ b/config/serverless/templates/deployment.yaml @@ -140,7 +140,7 @@ spec: - name: APP_FUNCTION_BUILD_EXECUTOR_ARGS value: "{{.Values.containers.manager.configuration.data.functionBuildExecutorArgs }}" - name: APP_FUNCTION_BUILD_EXECUTOR_IMAGE - value: "{{ include "imageurl" (dict "reg" .Values.global.containerRegistry "img" .Values.global.images.kaniko_executor) }}" + value: "{{ include "imageurl" (dict "reg" .Values.global.tpiContainerRegistry "img" .Values.global.images.kaniko_executor) }}" - name: APP_FUNCTION_TARGET_CPU_UTILIZATION_PERCENTAGE value: "{{.Values.containers.manager.configuration.data.targetCPUUtilizationPercentage }}" - name: APP_FUNCTION_BUILD_REPO_FETCHER_IMAGE diff --git a/config/serverless/values.yaml b/config/serverless/values.yaml index 384a6e9f1..968ca4600 100644 --- a/config/serverless/values.yaml +++ b/config/serverless/values.yaml @@ -69,6 +69,8 @@ global: domainName: containerRegistry: path: europe-docker.pkg.dev/kyma-project + tpiContainerRegistry: + path: europe-docker.pkg.dev/kyma-project images: function_controller: name: "function-controller" diff --git a/hack/build_all.sh b/hack/build_all.sh index 3a0f5c92b..99172ceb8 100755 --- a/hack/build_all.sh +++ b/hack/build_all.sh @@ -6,10 +6,10 @@ echo "New tag: $IMG_VERSION" (cd "${HACK_DIR}" && pwd && docker compose build) for i in $(yq '.services[].image' ${HACK_DIR}/docker-compose.yaml); do - IMAGE_NAME=$(echo "${i}" | cut -d ":" -f 1) + IMAGE_NAME=$(echo "${i}" | cut -d ":" -f 1,2) NEW_IMAGE_NAME="${IMAGE_NAME}:${IMG_VERSION}" docker tag "${i}" "${NEW_IMAGE_NAME}" set -x - k3d image import "${NEW_IMAGE_NAME}" -c kyma + docker push "${NEW_IMAGE_NAME}" set +x done diff --git a/hack/docker-compose.yaml b/hack/docker-compose.yaml old mode 100644 new mode 100755 index 367fb6630..7094ce6b6 --- a/hack/docker-compose.yaml +++ b/hack/docker-compose.yaml @@ -1,38 +1,38 @@ services: # serverless function_controller: - image: europe-docker.pkg.dev/kyma-project/dev/function-controller:local + image: localhost:5000/kyma-project/function-controller:local platform: "linux/amd64" build: context: ../ dockerfile: components/serverless/deploy/manager/Dockerfile function_build_init: - image: europe-docker.pkg.dev/kyma-project/dev/function-build-init:local + image: localhost:5000/kyma-project/function-build-init:local platform: "linux/amd64" build: context: ../ dockerfile: components/serverless/deploy/jobinit/Dockerfile # runtimes function_runtime_nodejs18: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-nodejs18:local + image: localhost:5000/kyma-project/function-runtime-nodejs18:local platform: "linux/amd64" build: context: ../components/runtimes/nodejs dockerfile: nodejs18/Dockerfile function_runtime_nodejs20: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-nodejs20:local + image: localhost:5000/kyma-project/function-runtime-nodejs20:local platform: "linux/amd64" build: context: ../components/runtimes/nodejs dockerfile: nodejs20/Dockerfile function_runtime_python39: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-python39:local + image: localhost:5000/kyma-project/function-runtime-python39:local platform: "linux/amd64" build: context: ../components/runtimes/python dockerfile: python39/Dockerfile function_runtime_python312: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-python312:local + image: localhost:5000/kyma-project/function-runtime-python312:local platform: "linux/amd64" build: context: ../components/runtimes/python diff --git a/hack/k3d.mk b/hack/k3d.mk old mode 100644 new mode 100755 index 7eab3ad02..eaec9da47 --- a/hack/k3d.mk +++ b/hack/k3d.mk @@ -1,17 +1,17 @@ CLUSTER_NAME ?= kyma REGISTRY_PORT ?= 5001 -REGISTRY_NAME ?= ${CLUSTER_NAME}-registry +REGISTRY_NAME ?= ${CLUSTER_NAME}-registry.localhost ifndef PROJECT_ROOT $(error PROJECT_ROOT is undefined) endif -include $(PROJECT_ROOT)/hack/tools.mk ##@ K3D .PHONY: create-k3d -create-k3d: kyma ## Create k3d with kyma CRDs. - ${KYMA} provision k3d --registry-port ${REGISTRY_PORT} --name ${CLUSTER_NAME} --ci -p 6080:8080@loadbalancer -p 6433:8433@loadbalancer +create-k3d: delete-k3d ## Delete old k3d registry and cluster. Create preconfigured k3d with registry + k3d registry create ${REGISTRY_NAME} --port 5000 + k3d cluster create ${CLUSTER_NAME} --registry-use "k3d-${REGISTRY_NAME}:5000" kubectl create namespace kyma-system .PHONY: delete-k3d diff --git a/hack/replace_serverless_chart_images.sh b/hack/replace_serverless_chart_images.sh index 73bad3932..5f8eefdc7 100755 --- a/hack/replace_serverless_chart_images.sh +++ b/hack/replace_serverless_chart_images.sh @@ -2,6 +2,7 @@ # if you only need replace images with version set to "main" specify "main-only" argument REPLACE_SCOPE=$1 +VALUES_FILE=${PROJECT_ROOT}/config/serverless/values.yaml REQUIRED_ENV_VARIABLES=('IMG_DIRECTORY' 'IMG_VERSION' 'PROJECT_ROOT') for VAR in "${REQUIRED_ENV_VARIABLES[@]}"; do @@ -16,11 +17,16 @@ if [[ ${REPLACE_SCOPE} == "main-only" ]]; then MAIN_ONLY_SELECTOR="| select(.version == \"main\")" fi -IMAGES_SELECTOR=".global.images[] | select(key == \"function_*\") ${MAIN_ONLY_SELECTOR}" -VALUES_FILE=${PROJECT_ROOT}/config/serverless/values.yaml -yq -i "(${IMAGES_SELECTOR} | .directory) = \"${IMG_DIRECTORY}\"" ${VALUES_FILE} -yq -i "(${IMAGES_SELECTOR} | .version) = \"${IMG_VERSION}\"" ${VALUES_FILE} +if [[ ${PURPOSE} == "local" ]]; then + echo "Changing container registry" + yq -i '.global.containerRegistry.path="k3d-kyma-registry.localhost:5000"' "${VALUES_FILE}" +fi + +IMAGES_SELECTOR=".global.images[] | select(key == \"function_*\") ${MAIN_ONLY_SELECTOR}" +yq --inplace "(${IMAGES_SELECTOR} | .directory) = \"${IMG_DIRECTORY}\"" ${VALUES_FILE} +yq --inplace "(${IMAGES_SELECTOR} | .version) = \"${IMG_VERSION}\"" ${VALUES_FILE} echo "==== Local Changes ====" -yq '.global.images' ${VALUES_FILE} +yq '.global.images' "${VALUES_FILE}" +yq '.global.containerRegistry' "${VALUES_FILE}" echo "==== End of Local Changes ===="