Skip to content

Commit dbd4bee

Browse files
committed
add dockerfile and makefile
Signed-off-by: KunWuLuan <[email protected]>
1 parent 0fa13e6 commit dbd4bee

File tree

250 files changed

+42307
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+42307
-99
lines changed

go.work

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go 1.25.1
2+
3+
use ./historyserver

go.work.sum

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
2+
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
3+
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
4+
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
5+
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
6+
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
7+
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
8+
github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ=
9+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
10+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
11+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
12+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
13+
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
14+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
15+
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
16+
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
17+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
18+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
19+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
20+
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
21+
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
22+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
23+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
24+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
25+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
26+
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
27+
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
28+
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
29+
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
30+
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b/go.mod h1:UZ2yyWbFTpuhSbFhv24aGNOdoRdJZgsIObGBUaYVsts=
31+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
32+
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
33+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
34+
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=

historyserver/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ARG TARGETOS
2+
ARG TARGETARCH
3+
4+
FROM --platform=$BUILDPLATFORM golang:1.25.1 as builder
5+
ENV GOPROXY=https://goproxy.cn,direct
6+
ARG BUILD_RAYSERVER_DASHBOARD
7+
8+
RUN if [ "$BUILD_RAYSERVER_DASHBOARD" = "yes" ] ; then \
9+
curl -o install.sh https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh && chmod +x install.sh && ./install.sh && /bin/bash -c "source $HOME/.nvm/nvm.sh && nvm install 14 && nvm use 14" ;\
10+
else \
11+
echo "$BUILD_RAYSERVER_DASHBOARD not yes, no need install nvm"; \
12+
fi
13+
14+
WORKDIR /historyserver
15+
COPY . .
16+
17+
RUN if [ "$BUILD_RAYSERVER_DASHBOARD" = "yes" ] ; then \
18+
/bin/bash -c "source $HOME/.nvm/nvm.sh && cd dashboard/ray/client && npm ci && npm run build" ;\
19+
else \
20+
mkdir -p dashboard/ray/client/build ;\
21+
echo "do not npm run build"; \
22+
fi
23+
24+
RUN make build GOOS=${TARGETOS} GOARCH=${TARGETARCH}
25+
26+
FROM ubuntu:22.04
27+
28+
RUN apt-get update && apt-get upgrade -y && rm -rf /var/cache/apt/ && apt-get install -y ca-certificates
29+
30+
COPY --from=builder /historyserver/output/bin/historyserver /usr/local/bin/historyserver
31+
COPY --from=builder /historyserver/output/bin/collector /usr/local/bin/collector
32+
COPY --from=builder /historyserver/dashboard/ray/client/build /dashboard/ray/build

