lifecycle/DEVELOPGUIDE.md
sealos only support Linux now, you need a Linux server to test it.
Some tools can be very handy to help you start a virtual machine such as multipass
wget https://go.dev/dl/go1.20.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.20.linux-amd64.tar.gz
cat >> /etc/profile <<EOF
# set go path
export PATH=\$PATH:/usr/local/go/bin
EOF
source /etc/profile && go version
git clone https://github.com/labring/sealos.git
cd sealos
make build BINS=sealos
You can scp the bin file to your Linux host.
If you use multipass, you can mount the bin dir to the vm:
multipass mount /your-bin-dir <name>[:<path>]
Then test it locally.
All the binaries except sealos can be built anywhere since they have CGO_ENABLED=0. However, sealos needs to support overlay driver when running some subcommands like images, which relies on CGO. Therefore, CGO is switched on when building sealos, making it impossible to build sealos binaries on platforms other than Linux.
Both Makefile and GoReleaser in this project have this setting.
As sealos is using go1.18's workspace feature, once you add a new module, you need to run go work use -r . at root directory to update the workspace synced.
/controllers first and cd into it.kubebuilder to init the project.go work use -r . at current directory to update the workspace.kubebuilder to create your CRD and ControllerYou can execute the following commands to do things above:
# cd sealos_code_dir
# edit the CRD_NAME and CRD_GROUP to your own
export CRD_NAME=Changeme
export CRD_GROUP=changeme
# copy and paste to create a new CRD and Controller
mkdir controllers/${CRD_NAME}
cd controllers/${CRD_NAME}
kubebuilder init --domain sealos.io --repo github.com/labring/sealos/controllers/${CRD_NAME}
# note: for darwin/arm64, execute the following command instead, refer: https://book.kubebuilder.io/quick-start.html#create-a-project
# kubebuilder init --domain sealos.io --repo github.com/labring/sealos/controllers/${CRD_NAME} --plugins=go/v4-alpha
go work use -r .
kubebuilder create api --group ${CRD_GROUP} --version v1 --kind ${CRD_NAME}
cd -
.PHONY: build
build:## Build manager binary.
CGO_ENABLED=0 go build -o bin/manager main.go
GOARCH=amd64 make build
mv bin/manager bin/controller-${{ matrix.module }}-amd64
chmod +x bin/controller-${{ matrix.module }}-amd64
GOARCH=arm64 make build
mv bin/manager bin/controller-${{ matrix.module }}-arm64
chmod +x bin/controller-${{ matrix.module }}-arm64
FROM gcr.io/distroless/static:nonroot
ARG TARGETARCH
WORKDIR /
USER 65532:65532
COPY bin/controller-${{ matrix.module }}-$TARGETARCH /manager
ENTRYPOINT ["/manager"]
docker buildx build \
--platform linux/amd64,linux/arm64 \
--push \
-t ${DOCKER_REPO}:${{ steps.prepare.outputs.tag_name }} \
-f Dockerfile \
.
.PHONY: deploy
pre-deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build -e SERVICE_NAME=webhook-service -e SERVICE_NAMESPACE=system config/default > deploy/manifests/deploy.yaml.tmpl
FROM scratch
USER 65532:65532
COPY manifests ./manifests/xxxx
COPY registry ./registry
CMD ["kubectl apply -f manifests/xxx"]
# edit the SEALOS_CODE_DIR to your own
export SEALOS_CODE_DIR=/Users/fanux/work/src/github.com/labring/sealos
# copy, paste and run to launch vm
multipass launch \
--mount ${SEALOS_CODE_DIR}:/go/src/github.com/labring/sealos \
--name sealos-dev --cpus 2 --mem 4G --disk 40G
multipass exec sealos-dev bash
sudo su
apt-get install build-essential
apt install make
wget https://go.dev/dl/go1.20.linux-arm64.tar.gz
tar -C /usr/local -zxvf go1.20.linux-arm64.tar.gz
cat >> /etc/profile <<EOF
# set go path
export PATH=\$PATH:/usr/local/go/bin
EOF
source /etc/profile && go version
go env -w GOPROXY=https://goproxy.cn,direct # optional
make build
git clone https://ghproxy.com/https://github.com/labring/sealosgo env -w GOPROXY=https://goproxy.cn,direct && make buildcgo: C compiler "x86_64-linux-gnu-gcc" not found: exec: "x86_64-linux-gnu-gcc": executable file not found in $PATH you need install gnu-gcc, like: apt-get install build-essential or yum -y install gcc-c++-x86_64-linux-gnu