-
Notifications
You must be signed in to change notification settings - Fork 392
Simplify standalone installer #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a647619
[no-relnote] Merge verifyFlags and validateFlags
elezar 76edd1d
[no-relnote] Remove unused TryDelete function
elezar 9753096
[no-relnote] Add app struct for nvidia-toolkit
elezar 69375d7
[no-relnote] Use logger in toolkit installation
elezar 5cbf3f8
[no-relnote] Move fileinstaller to separate file
elezar d953bbb
Move nvidia-toolkit to nvidia-ctk-installer
elezar 9429ce0
[no-relnote] Rename run.go to main.go
elezar 6bd292e
[no-relnote] Move tools/container to cmd/nvidia-ctk-installer
elezar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
95 changes: 95 additions & 0 deletions
95
cmd/nvidia-ctk-installer/container/toolkit/file-installer.go
This file contains hidden or 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,95 @@ | ||
/** | ||
# Copyright 2024 NVIDIA CORPORATION | ||
# | ||
# 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 toolkit | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | ||
) | ||
|
||
type fileInstaller struct { | ||
logger logger.Interface | ||
// sourceRoot specifies the root that is searched for the components to install. | ||
sourceRoot string | ||
} | ||
|
||
// installFileToFolder copies a source file to a destination folder. | ||
// The path of the input file is ignored. | ||
// e.g. installFileToFolder("/some/path/file.txt", "/output/path") | ||
// will result in a file "/output/path/file.txt" being generated | ||
func (t *fileInstaller) installFileToFolder(destFolder string, src string) (string, error) { | ||
name := filepath.Base(src) | ||
return t.installFileToFolderWithName(destFolder, name, src) | ||
} | ||
|
||
// cp src destFolder/name | ||
func (t *fileInstaller) installFileToFolderWithName(destFolder string, name, src string) (string, error) { | ||
dest := filepath.Join(destFolder, name) | ||
err := t.installFile(dest, src) | ||
if err != nil { | ||
return "", fmt.Errorf("error copying '%v' to '%v': %v", src, dest, err) | ||
} | ||
return dest, nil | ||
} | ||
|
||
// installFile copies a file from src to dest and maintains | ||
// file modes | ||
func (t *fileInstaller) installFile(dest string, src string) error { | ||
src = filepath.Join(t.sourceRoot, src) | ||
t.logger.Infof("Installing '%v' to '%v'", src, dest) | ||
|
||
source, err := os.Open(src) | ||
if err != nil { | ||
return fmt.Errorf("error opening source: %v", err) | ||
} | ||
defer source.Close() | ||
|
||
destination, err := os.Create(dest) | ||
if err != nil { | ||
return fmt.Errorf("error creating destination: %v", err) | ||
} | ||
defer destination.Close() | ||
|
||
_, err = io.Copy(destination, source) | ||
if err != nil { | ||
return fmt.Errorf("error copying file: %v", err) | ||
} | ||
|
||
err = applyModeFromSource(dest, src) | ||
if err != nil { | ||
return fmt.Errorf("error setting destination file mode: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
// applyModeFromSource sets the file mode for a destination file | ||
// to match that of a specified source file | ||
func applyModeFromSource(dest string, src string) error { | ||
sourceInfo, err := os.Stat(src) | ||
if err != nil { | ||
return fmt.Errorf("error getting file info for '%v': %v", src, err) | ||
} | ||
err = os.Chmod(dest, sourceInfo.Mode()) | ||
if err != nil { | ||
return fmt.Errorf("error setting mode for '%v': %v", dest, err) | ||
} | ||
return nil | ||
} |
This file contains hidden or 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,40 @@ | ||
/** | ||
# Copyright 2024 NVIDIA CORPORATION | ||
# | ||
# 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 toolkit | ||
|
||
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" | ||
|
||
// An Option provides a mechanism to configure an Installer. | ||
type Option func(*Installer) | ||
|
||
func WithLogger(logger logger.Interface) Option { | ||
return func(i *Installer) { | ||
i.logger = logger | ||
} | ||
} | ||
|
||
func WithToolkitRoot(toolkitRoot string) Option { | ||
return func(i *Installer) { | ||
i.toolkitRoot = toolkitRoot | ||
} | ||
} | ||
|
||
func WithSourceRoot(sourceRoot string) Option { | ||
return func(i *Installer) { | ||
i.sourceRoot = sourceRoot | ||
} | ||
} |
File renamed without changes.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.