2021-09-06 11:26:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2022-03-15 15:27:34 +00:00
|
|
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
2021-09-06 11:26:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var logger = NewLogger()
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := run(os.Args)
|
|
|
|
if err != nil {
|
2022-03-30 11:18:57 +00:00
|
|
|
logger.Errorf("%v", err)
|
2021-09-06 11:26:48 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// run is an entry point that allows for idiomatic handling of errors
|
|
|
|
// when calling from the main function.
|
2022-02-22 13:17:10 +00:00
|
|
|
func run(argv []string) (rerr error) {
|
2022-03-29 10:01:12 +00:00
|
|
|
cfg, err := config.GetConfig()
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error loading config: %v", err)
|
|
|
|
}
|
|
|
|
|
2022-05-05 15:27:36 +00:00
|
|
|
logger, err = UpdateLogger(
|
|
|
|
cfg.NVIDIAContainerRuntimeConfig.DebugFilePath,
|
|
|
|
cfg.NVIDIAContainerRuntimeConfig.LogLevel,
|
|
|
|
argv,
|
|
|
|
)
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
2022-05-05 15:27:36 +00:00
|
|
|
return fmt.Errorf("failed to set up logger: %v", err)
|
2022-03-11 15:37:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 11:45:27 +00:00
|
|
|
logger.Debugf("Command line arguments: %v", argv)
|
2022-03-24 11:45:03 +00:00
|
|
|
runtime, err := newNVIDIAContainerRuntime(logger.Logger, cfg, argv)
|
2021-09-06 11:26:48 +00:00
|
|
|
if err != nil {
|
2022-03-15 12:29:14 +00:00
|
|
|
return fmt.Errorf("failed to create NVIDIA Container Runtime: %v", err)
|
2021-09-06 11:26:48 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 11:45:03 +00:00
|
|
|
return runtime.Exec(argv)
|
2021-09-06 11:26:48 +00:00
|
|
|
}
|