historyserver/Makefile

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Image URL to use all building/pushing image targets
2+
GOLANGCILINT_VERSION ?= v1.59.0
3+
GOBIN := $(shell go env GOPATH)/bin
4+
GOBIN_GOLANGCILINT := $(GOBIN)/golangci-lint
5+
6+
DOCKERBUILDER_INSTANCE=historyserver
7+
OUT_DIR=output
8+
BIN_DIR=$(OUT_DIR)/bin
9+
BINARY_NAME=historyserver
10+
BINARY_NAME_COLLECTOR=collector
11+
12+
# Setting SHELL to bash allows bash commands to be executed by recipes.
13+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
14+
SHELL = /usr/bin/env bash -o pipefail
15+
BUILD_TIMESTAMP = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
16+
COMMIT_SHORT ?= $(shell git rev-parse --short HEAD)
17+
BRANCH ?= $(shell git branch --show-current)
18+
VERSION ?= $(shell git describe --tags --long|awk -F '-' '{print $$1"."$$2"-"$$3""}')
19+
20+
PACKAGE = gitlab.alibaba-inc.com/eml/historyserver
21+
22+
GO_LDFLAGS := -extldflags "-static"
23+
# GO_LDFLAGS += -w -s # Drop debugging symbols.
24+
GO_LDFLAGS += -X $(PACKAGE)/pkg.Version=$(VERSION) \
25+
-X $(PACKAGE)/pkg.CommitID=$(COMMIT_SHORT) \
26+
-X $(PACKAGE)/pkg.BuildDate=$(BUILD_TIMESTAMP) \
27+
-X $(PACKAGE)/pkg.Branch=$(BRANCH)
28+
GO_BUILD_FLAGS := -ldflags '$(GO_LDFLAGS)'
29+
30+
GOOS ?= darwin
31+
GOARCH ?= amd64
32+
33+
.PHONY: all
34+
35+
all: build
36+
37+
.PHONY: clean
38+
clean:
39+
rm -rf $(OUT_DIR)
40+
41+
.PHONY: build
42+
build: buildcollector buildhistoryserver
43+
44+
.PHONY: buildcollector
45+
#build: mod alllint test
46+
buildcollector: mod
47+
@echo ""
48+
@echo "go build ..."
49+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME_COLLECTOR) ./cmd/collector/main.go
50+
51+
.PHONY: buildhistoryserver
52+
#build: mod alllint test
53+
buildhistoryserver: mod
54+
@echo ""
55+
@echo "go build ..."
56+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME) ./cmd/historyserver/main.go
57+
58+
.PHONY: simplebuild
59+
simplebuild:
60+
@echo ""
61+
@echo "go build ..."
62+
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME)
63+
64+
.PHONY: mod
65+
mod:
66+
go mod tidy
67+
68+
.PHONY: localimage
69+
localimage: dockerbuilder_instance
70+
docker buildx build -t historyserver:laster --platform linux/amd64 . --load
71+
72+
.PHONY: dockerbuilder_instance
73+
dockerbuilder_instance:
74+
@docker buildx use $(DOCKERBUILDER_INSTANCE) || docker buildx create --name $(DOCKERBUILDER_INSTANCE)
75+
docker buildx use $(DOCKERBUILDER_INSTANCE)
76+
77+
# Run tests
78+
.PHONY: test
79+
test:
80+
go test -v ./pkg/... ./cmd/...
81+
82+
.PHONY: alllint
83+
alllint: todolist issuelint ## Run go lint against code.
84+
85+
.PHONY: issuelint
86+
issuelint: install-golint
87+
@echo ""
88+
@echo "-------------------- show issues info, if has issuse, return error --------------------"
89+
$(GOBIN_GOLANGCILINT) run -v --print-resources-usage -c .golangci.yaml
90+
91+
.PHONY: todolist
92+
todolist: install-golint ## Run go lint against code.
93+
@echo ""
94+
@echo "-------------------- only show TODO list info --------------------"
95+
$(GOBIN_GOLANGCILINT) run --print-resources-usage -c .golangci.info.yaml --enable-only godox
96+
@echo ""
97+
98+
install-golint: ## check golint if not exist install golint tools
99+
ifneq ("$(wildcard $(GOBIN_GOLANGCILINT))","")
100+
ifeq ($(shell $(GOBIN_GOLANGCILINT) version --format short), $(GOLANGCILINT_VERSION))
101+
@echo "golangci-lint version match"
102+
else
103+
@echo "golangci-lint version do not match"
104+
@{ \
105+
set -e ;\
106+
echo 'installing golangci-lint-$(GOLANGCILINT_VERSION)' ;\
107+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION) ;\
108+
echo 'Successfully installed' ;\
109+
}
110+
endif
111+
else
112+
@echo "golangci-lint not exist"
113+
@{ \
114+
set -e ;\
115+
echo 'installing golangci-lint-$(GOLANGCILINT_VERSION)' ;\
116+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION) ;\
117+
echo 'Successfully installed' ;\
118+
}
119+
endif
120+
121+
122+
123+
# Generate manifests e.g. CRD, RBAC etc.
124+
#manifests: controller-gen
125+
# $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
126+
127+
# Generate code
128+
#generate: controller-gen
129+
# $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
130+
131+
132+
# find or download controller-gen
133+
# download controller-gen if necessary
134+
#controller-gen:
135+
#ifeq (, $(shell which controller-gen))
136+
# go get sigs.k8s.io/controller-tools/cmd/[email protected]
137+
#CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
138+
#else
139+
#CONTROLLER_GEN=$(shell which controller-gen)
140+
#endif

historyserver/backend/collector/runtime/logcollector/collector.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/fsnotify/fsnotify"
1515
"github.com/hpcloud/tail"
1616
"github.com/ray-project/kuberay/historyserver/backend/collector/storage"
17+
"github.com/ray-project/kuberay/historyserver/utils"
1718
"github.com/sirupsen/logrus"
1819
)
1920

