Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
songlinfeng
container-toolkit
Commits
3e3a4e74
Commit
3e3a4e74
authored
Oct 27, 2025
by
songlinfeng
Browse files
add dtk-docker
parent
1df1b155
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
2 deletions
+81
-2
cmd/dtk-docker/main.go
cmd/dtk-docker/main.go
+73
-0
packaging/rpm/SPECS/dtk-container-toolkit.spec
packaging/rpm/SPECS/dtk-container-toolkit.spec
+8
-2
No files found.
cmd/dtk-docker/main.go
0 → 100644
View file @
3e3a4e74
package
main
import
(
"fmt"
"os"
"os/exec"
"strings"
"syscall"
)
func
isWritable
(
path
string
)
bool
{
return
syscall
.
Access
(
path
,
syscall
.
O_RDWR
)
==
nil
}
func
fixVolumeArg
(
arg
string
)
string
{
parts
:=
strings
.
Split
(
arg
,
":"
)
if
len
(
parts
)
<
2
{
return
arg
}
hostPath
:=
parts
[
0
]
writable
:=
isWritable
(
hostPath
)
hasMode
:=
len
(
parts
)
==
3
if
!
writable
{
if
hasMode
{
parts
[
len
(
parts
)
-
1
]
=
"ro"
return
strings
.
Join
(
parts
,
":"
)
}
return
arg
+
":ro"
}
return
arg
}
func
HasRunSubcommand
(
args
[]
string
)
bool
{
isrun
:=
false
for
_
,
arg
:=
range
args
{
if
arg
==
"run"
{
isrun
=
true
return
isrun
}
}
return
isrun
}
func
main
()
{
args
:=
os
.
Args
[
1
:
]
newArgs
:=
[]
string
{}
if
!
HasRunSubcommand
(
args
)
{
newArgs
=
args
}
else
{
for
i
:=
0
;
i
<
len
(
args
);
i
++
{
if
args
[
i
]
==
"-v"
&&
i
+
1
<
len
(
args
)
{
fixed
:=
fixVolumeArg
(
args
[
i
+
1
])
newArgs
=
append
(
newArgs
,
"-v"
,
fixed
)
i
++
}
else
{
newArgs
=
append
(
newArgs
,
args
[
i
])
}
}
}
cmd
:=
exec
.
Command
(
"sdocker"
,
newArgs
...
)
cmd
.
Stdin
=
os
.
Stdin
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
if
err
:=
cmd
.
Run
();
err
!=
nil
{
os
.
Exit
(
1
)
}
}
packaging/rpm/SPECS/dtk-container-toolkit.spec
View file @
3e3a4e74
...
...
@@ -13,23 +13,27 @@ Source0: dtk-ctk
Source1: dtk-container-runtime
Source2: dtk-cdi-hook
Source3: LICENSE
Source4: dtk-docker
%description
Provides tools and utilities to enable HCU support in containers.
%prep
cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} .
cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3}
%{SOURCE4}
.
%install
mkdir -p %{buildroot}%{_bindir}
install -m 755 -t %{buildroot}%{_bindir} dtk-container-runtime
install -m 755 -t %{buildroot}%{_bindir} dtk-ctk
install -m 755 -t %{buildroot}%{_bindir} dtk-cdi-hook
install -m 755 -t %{buildroot}%{_bindir} dtk-docker
%posttrans
if [ ! -e %{_bindir}/nvidia-container-runtime-hook ]; then
# repairing lost file nvidia-container-runtime-hook
ln -sf %{_bindir}/dtk-container-runtime %{_bindir}/nvidia-container-runtime-hook
mv %{_bindir}/docker %{_bindir}/sdocker
mv %{_bindir}/dtk-docker %{_bindir}/docker
fi
# Generate the default config; If this file already exists no changes are made.
...
...
@@ -44,6 +48,7 @@ echo -e "\e[032m ================================== \e[0m"
%postun
if [ "$1" = 0 ]; then # package is uninstalled, not upgraded
if [ -L %{_bindir}/nvidia-container-runtime-hook ]; then rm -f %{_bindir}/nvidia-container-runtime-hook; fi
if [ -e %{_bindir}/sdocker ]; then mv %{_bindir}/sdocker %{_bindir}/docker; fi
fi
%files
...
...
@@ -51,6 +56,7 @@ fi
%{_bindir}/dtk-ctk
%{_bindir}/dtk-container-runtime
%{_bindir}/dtk-cdi-hook
%{_bindir}/dtk-docker
%changelog
* %{release_date} HCUOpt CORPORATION %{version}-%{release}
- initialize version
\ No newline at end of file
- initialize version
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment