Project: KubeBlocks by ApeCloud (App Definition and Development / Database)
File: 01 - build.md

There are two options for getting an environment up and running for `KubeBlocks` development. To build `KubeBlocks` on your own host, needs to install the following tools: Go (Golang) Make Download and install . `KubeBlocks` uses `make` for a variety of build and test actions, and needs to be installed as appropriate for your platform: Linux Install the `build-essential` package: ```shell sudo apt-get install build-essential ``` macOS Ensure that build tools are installed: ```shell xcode-select --install ``` When completed, you should see `make` and other command line developer tools in `/usr/bin`. When `go` and `make` are installed, you can clone the `KubeBlocks` repository, and build `KubeBlocks` binaries with the `make` tool. To build for your current local environment: ```shell make all ``` To cross-compile for a different platform, use the `GOOS` and `GOARCH` environmental variables: ```shell make all GOOS=windows GOARCH=amd64 ``` If you are using Visual Studio Code, you can connect to a configured for KubeBlocks development. With development container, you don't need to manually install all of the tools and frameworks needed. Install VSCode Open the `KubeBlocks` project folder in VSCode VSCode will detect the presence of a dev container definition in the repo and will prompt you to reopen the project in a container: Alternatively, you can open the command palette and use the Remote-Containers: Reopen in Container command: VSCode will pull image and start dev container automatically, once the container is loaded, open an integrated terminal in VS Code and you're ready to develop `KubeBlocks` in a containerized environment. And you can run `make all` to build `KubeBlocks` in the dev container. The uses the latest image from , you can customize image to suit your need. Edit the dev container image definition, you can change the `[Option]` configuration or install additional tools. ```Dockerfile COPY library-scripts/.sh library-scripts/.env /tmp/library-scripts/ ARG INSTALL_ZSH="true" ``` Build a new image using updated `Dockerfile`, and replace the `"image"` property in

```json { // Update to your dev container image "image": "docker.io/apecloud/kubeblocks-dev:latest", } ``` Rebuild and reopen the workspace in the dev container via the command palette and the `Remote-Containers: Rebuild and Reopen` in Container command. When you are satisfied with your changes, you can optionally publish your container image to your own registry to speed up rebuilding the container when you only want to make changes to the `devcontainer.json` configuration in the future. For a docker image named `docker.io/xxxx/kubeblocks-dev`: ```shell make build-dev-image DEVCONTAINERIMAGE_NAME=docker.io/xxxx/kubeblocks-dev ``` If you want to reuse an existing Kubernetes config, such as your cluster or local cluster, you can configure the `devcontainer.json` copy those settings into the dev container. This requires: Enabling the `SYNCLOCALHOSTKUBECONFIG` environment variable Bind mounting the locations of your Kubernetes and Minikube config paths to `/home/kubeblocks/.kube-localhost` and `/home/kubeblocks/.minikube-localhost` respectively. You don't need to bind the Minikube path if you're not using it. ```json "containerEnv": { // Uncomment to overwrite devcontainer .kube/config and .minikube certs with the localhost versions // each time the devcontainer starts, if the respective .kube-localhost/config and .minikube-localhost // folders respectively are bind mounted to the devcontainer. "SYNCLOCALHOSTKUBECONFIG": "true", }, ... "mounts": [ // Uncomment to clone local .kube/config into devcontainer "type=bind,source=${env:HOME}${env:USERPROFILE}/.kube,target=/home/kubeblocks/.kube-localhost", // Uncomment to additionally clone minikube certs into devcontainer for use with .kube/config "type=bind,source=${env:HOME}${env:USERPROFILE}/.minikube,target=/home/kubeblocks/.minikube-localhost" ] ``` The `SYNCLOCALHOSTKUBECONFIG` option only supports providing the dev container with the snapshot configuration from the host and does not support updating the host Kubernetes configuration from the dev container directly. To run `KubeBlocks`, you needs `Docker` and a `Kubernetes` 1.24.1+ cluster for development. Install > For Linux, you'll have to configure docker to run without `sudo` for the KubeBlocks build scripts to work. Follow the instructions to . Create your if you don't already have one. Kubernetes cluster You can use cloud Kubernetes service, such as , or use local Kubernetes cluster, such as . For development purposes, you will also want to follow the optional steps to install .