@@ -29,6 +30,7 @@ type RayLogHandler struct {
2930

3031
RayClusterName string
3132
RayClusterID string
33+
RayNodeName string
3234

3335
LogBatching int
3436
PushInterval time.Duration
@@ -80,16 +82,16 @@ func (r *RayLogHandler) PushLog(absoluteLogPathName string) error {
8082
// subdir events/aa/
8183
// filename a.txt
8284
subdir, filename := filepath.Split(relativePath)
83-
85+
logDir := utils.GetLogDir(r.RootDir, r.RayClusterName, r.RayClusterID, r.RayNodeName)
8486
if len(subdir) != 0 {
85-
dirName := path.Join(r.RootDir, subdir)
87+
dirName := path.Join(logDir, subdir)
8688
if err := r.Writter.CreateDirectory(dirName); err != nil {
8789
logrus.Errorf("Failed to create directory '%s': %v", dirName, err)
8890
return err
8991
}
9092
}
9193

92-
objectName := path.Join(r.RootDir, subdir, filename)
94+
objectName := path.Join(logDir, subdir, filename)
9395
logrus.Infof("Begin to create and append oss object %s by absoluteLogPathName %s, oss subdir [%s] filename [%s] relativePath[%s]",
9496
objectName, absoluteLogPathName, subdir, filename, relativePath)
9597

historyserver/backend/collector/runtime/logcollector/meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (r *RayLogHandler) PersistMetaLoop(stop chan struct{}) {
4141
logrus.Errorf("Build cluster meta information error %v", err)
4242
return
4343
}
44-
fileName := path.Clean(clistDir + "/" + r.RayClusterName + "_" + r.RayClusterID + "_" + path.Base(r.SessionDir) + "_" + fmt.Sprintf("%v", timestamp))
44+
fileName := path.Clean(clistDir + "/" + r.RayClusterName + "#" + r.RayClusterID + "#" + path.Base(r.SessionDir) + "#" + fmt.Sprintf("%v", timestamp))
4545
if err := r.Writter.WriteFile(fileName, bytes.NewReader(data)); err != nil {
4646
logrus.Errorf("CreateObjectIfNotExist %s error %v", fileName, err)
4747
return

historyserver/backend/collector/runtime/logcollector/util.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ type JobUrlInfo struct {
3333
}
3434

3535
var metaCommonUrlInfo = []*UrlInfo{
36-
&UrlInfo{
37-
Key: utils.OssMetaFile_ClusterSessionName,
38-
Path: "/tmp/ray/session_[1-9].*",
39-
Type: MetaTypeFileNames,
40-
},
4136
&UrlInfo{
4237
Key: utils.OssMetaFile_ClusterStatus,
4338
Url: "http://localhost:8265/api/cluster_status?format=1",

historyserver/backend/collector/runtime/runtime.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import (
44
"fmt"
55
"net/http"
66
"path"
7+
"strings"
78
"time"
89

910
"github.com/ray-project/kuberay/historyserver/backend/collector/runtime/logcollector"
1011
"github.com/ray-project/kuberay/historyserver/backend/collector/storage"
1112
"github.com/ray-project/kuberay/historyserver/backend/types"
13+
"github.com/ray-project/kuberay/historyserver/utils"
1214
)
1315

1416
func NewCollector(config *types.RayCollectorConfig, writter storage.StorageWritter) RayLogCollector {
1517
handler := logcollector.RayLogHandler{
16-
LogFiles: make(chan string),
18+
EnableMeta: config.Role == "Head",
19+
LogFiles: make(chan string),
1720

1821
RootDir: config.RootDir,
1922
SessionDir: config.SessionDir,
2023

21-
RayClusterName: config.RayNodeName,
24+
RayClusterName: config.RayClusterName,
2225
RayClusterID: config.RayClusterID,
26+
RayNodeName: config.RayNodeName,
2327

2428
LogBatching: config.LogBatching,
2529
PushInterval: config.PushInterval,
@@ -33,7 +37,9 @@ func NewCollector(config *types.RayCollectorConfig, writter storage.StorageWritt
3337
},
3438
Writter: writter,
3539
}
36-
rootMetaDir := fmt.Sprintf("%s/", path.Clean(path.Join(handler.RootDir, handler.RayClusterName+"_"+handler.RayClusterID, "_meta")))
40+
logDir := strings.TrimSpace(path.Join(config.SessionDir, utils.RAY_SESSIONDIR_LOGDIR_NAME))
41+
handler.LogDir = logDir
42+
rootMetaDir := fmt.Sprintf("%s/", path.Clean(path.Join(handler.RootDir, handler.RayClusterName+"_"+handler.RayClusterID, "meta")))
3743
handler.MetaDir = rootMetaDir
3844

3945
return &handler
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This module is the collector for aliyunoss.
2+
3+
Oss endpoint and oss bucket are read from /var/collector-config/data.
4+
5+
Content in /var/collector-config/data should be in json format, like
6+
`{"ossBucket": "", "ossEndpoint": ""}`
7+
8+
Set `--runtime-class-name=aliyunoss` to enable this module.
9+
10+
Currently this module can only be used in ack environment. Oidc must be
11+
enabled for the cluster, and permission for write the oss must be granted.

historyserver/backend/collector/storage/aliyunoss/ray/config.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,13 @@ type config struct {
1212
func (c *config) complete(rcc *types.RayCollectorConfig, jd map[string]interface{}) {
1313
c.RayCollectorConfig = *rcc
1414
c.OSSBucket = jd["ossBucket"].(string)
15-
c.OSSBucket = jd["ossEndpoint"].(string)
15+
c.OSSEndpoint = jd["ossEndpoint"].(string)
16+
}
17+
18+
func (c *config) completeHSConfig(rcc *types.RayHistoryServerConfig, jd map[string]interface{}) {
19+
c.RayCollectorConfig = types.RayCollectorConfig{
20+
RootDir: rcc.RootDir,
21+
}
22+
c.OSSBucket = jd["ossBucket"].(string)
23+
c.OSSEndpoint = jd["ossEndpoint"].(string)
1624
}

0 commit comments

Comments
 (0)