mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
TOFIX: detect host type
Some checks failed
Some checks failed
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
bfea63246d
commit
4da1db4549
@ -38,6 +38,8 @@ type toolkitInstaller struct {
|
|||||||
ignoreErrors bool
|
ignoreErrors bool
|
||||||
sourceRoot string
|
sourceRoot string
|
||||||
|
|
||||||
|
hostRoot string
|
||||||
|
packageType string
|
||||||
artifactRoot *artifactRoot
|
artifactRoot *artifactRoot
|
||||||
|
|
||||||
ensureTargetDirectory Installer
|
ensureTargetDirectory Installer
|
||||||
@ -47,7 +49,10 @@ var _ Installer = (*toolkitInstaller)(nil)
|
|||||||
|
|
||||||
// New creates a toolkit installer with the specified options.
|
// New creates a toolkit installer with the specified options.
|
||||||
func New(opts ...Option) (Installer, error) {
|
func New(opts ...Option) (Installer, error) {
|
||||||
t := &toolkitInstaller{}
|
t := &toolkitInstaller{
|
||||||
|
hostRoot: "/",
|
||||||
|
packageType: "auto",
|
||||||
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(t)
|
opt(t)
|
||||||
}
|
}
|
||||||
@ -56,7 +61,11 @@ func New(opts ...Option) (Installer, error) {
|
|||||||
t.logger = logger.New()
|
t.logger = logger.New()
|
||||||
}
|
}
|
||||||
if t.sourceRoot == "" {
|
if t.sourceRoot == "" {
|
||||||
t.sourceRoot = "/"
|
sourceRoot, err := defaultSourceRoot(t.hostRoot, t.packageType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
t.sourceRoot = sourceRoot
|
||||||
}
|
}
|
||||||
if t.artifactRoot == nil {
|
if t.artifactRoot == nil {
|
||||||
artifactRoot, err := newArtifactRoot(t.logger, t.sourceRoot)
|
artifactRoot, err := newArtifactRoot(t.logger, t.sourceRoot)
|
||||||
|
@ -45,3 +45,15 @@ func WithSourceRoot(sourceRoot string) Option {
|
|||||||
ti.sourceRoot = sourceRoot
|
ti.sourceRoot = sourceRoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithPackageType(packageType string) Option {
|
||||||
|
return func(ti *toolkitInstaller) {
|
||||||
|
ti.packageType = packageType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithHostRoot(hostRoot string) Option {
|
||||||
|
return func(ti *toolkitInstaller) {
|
||||||
|
ti.hostRoot = hostRoot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
55
cmd/nvidia-ctk-installer/toolkit/installer/package-type.go
Normal file
55
cmd/nvidia-ctk-installer/toolkit/installer/package-type.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
# http://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 installer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resolvePackageType(hostRoot string, packageType string) (rPackageTypes string, rerr error) {
|
||||||
|
if packageType != "" && packageType != "auto" {
|
||||||
|
return packageType, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/rpm")); err != nil && !info.IsDir() {
|
||||||
|
return "rpm", nil
|
||||||
|
}
|
||||||
|
if info, err := os.Stat(filepath.Join(hostRoot, "/usr/bin/dpkg")); err != nil && !info.IsDir() {
|
||||||
|
return "deb", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "deb", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultSourceRoot(hostRoot string, packageType string) (string, error) {
|
||||||
|
resolvedPackageType, err := resolvePackageType(hostRoot, packageType)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
switch resolvedPackageType {
|
||||||
|
case "deb":
|
||||||
|
return "/artifacts/deb", nil
|
||||||
|
case "rpm":
|
||||||
|
return "/artifacts/rpm", nil
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("invalid package type: %v", resolvedPackageType)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user