-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add index creation job implementation
Signed-off-by: hlts2 <[email protected]>
- Loading branch information
Showing
11 changed files
with
820 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# | ||
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
name: "Build docker image: index-creation" | ||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- "*.*.*" | ||
- "v*.*.*" | ||
- "*.*.*-*" | ||
- "v*.*.*-*" | ||
paths: | ||
- ".github/actions/docker-build/actions.yaml" | ||
- ".github/workflows/dockers-index-creation.yml" | ||
- "go.mod" | ||
- "go.sum" | ||
- "internal/**" | ||
- "!internal/**/*_test.go" | ||
- "!internal/db/**" | ||
- "!internal/k8s/**" | ||
- "apis/grpc/**" | ||
- "pkg/index/job/creation/**" | ||
- "cmd/index/job/creation/**" | ||
- "dockers/index/job/creation/Dockerfile" | ||
- "versions/GO_VERSION" | ||
pull_request: | ||
paths: | ||
- ".github/actions/docker-build/actions.yaml" | ||
- ".github/workflows/_docker-image.yaml" | ||
- ".github/workflows/dockers-index-creation.yml" | ||
- "go.mod" | ||
- "go.sum" | ||
- "internal/**" | ||
- "!internal/**/*_test.go" | ||
- "!internal/db/**" | ||
- "!internal/k8s/**" | ||
- "apis/grpc/**" | ||
- "pkg/index/job/creation/**" | ||
- "cmd/index/job/creation/**" | ||
- "dockers/index/job/creation/Dockerfile" | ||
- "versions/GO_VERSION" | ||
pull_request_target: | ||
paths: | ||
- ".github/actions/docker-build/actions.yaml" | ||
- ".github/workflows/_docker-image.yaml" | ||
- ".github/workflows/dockers-index-creation.yml" | ||
- "go.mod" | ||
- "go.sum" | ||
- "internal/**" | ||
- "!internal/**/*_test.go" | ||
- "!internal/db/**" | ||
- "!internal/k8s/**" | ||
- "apis/grpc/**" | ||
- "pkg/index/job/creation/**" | ||
- "cmd/index/job/creation/**" | ||
- "dockers/index/job/creation/Dockerfile" | ||
- "versions/GO_VERSION" | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/_docker-image.yaml | ||
with: | ||
target: index-creation | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (C) 2019-2023 vdaas.org vald team <[email protected]> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/vdaas/vald/internal/errors" | ||
"github.com/vdaas/vald/internal/info" | ||
"github.com/vdaas/vald/internal/log" | ||
"github.com/vdaas/vald/internal/runner" | ||
"github.com/vdaas/vald/internal/safety" | ||
"github.com/vdaas/vald/pkg/index/job/creation/config" | ||
"github.com/vdaas/vald/pkg/index/job/creation/usecase" | ||
) | ||
|
||
const ( | ||
maxVersion = "v0.0.10" | ||
minVersion = "v0.0.0" | ||
name = "index creation job" | ||
) | ||
|
||
func main() { | ||
if err := safety.RecoverFunc(func() error { | ||
return runner.Do( | ||
context.Background(), | ||
runner.WithName(name), | ||
runner.WithVersion(info.Version, maxVersion, minVersion), | ||
runner.WithConfigLoader(func(path string) (interface{}, *config.GlobalConfig, error) { | ||
cfg, err := config.NewConfig(path) | ||
if err != nil { | ||
return nil, nil, errors.Wrap(err, "failed to load "+name+"'s configuration") | ||
} | ||
return cfg, &cfg.GlobalConfig, nil | ||
}), | ||
runner.WithDaemonInitializer(func(cfg interface{}) (runner.Runner, error) { | ||
c, ok := cfg.(*config.Data) | ||
if !ok { | ||
return nil, errors.ErrInvalidConfig | ||
} | ||
return usecase.New(c) | ||
}), | ||
) | ||
})(); err != nil { | ||
log.Fatal(err, info.Get()) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# | ||
# Copyright (C) 2019-2023 vdaas.org vald team <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
ARG GO_VERSION=latest | ||
ARG DISTROLESS_IMAGE=gcr.io/distroless/static | ||
ARG DISTROLESS_IMAGE_TAG=nonroot | ||
ARG MAINTAINER="vdaas.org vald team <[email protected]>" | ||
|
||
FROM golang:${GO_VERSION} AS golang | ||
|
||
FROM ubuntu:devel AS builder | ||
|
||
ENV GO111MODULE on | ||
ENV DEBIAN_FRONTEND noninteractive | ||
ENV INITRD No | ||
ENV LANG en_US.UTF-8 | ||
ENV GOROOT /opt/go | ||
ENV GOPATH /go | ||
ENV PATH ${PATH}:${GOROOT}/bin:${GOPATH}/bin | ||
ENV ORG vdaas | ||
ENV REPO vald | ||
ENV PKG index/job/creation | ||
ENV APP_NAME index-creation | ||
|
||
# skipcq: DOK-DL3008 | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
build-essential \ | ||
curl \ | ||
upx \ | ||
git \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY --from=golang /usr/local/go $GOROOT | ||
RUN mkdir -p "$GOPATH/src" | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/Makefile.d | ||
COPY Makefile.d . | ||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} | ||
COPY Makefile . | ||
COPY .git . | ||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
RUN make go/download | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal | ||
COPY internal . | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/apis/grpc | ||
COPY apis/grpc . | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/pkg/${PKG} | ||
COPY pkg/${PKG} . | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} | ||
COPY cmd/${PKG} . | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions | ||
COPY versions . | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO} | ||
RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \ | ||
&& mv "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}" | ||
|
||
WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG} | ||
RUN cp sample.yaml /tmp/config.yaml | ||
|
||
FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG} | ||
LABEL maintainer="${MAINTAINER}" | ||
|
||
ENV APP_NAME index-creation | ||
|
||
COPY --from=builder /usr/bin/${APP_NAME} /go/bin/${APP_NAME} | ||
COPY --from=builder /tmp/config.yaml /etc/server/config.yaml | ||
|
||
USER nonroot:nonroot | ||
|
||
ENTRYPOINT ["/go/bin/index-creation"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Package config providers configuration type and load configuration logic | ||
package config | ||
|
||
// IndexCreator represents the index creator configurations. | ||
type IndexCreator struct { | ||
// AgentPort represent agent port number | ||
AgentPort int `json:"agent_port" yaml:"agent_port"` | ||
|
||
// AgentName represent agents meta_name for service discovery | ||
AgentName string `json:"agent_name" yaml:"agent_name"` | ||
|
||
// AgentNamespace represent agent namespace location | ||
AgentNamespace string `json:"agent_namespace" yaml:"agent_namespace"` | ||
|
||
// AgentDNS represent agents dns A record for service discovery | ||
AgentDNS string `json:"agent_dns" yaml:"agent_dns"` | ||
|
||
// NodeName represents node name | ||
NodeName string `json:"node_name" yaml:"node_name"` | ||
|
||
// Concurrency represents indexing concurrency. | ||
Concurrency int `json:"concurrency" yaml:"concurrency"` | ||
|
||
// CreationPoolSize represents batch pool size for indexing. | ||
CreationPoolSize uint32 `yaml:"creation_pool_size" json:"creation_pool_size"` | ||
|
||
// TargetAddrs represents indexing target addresses. | ||
TargetAddrs []string `yaml:"target_addrs" json:"target_addrs"` | ||
|
||
// Discoverer represents agent discoverer service configuration. | ||
Discoverer *DiscovererClient `json:"discoverer" yaml:"discoverer"` | ||
} | ||
|
||
func (ic *IndexCreator) Bind() *IndexCreator { | ||
ic.AgentName = GetActualValue(ic.AgentName) | ||
ic.AgentNamespace = GetActualValue(ic.AgentNamespace) | ||
ic.AgentDNS = GetActualValue(ic.AgentDNS) | ||
ic.NodeName = GetActualValue(ic.NodeName) | ||
ic.TargetAddrs = GetActualValues(ic.TargetAddrs) | ||
|
||
if ic.Discoverer != nil { | ||
ic.Discoverer.Bind() | ||
} | ||
return ic | ||
} |
Oops, something went wrong.