Skip to content

Commit

Permalink
optimize: optimize makefile targets and speed up docker build (fluid-…
Browse files Browse the repository at this point in the history
…cloudnative#3246)

* Remove dlv binary in Dockerfiles

Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>

* Optimize makefile targets

Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>

* Fix csi fuse recovery testcase

Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>

* Move "OpenAPI validation check" to lint CI task

Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>

---------

Signed-off-by: trafalgarzzz <trafalgarz@outlook.com>
  • Loading branch information
TrafalgarZZZ authored May 24, 2023
1 parent 0f7d87c commit 37e17c6
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 102 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ jobs:
make update-crd
git status --porcelain
if [ -z "`git status --porcelain`" ]; then echo "CRD validation passed."; else echo "CRD validation failed. Please use 'make update-crd' to keep CRDs latest"; exit 1; fi
- name: OpenAPI validation check
run: |
make gen-openapi
echo $(git status --porcelain | grep generated)
if [ -z "$(git status --porcelain | grep generated)" ]; then echo "openapi validation passed."; else echo "openapi validation failed. Please use 'make gen-openapi' to update openapi"; exit 1; fi
- name: Project lint
run: |
Expand Down Expand Up @@ -94,6 +101,4 @@ jobs:
run: |
make build
make test
echo $(git status --porcelain | grep generated)
if [ -z "$(git status --porcelain | grep generated)" ]; then echo "openapi validation passed."; else echo "openapi validation failed. Please use 'make build' to update openapi"; exit 1; fi
bash <(curl -s https://codecov.io/bash)
147 changes: 63 additions & 84 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,115 +118,99 @@ test: generate fmt vet
unit-test: generate fmt vet
GO111MODULE=${GO_MODULE} go list ./... | grep -v controller | grep -v e2etest | xargs go test ${CI_TEST_FLAGS} ${LOCAL_FLAGS}

# Build binary
# Make code, artifacts, dependencies, and CRDs fresh.
pre-setup: generate fmt vet update-crd gen-openapi

# Generate code
generate: controller-gen
GO111MODULE=${GO_MODULE} $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."

# Run go fmt against code
fmt:
GO111MODULE=${GO_MODULE} go fmt ./...

build: ${BINARY_BUILD}
# Run go vet against code
vet:
GO111MODULE=${GO_MODULE} go list ./... | grep -v "vendor" | xargs go vet

# Update fluid crds
update-crd: manifests
cp config/crd/bases/* charts/fluid/fluid/crds

csi-build: generate fmt vet
gen-openapi:
./hack/gen-openapi.sh

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
GO111MODULE=${GO_MODULE} $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

gen-sdk:
./hack/sdk/gen-sdk.sh

update-api-doc:
bash tools/api-doc-gen/generate_api_doc.sh && mv tools/api-doc-gen/api_doc.md docs/zh/dev/api_doc.md && cp docs/zh/dev/api_doc.md docs/en/dev/api_doc.md

# Build binary
build: pre-setup ${BINARY_BUILD}

csi-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/fluid-csi -ldflags '${LDFLAGS}' cmd/csi/main.go

dataset-controller-build: generate gen-openapi fmt vet
dataset-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/dataset-controller -ldflags '${LDFLAGS}' cmd/dataset/main.go

alluxioruntime-controller-build: generate gen-openapi fmt vet
alluxioruntime-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/alluxioruntime-controller -ldflags '${LDFLAGS}' cmd/alluxio/main.go

jindoruntime-controller-build: generate gen-openapi fmt vet
jindoruntime-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/jindoruntime-controller -ldflags '${LDFLAGS}' cmd/jindo/main.go

goosefsruntime-controller-build: generate gen-openapi fmt vet
goosefsruntime-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/goosefsruntime-controller -ldflags '${LDFLAGS}' cmd/goosefs/main.go

juicefsruntime-controller-build: generate gen-openapi fmt vet
juicefsruntime-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/juicefsruntime-controller -ldflags '-s -w ${LDFLAGS}' cmd/juicefs/main.go

thinruntime-controller-build: generate gen-openapi fmt vet
thinruntime-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/thinruntime-controller -ldflags '-s -w ${LDFLAGS}' cmd/thin/main.go

efcruntime-controller-build: generate gen-openapi fmt vet
efcruntime-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/efcruntime-controller -ldflags '${LDFLAGS}' cmd/efc/main.go

webhook-build: generate fmt vet
webhook-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/fluid-webhook -ldflags '${LDFLAGS}' cmd/webhook/main.go

application-controller-build: generate fmt vet
application-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go build ${GC_FLAGS} -a -o bin/fluidapp-controller -ldflags '${LDFLAGS}' cmd/fluidapp/main.go

# Debug against the configured Kubernetes cluster in ~/.kube/config, add debug
debug: generate fmt vet manifests
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} dlv debug --headless --listen ":12345" --log --api-version=2 cmd/controller/main.go

# Debug against the configured Kubernetes cluster in ~/.kube/config, add debug
debug-csi: generate fmt vet manifests
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} dlv debug --headless --listen ":12346" --log --api-version=2 cmd/csi/main.go -- --nodeid=cn-hongkong.172.31.136.194 --endpoint=unix://var/lib/kubelet/csi-plugins/fuse.csi.fluid.io/csi.sock

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=${GO_MODULE} go run cmd/controller/main.go

# Install CRDs into a cluster
install: manifests
kustomize build config/crd | kubectl apply -f -

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
GO111MODULE=${GO_MODULE} $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

# Run go fmt against codecsi-node-driver-registrar
fmt:
GO111MODULE=${GO_MODULE} go fmt ./...

# Run go vet against code
vet:
GO111MODULE=${GO_MODULE} go list ./... | grep -v "vendor" | xargs go vet

# Generate code
generate: controller-gen
GO111MODULE=${GO_MODULE} $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."

# Update fluid helm chart
update-crd: manifests
cp config/crd/bases/* charts/fluid/fluid/crds

update-api-doc:
bash tools/api-doc-gen/generate_api_doc.sh && mv tools/api-doc-gen/api_doc.md docs/zh/dev/api_doc.md && cp docs/zh/dev/api_doc.md docs/en/dev/api_doc.md

# Build the docker image
docker-build-dataset-controller: generate gen-openapi fmt vet
docker-build-dataset-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.dataset -t ${DATASET_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-application-controller: generate fmt vet
docker-build-application-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.application -t ${APPLICATION_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-alluxioruntime-controller: generate gen-openapi fmt vet
docker-build-alluxioruntime-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.alluxioruntime -t ${ALLUXIORUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-jindoruntime-controller: generate gen-openapi fmt vet
docker-build-jindoruntime-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.jindoruntime -t ${JINDORUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-goosefsruntime-controller: generate gen-openapi fmt vet
docker-build-goosefsruntime-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.goosefsruntime -t ${GOOSEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-juicefsruntime-controller: generate gen-openapi fmt vet juicefsruntime-controller-build
docker-build-juicefsruntime-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.juicefsruntime -t ${JUICEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-thinruntime-controller: generate gen-openapi fmt vet thinruntime-controller-build
docker-build-thinruntime-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.thinruntime -t ${THINRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-efcruntime-controller: generate gen-openapi fmt vet
docker-build-efcruntime-controller:
docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.efcruntime -t ${EFCRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-build-csi: generate fmt vet
docker-build-csi:
docker build --no-cache . -f docker/Dockerfile.csi -t ${CSI_IMG}:${GIT_VERSION}

docker-build-loader:
docker build --no-cache charts/fluid-dataloader/docker/loader -t ${LOADER_IMG}

docker-build-init-users:
docker build --no-cache charts/alluxio/docker/init-users -t ${INIT_USERS_IMG}:${VERSION}

Expand Down Expand Up @@ -277,28 +261,28 @@ docker-push-crd-upgrader: docker-build-crd-upgrader
docker push ${CRD_UPGRADER_IMG}:${GIT_VERSION}

# Buildx and push the docker image
docker-buildx-push-dataset-controller: generate gen-openapi fmt vet
docker-buildx-push-dataset-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.dataset -t ${DATASET_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-application-controller: generate fmt vet
docker-buildx-push-application-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.application -t ${APPLICATION_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-alluxioruntime-controller: generate gen-openapi fmt vet
docker-buildx-push-alluxioruntime-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.alluxioruntime -t ${ALLUXIORUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-jindoruntime-controller: generate gen-openapi fmt vet
docker-buildx-push-jindoruntime-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.jindoruntime -t ${JINDORUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-goosefsruntime-controller: generate gen-openapi fmt vet
docker-buildx-push-goosefsruntime-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.goosefsruntime -t ${GOOSEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-juicefsruntime-controller: generate gen-openapi fmt vet juicefsruntime-controller-build
docker-buildx-push-juicefsruntime-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.juicefsruntime -t ${JUICEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-thinruntime-controller: generate gen-openapi fmt vet thinruntime-controller-build
docker-buildx-push-thinruntime-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.thinruntime -t ${THINRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-efcruntime-controller: generate gen-openapi fmt vet
docker-buildx-push-efcruntime-controller:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.efcruntime -t ${EFCRUNTIME_CONTROLLER_IMG}:${GIT_VERSION}

docker-buildx-push-csi: generate fmt vet
Expand All @@ -313,15 +297,10 @@ docker-buildx-push-webhook:
docker-buildx-push-crd-upgrader:
docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.crds -t ${CRD_UPGRADER_IMG}:${GIT_VERSION}

docker-build-all: ${DOCKER_BUILD}
docker-push-all: ${DOCKER_PUSH}
docker-buildx-all-push: ${DOCKER_BUILDX_PUSH}
docker-build-all: pre-setup ${DOCKER_BUILD}
docker-push-all: pre-setup ${DOCKER_PUSH}
docker-buildx-all-push: pre-setup ${DOCKER_BUILDX_PUSH}

gen-sdk:
./hack/sdk/gen-sdk.sh

gen-openapi:
./hack/gen-openapi.sh

# find or download controller-gen
# download controller-gen if necessary
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.application
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN make application-controller-build && \
cp bin/fluidapp-controller /go/bin/fluidapp-controller

# Debug
RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2
#RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2

FROM alpine:3.17
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
Expand All @@ -29,7 +29,7 @@ RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-rel
ADD charts/ /charts

COPY --from=builder /go/bin/fluidapp-controller /usr/local/bin/fluidapp-controller
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
#COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
RUN chmod -R u+x /usr/local/bin/

CMD ["fluidapp-controller", "start"]
4 changes: 2 additions & 2 deletions docker/Dockerfile.csi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN make csi-build && \
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -gcflags="all=-N -l" -a -o /go/bin/fluid-csi cmd/csi/*.go

# Debug
RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2
#RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2

# Use distroless as minimal base image to package the csi binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand All @@ -25,7 +25,7 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \

WORKDIR /
COPY --from=builder /go/bin/fluid-csi /usr/local/bin/fluid-csi
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
#COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
ADD csi/shell/check_mount.sh /usr/local/bin/check_mount.sh
ADD csi/shell/entrypoint.sh /usr/local/bin/entrypoint.sh
ADD csi/shell/check_bind_mounts.sh /usr/local/bin/check_bind_mounts.sh
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.efcruntime
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN make efcruntime-controller-build && \
cp bin/efcruntime-controller /go/bin/efcruntime-controller

# Debug
RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2
#RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2

FROM alpine:3.17
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
Expand All @@ -29,7 +29,7 @@ RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-rel
ADD charts/ /charts

COPY --from=builder /go/bin/efcruntime-controller /usr/local/bin/efcruntime-controller
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
#COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
RUN chmod -R u+x /usr/local/bin/

CMD ["efcruntime-controller", "start"]
5 changes: 1 addition & 4 deletions docker/Dockerfile.jindoruntime
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ COPY . .
RUN make jindoruntime-controller-build && \
cp bin/jindoruntime-controller /go/bin/jindoruntime-controller

# Debug
RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2

FROM alpine:3.17
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
rm -rf /var/cache/apk/* && \
Expand All @@ -30,7 +27,7 @@ ADD charts/jindofs /charts/jindofs
ADD charts/jindofsx /charts/jindofsx

COPY --from=builder /go/bin/jindoruntime-controller /usr/local/bin/jindoruntime-controller
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
#COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
RUN chmod -R u+x /usr/local/bin/

CMD ["jindoruntime-controller", "start"]
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.juicefsruntime
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN make juicefsruntime-controller-build && \
cp bin/juicefsruntime-controller /go/bin/juicefsruntime-controller

# Debug
RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2
#RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2

FROM alpine:3.17
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
Expand All @@ -29,7 +29,7 @@ RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-rel
ADD charts/ /charts

COPY --from=builder /go/bin/juicefsruntime-controller /usr/local/bin/juicefsruntime-controller
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
#COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
RUN chmod -R u+x /usr/local/bin/

CMD ["juicefsruntime-controller", "start"]
4 changes: 2 additions & 2 deletions docker/Dockerfile.thinruntime
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN make thinruntime-controller-build && \
cp bin/thinruntime-controller /go/bin/thinruntime-controller

# Debug
RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2
#RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2

FROM alpine:3.17
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
Expand All @@ -29,7 +29,7 @@ RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-rel
ADD charts/ /charts

COPY --from=builder /go/bin/thinruntime-controller /usr/local/bin/thinruntime-controller
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
#COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
RUN chmod -R u+x /usr/local/bin/

CMD ["thinruntime-controller", "start"]
4 changes: 2 additions & 2 deletions docker/Dockerfile.webhook
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN make webhook-build && \
cp bin/fluid-webhook /go/bin/fluid-webhook

# Debug
RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2
#RUN go install github.com/go-delve/delve/cmd/dlv@v1.8.2

FROM alpine:3.17
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
Expand All @@ -21,7 +21,7 @@ ENV K8S_VERSION v1.14.8
RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl

COPY --from=builder /go/bin/fluid-webhook /usr/local/bin/fluid-webhook
COPY --from=builder /go/bin/dlv /usr/local/bin/dlv
#COPY --from=builder /go/bin/dlv /usr/local/bin/dlv

RUN mkdir -p /etc/k8s-webhook-server/certs && \
chmod -R u+w /etc/k8s-webhook-server/certs && \
Expand Down
2 changes: 2 additions & 0 deletions test/prow/testcases/common/fuse_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def getFuseRecoveredUids(namespace="default"):
items = api.list_namespaced_event(namespace=namespace).items
fuseRecoveryUids = set()
for item in items:
if item.message is None:
continue
if item.message.__contains__("Fuse recover"):
fuseRecoveryUids.add(item.involved_object.uid)
return fuseRecoveryUids
Expand Down

0 comments on commit 37e17c6

Please sign in to comment.