diff --git a/docs/development-guide.md b/CONTRIBUTING.md similarity index 71% rename from docs/development-guide.md rename to CONTRIBUTING.md index 93e0df2a3d2a19de65e5e3b266c2c6cca1869968..081db03a9629c820234498d54bbb5c3ad9412bf7 100644 --- a/docs/development-guide.md +++ b/CONTRIBUTING.md @@ -17,14 +17,15 @@ KubeSphere development is based on [Kubernetes](https://github.com/kubernetes/ku environment instructions. > - It's recommended to install [macOS GNU tools](https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x) for Mac OS. +### Docker + +KubeSphere components are often deployed as containers in Kubernetes. If you need to rebuild the KubeSphere components in the Kubernetes cluster, you will need to [install Docker](https://docs.docker.com/install/). + ### Dependency management -KubeSphere uses `dep` to manage dependencies in the `vendor/` tree, execute following command to install [dep](https://github.com/golang/dep). +KubeSphere uses [Go Modules](https://github.com/golang/go/wiki/Modules) to manage dependencies in the `vendor/` tree. -```go -go get -u github.com/golang/dep/cmd/dep -``` #### Dependencies [kubesphere/kubesphere](https://github.com/kubesphere/kubesphere) repository contains the source code . If you're looking for its dependent components, they live in their own repositories since they can be individual and universal. @@ -34,6 +35,50 @@ go get -u github.com/golang/dep/cmd/dep - [OpenPitrix](https://github.com/openpitrix/openpitrix): Application management platform on multi-cloud environment, it provides application template and application management for KubeSphere currently. - [SonarQube](https://github.com/SonarSource/sonarqube): Integrated in KubeSphere DevOps, it provides the capability to not only show health of an application but also to highlight issues newly introduced. +## Building KubeSphere on a local OS/shell environment + +### For Quick Taste Binary + +```bash +mkdir ks-tmp +cd ks-tmp +echo 'module kubesphere' > go.mod +echo 'replace ( + github.com/Sirupsen/logrus v1.4.1 => github.com/sirupsen/logrus v1.4.1 + github.com/kiali/kiali => github.com/kubesphere/kiali v0.15.1-0.20190407071308-6b5b818211c3 + github.com/kubernetes-sigs/application => github.com/kubesphere/application v0.0.0-20190518133311-b9d9eb0b5cf7 + )' >> go.mod + +GO111MODULE=on go get kubesphere.io/kubesphere@d649e3d0bbc64bfba18816c904819e4850d021e0 +GO111MODULE=on go build -o ks-apiserver kubesphere.io/kubesphere/cmd/ks-apiserver # build ks-apiserver +GO111MODULE=on go build -o ks-apigateway kubesphere.io/kubesphere/cmd/ks-apigateway # build ks-apigateway +GO111MODULE=on go build -o ks-controller-manager kubesphere.io/kubesphere/cmd/controller-manager # build ks-controller-manager +GO111MODULE=on go build -o ks-iam kubesphere.io/kubesphere/cmd/ks-iam # build ks-iam +``` + +### For Building KubeSphere Images + +KubeSphere components are often deployed as a container in a kubernetes cluster, you may need to build a Docker image locally. + +1. Clone repo to local + +```bash +git clone https://github.com/kubesphere/kubesphere.git +``` + +2. Run Docker command to build image + +```bash +# $REPO is the docker registry to push to +# $Tag is the tag name of the docker image +# The full go build process will be executed in the Dockerfile, so you may need to set GOPROXY in it. +docker build -f build/ks-apigateway/Dockerfile -t $REPO/ks-apigateway:$TAG . +docker build -f build/ks-apiserver/Dockerfile -t $REPO/ks-apiserver:$TAG . +docker build -f build/ks-iam/Dockerfile -t $REPO/ks-account:$TAG . +docker build -f build/ks-controller-manager/Dockerfile -t $REPO/ks-controller-manager:$TAG . +docker build -f ./pkg/db/Dockerfile -t $REPO/ks-devops:flyway-$TAG ./pkg/db/ +``` + ### Test In the development process, it is recommended to use local Kubernetes clusters, such as [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/), or to install an single-node [all-in-one](https://github.com/kubesphere/kubesphere#all-in-one) environment (Kubernetes-based) for quick testing. @@ -42,7 +87,7 @@ In the development process, it is recommended to use local Kubernetes clusters, ## Development Workflow -![ks-workflow](images/ks-workflow.png) +![ks-workflow](docs/images/ks-workflow.png) ### 1 Fork in the cloud @@ -173,4 +218,4 @@ Please reference [Code conventions](https://github.com/kubernetes/community/blob > - All new packages and most new significant functionality must come with unit tests > - Comment your code in English, see [Go's commenting conventions -](http://blog.golang.org/godoc-documenting-go-code) \ No newline at end of file +](http://blog.golang.org/godoc-documenting-go-code) diff --git a/README.md b/README.md index c54e4d5ebbf485c44bd7ff3c59b6f0913bff9c72..e49f337e8d38dea5fe055c6890e5a691f3d8b703 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ The [Quick Start Guide](https://docs.kubesphere.io/advanced-v2.0/quick-start/adm ## To start developing KubeSphere -The [development guide](docs/development-guide.md) hosts all information about building KubeSphere from source, git workflow, how to contribute code and how to test. +The [development guide](CONTRIBUTING.md) hosts all information about building KubeSphere from source, git workflow, how to contribute code and how to test. ## RoadMap diff --git a/build/ks-apigateway/Dockerfile b/build/ks-apigateway/Dockerfile index 85b1e7d3753a258d722858d14926a62fd0a5992a..61700244d50b08ec5fafd53e68e25c42079723ff 100644 --- a/build/ks-apigateway/Dockerfile +++ b/build/ks-apigateway/Dockerfile @@ -10,11 +10,11 @@ FROM golang:1.12 as ks-apigateway-builder COPY / /go/src/kubesphere.io/kubesphere WORKDIR /go/src/kubesphere.io/kubesphere -RUN CGO_ENABLED=0 GO111MODULE=off GOOS=linux GOARCH=amd64 go build -i -ldflags '-w -s' -o ks-apigateway cmd/ks-apigateway/apiserver.go && \ +RUN CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 GOFLAGS=-mod=vendor go build -i -ldflags '-w -s' -o ks-apigateway cmd/ks-apigateway/apiserver.go && \ go run tools/cmd/doc-gen/main.go --output=install/swagger-ui/api.json FROM alpine:3.9 RUN apk add --update ca-certificates && update-ca-certificates COPY --from=ks-apigateway-builder /go/src/kubesphere.io/kubesphere/ks-apigateway /usr/local/bin/ COPY --from=ks-apigateway-builder /go/src/kubesphere.io/kubesphere/install/swagger-ui /var/static/swagger-ui -CMD ["sh"] \ No newline at end of file +CMD ["sh"] diff --git a/build/ks-apiserver/Dockerfile b/build/ks-apiserver/Dockerfile index ae6171773377f8f3c7a65ff9d1ce098a77a80121..6b83416dc232827fb1db1241db467b5850124085 100644 --- a/build/ks-apiserver/Dockerfile +++ b/build/ks-apiserver/Dockerfile @@ -10,7 +10,7 @@ FROM golang:1.12 as ks-apiserver-builder COPY / /go/src/kubesphere.io/kubesphere WORKDIR /go/src/kubesphere.io/kubesphere -RUN CGO_ENABLED=0 GO111MODULE=off GOOS=linux GOARCH=amd64 go build -i -ldflags '-w -s' -o ks-apiserver cmd/ks-apiserver/apiserver.go +RUN CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 GOFLAGS=-mod=vendor go build -i -ldflags '-w -s' -o ks-apiserver cmd/ks-apiserver/apiserver.go FROM alpine:3.9 RUN apk add --update ca-certificates && update-ca-certificates diff --git a/build/ks-controller-manager/Dockerfile b/build/ks-controller-manager/Dockerfile index 45b1025c75a94db152be39f18e9977c0d11927e7..ed8a1cc13e978736c4c74630e1a2c80701d7538d 100644 --- a/build/ks-controller-manager/Dockerfile +++ b/build/ks-controller-manager/Dockerfile @@ -10,7 +10,7 @@ FROM golang:1.12 as controller-manager-builder COPY / /go/src/kubesphere.io/kubesphere WORKDIR /go/src/kubesphere.io/kubesphere -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build --ldflags "-extldflags -static" -o controller-manager ./cmd/controller-manager/ +RUN CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 GOFLAGS=-mod=vendor go build --ldflags "-extldflags -static" -o controller-manager ./cmd/controller-manager/ FROM alpine:3.7 RUN apk add --update ca-certificates && update-ca-certificates diff --git a/build/ks-iam/Dockerfile b/build/ks-iam/Dockerfile index a8bb9c17e8b7c180dbca573112b3046d4c2b9be9..3e65a47e8e0f7846dd33c9a698247739a8e356c0 100644 --- a/build/ks-iam/Dockerfile +++ b/build/ks-iam/Dockerfile @@ -10,7 +10,7 @@ FROM golang:1.12 as ks-iam-builder COPY / /go/src/kubesphere.io/kubesphere WORKDIR /go/src/kubesphere.io/kubesphere -RUN CGO_ENABLED=0 GO111MODULE=off GOOS=linux GOARCH=amd64 go build -i -ldflags '-w -s' -o ks-iam cmd/ks-iam/apiserver.go +RUN CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 GOFLAGS=-mod=vendor go build -i -ldflags '-w -s' -o ks-iam cmd/ks-iam/apiserver.go FROM alpine:3.9 RUN apk add --update ca-certificates && update-ca-certificates diff --git a/hack/docker_build.sh b/hack/docker_build.sh index 6d68bdbe997d6217d6b3b8c89bafcb36317ba34a..0163be392549aa646b6bca450051f6fdaffd7407 100755 --- a/hack/docker_build.sh +++ b/hack/docker_build.sh @@ -7,9 +7,7 @@ REPO=kubespheredev TAG=latest # check if build was triggered by a travis cronjob -if [[ ! -v TRAVIS_EVENT_TYPE ]]; then - echo "TRAVIS_EVENT_TYPE is not set, treat as regular build" -elif [[ -z "$TRAVIS_EVENT_TYPE" ]]; then +if [[ -z "$TRAVIS_EVENT_TYPE" ]]; then echo "TRAVIS_EVENT_TYPE is empty, also normaly build" elif [ $TRAVIS_EVENT_TYPE == "cron" ]; then TAG=dev-$(date +%Y%m%d)