mirror of https://github.com/containers/podman.git
Merge pull request #17930 from ygalblum/quadlet-systemd-specifiers
Quadlet - treat paths starting with systemd specifiers as absolute
This commit is contained in:
commit
365131e0b7
|
|
@ -968,8 +968,22 @@ func addNetworks(quadletUnitFile *parser.UnitFile, groupName string, serviceUnit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Systemd Specifiers start with % with the exception of %%
|
||||||
|
func startsWithSystemdSpecifier(filePath string) bool {
|
||||||
|
if len(filePath) == 0 || filePath[0] != '%' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(filePath) > 1 && filePath[1] == '%' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func getAbsolutePath(quadletUnitFile *parser.UnitFile, filePath string) (string, error) {
|
func getAbsolutePath(quadletUnitFile *parser.UnitFile, filePath string) (string, error) {
|
||||||
if !filepath.IsAbs(filePath) {
|
// When the path starts with a Systemd specifier do not resolve what looks like a relative address
|
||||||
|
if !startsWithSystemdSpecifier(filePath) && !filepath.IsAbs(filePath) {
|
||||||
if len(quadletUnitFile.Path) > 0 {
|
if len(quadletUnitFile.Path) > 0 {
|
||||||
filePath = filepath.Join(filepath.Dir(quadletUnitFile.Path), filePath)
|
filePath = filepath.Join(filepath.Dir(quadletUnitFile.Path), filePath)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
## assert-podman-final-args localhost/imagename
|
## assert-podman-final-args localhost/imagename
|
||||||
## assert-podman-args --env-file /opt/env/abs-1 --env-file /opt/env/abs-2
|
## assert-podman-args --env-file /opt/env/abs-1
|
||||||
|
## assert-podman-args --env-file /opt/env/abs-2
|
||||||
## assert-podman-args-regex --env-file /.*/podman_test.*/quadlet/rel-1
|
## assert-podman-args-regex --env-file /.*/podman_test.*/quadlet/rel-1
|
||||||
|
## assert-podman-args --env-file %h/env
|
||||||
|
|
||||||
[Container]
|
[Container]
|
||||||
Image=localhost/imagename
|
Image=localhost/imagename
|
||||||
EnvironmentFile=/opt/env/abs-1
|
EnvironmentFile=/opt/env/abs-1
|
||||||
EnvironmentFile=/opt/env/abs-2
|
EnvironmentFile=/opt/env/abs-2
|
||||||
EnvironmentFile=rel-1
|
EnvironmentFile=rel-1
|
||||||
|
EnvironmentFile=%h/env
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
## assert-podman-args -v /host/dir2:/container/volume2:Z
|
## assert-podman-args -v /host/dir2:/container/volume2:Z
|
||||||
## assert-podman-args-regex -v .*/podman_test.*/quadlet/host/dir3:/container/volume3
|
## assert-podman-args-regex -v .*/podman_test.*/quadlet/host/dir3:/container/volume3
|
||||||
## assert-podman-args -v named:/container/named
|
## assert-podman-args -v named:/container/named
|
||||||
## assert-podman-args -v systemd-quadlet:/container/quadlet localhost/imagename
|
## assert-podman-args -v systemd-quadlet:/container/quadlet
|
||||||
|
## assert-podman-args -v %h/container:/container/volume4
|
||||||
|
|
||||||
[Container]
|
[Container]
|
||||||
Image=localhost/imagename
|
Image=localhost/imagename
|
||||||
|
|
@ -12,3 +13,4 @@ Volume=./host/dir3:/container/volume3
|
||||||
Volume=/container/empty
|
Volume=/container/empty
|
||||||
Volume=named:/container/named
|
Volume=named:/container/named
|
||||||
Volume=quadlet.volume:/container/quadlet
|
Volume=quadlet.volume:/container/quadlet
|
||||||
|
Volume=%h/container:/container/volume4
|
||||||
|
|
|
||||||
|
|
@ -558,4 +558,28 @@ EOF
|
||||||
remove_secret $SECRET_NAME
|
remove_secret $SECRET_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "quadlet - volume path using specifier" {
|
||||||
|
local tmp_path=$(mktemp -d --tmpdir=$PODMAN_TMPDIR quadlet.volume.XXXXXX)
|
||||||
|
local tmp_dir=${tmp_path#/tmp/}
|
||||||
|
local file_name="f$(random_string 10).txt"
|
||||||
|
local file_content="data_$(random_string 15)"
|
||||||
|
echo $file_content > $tmp_path/$file_name
|
||||||
|
|
||||||
|
local quadlet_file=$PODMAN_TMPDIR/basic_$(random_string).container
|
||||||
|
cat > $quadlet_file <<EOF
|
||||||
|
[Container]
|
||||||
|
Image=$IMAGE
|
||||||
|
Volume=%T/$tmp_dir:/test_content:Z
|
||||||
|
Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; top"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
run_quadlet "$quadlet_file"
|
||||||
|
service_setup $QUADLET_SERVICE_NAME
|
||||||
|
|
||||||
|
run_podman exec $QUADLET_CONTAINER_NAME /bin/sh -c "cat /test_content/$file_name"
|
||||||
|
is "$output" $file_content
|
||||||
|
|
||||||
|
rm -rf $tmp_path
|
||||||
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue