Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ env:
BUILDKIT_IMAGE: moby/buildkit@sha256:28a898719c18a33f4e8000685287fa36fd0dd9560c6440227d3a732d79bb41d8
GOLANGCI_LINT_VERSION: v2.13.1
GORELEASER_VERSION: v2.18.0
GOPRIVATE: github.com/dynamia-ai/*

jobs:
go:
Expand All @@ -39,11 +38,6 @@ jobs:
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
steps:
- name: Require private module token
env:
HAMI_ENTERPRISE_REPO_TOKEN: ${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}
run: test -n "$HAMI_ENTERPRISE_REPO_TOKEN"

- name: Checkout source
uses: actions/checkout@v7
with:
Expand Down Expand Up @@ -74,10 +68,6 @@ jobs:
install-only: true

- name: Run local CI contract
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}@github.com/.insteadOf
GIT_CONFIG_VALUE_0: https://github.com/
run: make ci

image:
Expand All @@ -102,11 +92,6 @@ jobs:
IMAGE_SOURCE: ${{ github.server_url }}/${{ github.repository }}
IMAGE_REVISION: ${{ github.sha }}
steps:
- name: Require private module token
env:
HAMI_ENTERPRISE_REPO_TOKEN: ${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}
run: test -n "$HAMI_ENTERPRISE_REPO_TOKEN"

- name: Checkout source
uses: actions/checkout@v7
with:
Expand All @@ -127,8 +112,6 @@ jobs:
driver-opts: image=${{ env.BUILDKIT_IMAGE }}

- name: Build and load without publishing
env:
HAMI_ENTERPRISE_REPO_TOKEN: ${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}
run: make build-image

- name: Inspect image
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ env:
BUILDX_VERSION: v0.36.1
BUILDKIT_IMAGE: moby/buildkit@sha256:28a898719c18a33f4e8000685287fa36fd0dd9560c6440227d3a732d79bb41d8
DOCKER_BUILD_RECORD_UPLOAD: "false"
GOPRIVATE: github.com/dynamia-ai/*
GOLANGCI_LINT_VERSION: v2.13.1
GORELEASER_VERSION: v2.18.0
OSSUTIL_VERSION: 2.3.0
Expand Down Expand Up @@ -54,11 +53,6 @@ jobs:
git merge-base --is-ancestor "$GITHUB_SHA" refs/remotes/origin/main
echo "source-date-epoch=$(git show -s --format=%ct "$GITHUB_SHA")" >> "$GITHUB_OUTPUT"

- name: Validate private module credential
env:
HAMI_ENTERPRISE_REPO_TOKEN: ${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}
run: test -n "$HAMI_ENTERPRISE_REPO_TOKEN"

- name: Set up Go
uses: actions/setup-go@v7
with:
Expand All @@ -73,10 +67,6 @@ jobs:
install-only: true

- name: Run release checks
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}@github.com/.insteadOf
GIT_CONFIG_VALUE_0: https://github.com/
run: make ci

- name: Build release artifacts with GoReleaser
Expand All @@ -85,10 +75,6 @@ jobs:
distribution: goreleaser
version: ${{ env.GORELEASER_VERSION }}
args: release --clean
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}@github.com/.insteadOf
GIT_CONFIG_VALUE_0: https://github.com/

- name: Verify release archive contents
run: bash hack/verify-release-archives.sh dist "$GITHUB_REF_NAME"
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/rolling-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ env:
BUILDX_VERSION: v0.36.1
BUILDKIT_IMAGE: moby/buildkit@sha256:28a898719c18a33f4e8000685287fa36fd0dd9560c6440227d3a732d79bb41d8
DOCKER_BUILD_RECORD_UPLOAD: "false"
GOPRIVATE: github.com/dynamia-ai/*
GOLANGCI_LINT_VERSION: v2.13.1
GORELEASER_VERSION: v2.18.0
OSSUTIL_VERSION: 2.3.0
Expand Down Expand Up @@ -103,11 +102,6 @@ jobs:
echo "- Revision: \`$revision\`"
} >> "$GITHUB_STEP_SUMMARY"

- name: Validate private module credential
env:
HAMI_ENTERPRISE_REPO_TOKEN: ${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}
run: test -n "$HAMI_ENTERPRISE_REPO_TOKEN"

- name: Set up Go
uses: actions/setup-go@v7
with:
Expand All @@ -122,10 +116,6 @@ jobs:
install-only: true

- name: Run release checks
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}@github.com/.insteadOf
GIT_CONFIG_VALUE_0: https://github.com/
run: make ci

- name: Build snapshot artifacts with GoReleaser
Expand All @@ -136,9 +126,6 @@ jobs:
args: release --snapshot --clean
env:
RELEASE_VERSION: ${{ steps.release.outputs.version }}
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: url.https://x-access-token:${{ secrets.HAMI_ENTERPRISE_REPO_TOKEN }}@github.com/.insteadOf
GIT_CONFIG_VALUE_0: https://github.com/

- name: Verify release archive contents
env:
Expand Down
21 changes: 4 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,18 @@ ARG VERSION=devel
ARG REVISION=unknown
ARG BUILD_DATE=unknown

ENV GOPRIVATE=github.com/dynamia-ai/*

WORKDIR /src

RUN apk add --no-cache ca-certificates git

COPY go.mod go.sum ./
RUN --mount=type=secret,id=github_token,required=true \
set -eu; \
token="$(cat /run/secrets/github_token)"; \
git config --global url."https://x-access-token:${token}@github.com/".insteadOf "https://github.com/"; \
GOWORK=off go mod download; \
rm -f "${HOME}/.gitconfig"
RUN GOWORK=off go mod download

COPY *.go ./
COPY internal/ ./internal/
COPY skills/ ./skills/
RUN --mount=type=secret,id=github_token,required=true \
set -eu; \
token="$(cat /run/secrets/github_token)"; \
git config --global url."https://x-access-token:${token}@github.com/".insteadOf "https://github.com/"; \
CGO_ENABLED=0 GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" GOWORK=off \
RUN CGO_ENABLED=0 GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" GOWORK=off \
go build -trimpath \
-ldflags "-s -w -X main.cliVersion=${VERSION} -X main.cliRevision=${REVISION} -X main.cliBuildDate=${BUILD_DATE}" \
-o /out/hami-cli .; \
rm -f "${HOME}/.gitconfig"
-o /out/hami-cli .

FROM gcr.io/distroless/static-debian12:nonroot

Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ verify: test vet
git diff --check

define build_image
test -n "$${HAMI_ENTERPRISE_REPO_TOKEN}"
$(DOCKER) buildx build \
--file "$(DOCKERFILE)" \
--platform "$(1)" \
Expand All @@ -64,7 +63,6 @@ define build_image
--build-arg "VERSION=$(VERSION)" \
--build-arg "REVISION=$(IMAGE_REVISION)" \
--build-arg "BUILD_DATE=$(BUILD_DATE)" \
--secret id=github_token,env=HAMI_ENTERPRISE_REPO_TOKEN \
--load \
"$(IMAGE_CONTEXT)"
endef
Expand Down
6 changes: 4 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

厂商运行时插件仍处于设计阶段。

[`internal/resourcepool/v1alpha1`](../internal/resourcepool/v1alpha1) 定义 CLI 使用的 Kubernetes 对象。修改对象定义时,需保持 API 组和版本、JSON 字段以及设备命名和标签规则与已部署的资源池 CRD 一致。

## 目标命令模型

厂商运行时能力计划收敛到统一入口:
Expand Down Expand Up @@ -71,8 +73,8 @@ cmd/root

- 建立独立 Go 模块并原样迁入资源池命令和测试。
- 在新仓库验证独立构建、安装和发布。
- 从 `hami-enterprise` 删除旧 CLI 源码,保留独立发布的资源池 API。
- 从 `hami-enterprise` 删除旧 CLI 源码,由 `hami-cli` 维护资源池客户端类型。
- 根据真实 NVIDIA Docker PoC 固定共享运行合同和 NVIDIA 插件。
- 在独立验证 Ascend 注入合同后接入 Ascend 插件。

迁移完成前,不应在两个仓库同时修改 CLI 行为。进入删除阶段后,`hami-enterprise` 只维护资源池服务端和公开 API,CLI 行为由本仓库维护。
迁移完成前,不应在两个仓库同时修改 CLI 行为。进入删除阶段后,`hami-enterprise` 维护资源池服务端和 CRD,`hami-cli` 维护客户端类型和命令行为。
5 changes: 1 addition & 4 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ GHCR 验证会检查清单 digest,以及 `linux/amd64`、`linux/arm64` 镜像

仓库需要以下 Actions secrets:

- `HAMI_ENTERPRISE_REPO_TOKEN`:对 `github.com/dynamia-ai/hami-enterprise` 具有只读 `Contents` 权限,用于解析私有 Go 模块。
- `ALIYUN_OSS_ACCESS_KEY_ID`、`ALIYUN_OSS_ACCESS_KEY_SECRET`:OSS 访问凭据。
- `ALIYUN_OSS_BUCKET`、`ALIYUN_OSS_ENDPOINT`、`ALIYUN_OSS_REGION`:OSS Bucket、API 端点和区域。
- `S3_ACCESS_KEY_ID`、`S3_SECRET_ACCESS_KEY`:S3 兼容存储访问凭据。
Expand All @@ -108,9 +107,7 @@ OSS 发布身份需要读写对象和设置对象 ACL,S3 发布身份需要读

## 凭据边界

Pull Request 和 `main` 的 CI 都需要读取私有资源池 API 模块。`hami-cli` 仓库的 write 权限不得授予无权读取 `hami-enterprise` 的用户,否则同仓库 PR 代码执行边界会扩大私有模块访问范围。

调整任一仓库成员权限时,需要重新核对这一条件。如果两个仓库的写入和读取边界不再一致,应先停用 Pull Request 中使用私有模块 token 的 job,再改用具备审批保护的凭据边界。
Pull Request 和 `main` 的 CI 使用仓库源码和公开 Go 模块构建。云存储访问凭据仅用于发布任务。

GHCR package 的写权限只能授予本仓库发布 workflow。其他主体拥有写权限时,可以在 workflow 完成后将已验证的稳定标签指向其他镜像。稳定交付必须保留并使用 `image@sha256:...` 引用,不能只依赖标签。

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/dynamia-ai/hami-cli
go 1.27.0

require (
github.com/dynamia-ai/hami-enterprise/pkg/resourcepool/api v0.0.0-20260916034425-492db1bedb3f
github.com/lathe-cli/kitup/go v0.1.4
github.com/lathe-cli/kitup/go-cobra v0.1.4
github.com/spf13/cobra v1.10.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dynamia-ai/hami-enterprise/pkg/resourcepool/api v0.0.0-20260916034425-492db1bedb3f h1:K219Pu9Senfmsw7XUsAkZaghMFt8ONulxYTnb6H+6EM=
github.com/dynamia-ai/hami-enterprise/pkg/resourcepool/api v0.0.0-20260916034425-492db1bedb3f/go.mod h1:ZM1AWRXzsPuvqt717dSuc4hbNwW0F4Y8tipjY5tgNeE=
github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bFY/oTyCes=
github.com/emicklei/go-restful/v3 v3.13.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU=
Expand Down
34 changes: 34 additions & 0 deletions internal/resourcepool/v1alpha1/conventions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package v1alpha1

import (
"crypto/sha256"
"encoding/hex"
"maps"
"strings"
)

const (
PoolLabel = "resource.hami.io/pool"
DeviceTypeLabel = "resource.hami.io/device-type"
NVIDIADeviceType = "NVIDIA"
)

// DeviceObjectName uses the RPM naming convention to look up existing devices.
func DeviceObjectName(identity DeviceIdentity) string {
key := identity.NodeName + "\x00" + identity.DeviceType + "\x00" + identity.DeviceID
digest := sha256.Sum256([]byte(key))
return "gpu-" + hex.EncodeToString(digest[:16])
}

// PoolLabels keeps user labels and derives the indexes from the device spec.
func PoolLabels(device *GPUDevice) map[string]string {
labels := make(map[string]string, len(device.Labels)+2)
maps.Copy(labels, device.Labels)
labels[DeviceTypeLabel] = strings.ToLower(device.Spec.Identity.DeviceType)
if ref := device.Spec.PoolRef; ref != nil {
labels[PoolLabel] = ref.Name
} else {
delete(labels, PoolLabel)
}
return labels
}
Loading