mirror of
https://github.com/mudler/luet.git
synced 2025-09-05 17:20:29 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e5d6d21178 | ||
|
0379855592 | ||
|
958b8c32e1 | ||
|
b0b95d1721 | ||
|
f85891e362 |
@@ -40,7 +40,7 @@ var Verbose bool
|
|||||||
var LockedCommands = []string{"install", "uninstall", "upgrade"}
|
var LockedCommands = []string{"install", "uninstall", "upgrade"}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LuetCLIVersion = "0.14.1"
|
LuetCLIVersion = "0.14.2"
|
||||||
LuetEnvPrefix = "LUET"
|
LuetEnvPrefix = "LUET"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -25,7 +25,6 @@ import (
|
|||||||
|
|
||||||
bus "github.com/mudler/luet/pkg/bus"
|
bus "github.com/mudler/luet/pkg/bus"
|
||||||
|
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
|
||||||
capi "github.com/mudler/docker-companion/api"
|
capi "github.com/mudler/docker-companion/api"
|
||||||
|
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
@@ -56,24 +55,6 @@ func (*SimpleDocker) BuildImage(opts Options) error {
|
|||||||
|
|
||||||
Info(":whale: Building image " + name + " done")
|
Info(":whale: Building image " + name + " done")
|
||||||
|
|
||||||
if os.Getenv("DOCKER_SQUASH") == "true" {
|
|
||||||
Info(":whale: Squashing image " + name)
|
|
||||||
var client *docker.Client
|
|
||||||
|
|
||||||
Spinner(22)
|
|
||||||
defer SpinnerStop()
|
|
||||||
client, err = docker.NewClientFromEnv()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "could not connect to the Docker daemon")
|
|
||||||
}
|
|
||||||
err = capi.Squash(client, name, name)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "Failed squashing image")
|
|
||||||
}
|
|
||||||
|
|
||||||
Info(":whale: Squashing image " + name + " done")
|
|
||||||
}
|
|
||||||
|
|
||||||
bus.Manager.Publish(bus.EventImagePostBuild, opts)
|
bus.Manager.Publish(bus.EventImagePostBuild, opts)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@@ -27,7 +27,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
system "github.com/docker/docker/pkg/system"
|
|
||||||
zstd "github.com/klauspost/compress/zstd"
|
zstd "github.com/klauspost/compress/zstd"
|
||||||
gzip "github.com/klauspost/pgzip"
|
gzip "github.com/klauspost/pgzip"
|
||||||
|
|
||||||
@@ -584,47 +583,16 @@ type CopyJob struct {
|
|||||||
Artifact string
|
Artifact string
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyXattr(srcPath, dstPath, attr string) error {
|
|
||||||
data, err := system.Lgetxattr(srcPath, attr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if data != nil {
|
|
||||||
if err := system.Lsetxattr(dstPath, attr, data, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func doCopyXattrs(srcPath, dstPath string) error {
|
|
||||||
if err := copyXattr(srcPath, dstPath, "security.capability"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return copyXattr(srcPath, dstPath, "trusted.overlay.opaque")
|
|
||||||
}
|
|
||||||
|
|
||||||
func worker(i int, wg *sync.WaitGroup, s <-chan CopyJob) {
|
func worker(i int, wg *sync.WaitGroup, s <-chan CopyJob) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
for job := range s {
|
for job := range s {
|
||||||
//Info("#"+strconv.Itoa(i), "copying", job.Src, "to", job.Dst)
|
|
||||||
// if dir, err := helpers.IsDirectory(job.Src); err == nil && dir {
|
|
||||||
// err = helpers.CopyDir(job.Src, job.Dst)
|
|
||||||
// if err != nil {
|
|
||||||
// Warning("Error copying dir", job, err)
|
|
||||||
// }
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
_, err := os.Lstat(job.Dst)
|
_, err := os.Lstat(job.Dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Debug("Copying ", job.Src)
|
Debug("Copying ", job.Src)
|
||||||
if err := helpers.CopyFile(job.Src, job.Dst); err != nil {
|
if err := helpers.DeepCopyFile(job.Src, job.Dst); err != nil {
|
||||||
Warning("Error copying", job, err)
|
Warning("Error copying", job, err)
|
||||||
}
|
}
|
||||||
doCopyXattrs(job.Src, job.Dst)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/google/renameio"
|
"github.com/google/renameio"
|
||||||
copy "github.com/otiai10/copy"
|
copy "github.com/otiai10/copy"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -167,9 +168,27 @@ func Read(file string) (string, error) {
|
|||||||
return string(dat), nil
|
return string(dat), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EnsureDirPerm(src, dst string) {
|
||||||
|
if info, err := os.Lstat(filepath.Dir(src)); err == nil {
|
||||||
|
if _, err := os.Lstat(filepath.Dir(dst)); os.IsNotExist(err) {
|
||||||
|
err := os.MkdirAll(filepath.Dir(dst), info.Mode().Perm())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("warning: failed creating", filepath.Dir(dst), err.Error())
|
||||||
|
}
|
||||||
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||||
|
if err := os.Lchown(filepath.Dir(dst), int(stat.Uid), int(stat.Gid)); err != nil {
|
||||||
|
fmt.Println("warning: failed chowning", filepath.Dir(dst), err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EnsureDir(dst)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func EnsureDir(fileName string) error {
|
func EnsureDir(fileName string) error {
|
||||||
dirName := filepath.Dir(fileName)
|
dirName := filepath.Dir(fileName)
|
||||||
if _, serr := os.Stat(dirName); serr != nil {
|
if _, serr := os.Stat(dirName); os.IsNotExist(serr) {
|
||||||
merr := os.MkdirAll(dirName, os.ModePerm) // FIXME: It should preserve permissions from src to dst instead
|
merr := os.MkdirAll(dirName, os.ModePerm) // FIXME: It should preserve permissions from src to dst instead
|
||||||
if merr != nil {
|
if merr != nil {
|
||||||
return merr
|
return merr
|
||||||
@@ -178,12 +197,39 @@ func EnsureDir(fileName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyFile copies the contents of the file named src to the file named
|
func CopyFile(src, dst string) (err error) {
|
||||||
|
return copy.Copy(src, dst, copy.Options{
|
||||||
|
Sync: true,
|
||||||
|
OnSymlink: func(string) copy.SymlinkAction { return copy.Shallow }})
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyXattr(srcPath, dstPath, attr string) error {
|
||||||
|
data, err := system.Lgetxattr(srcPath, attr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if data != nil {
|
||||||
|
if err := system.Lsetxattr(dstPath, attr, data, 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func doCopyXattrs(srcPath, dstPath string) error {
|
||||||
|
if err := copyXattr(srcPath, dstPath, "security.capability"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return copyXattr(srcPath, dstPath, "trusted.overlay.opaque")
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopyFile copies the contents of the file named src to the file named
|
||||||
// by dst. The file will be created if it does not already exist. If the
|
// by dst. The file will be created if it does not already exist. If the
|
||||||
// destination file exists, all it's contents will be replaced by the contents
|
// destination file exists, all it's contents will be replaced by the contents
|
||||||
// of the source file. The file mode will be copied from the source and
|
// of the source file. The file mode will be copied from the source and
|
||||||
// the copied data is synced/flushed to stable storage.
|
// the copied data is synced/flushed to stable storage.
|
||||||
func CopyFile(src, dst string) (err error) {
|
func DeepCopyFile(src, dst string) (err error) {
|
||||||
// Workaround for https://github.com/otiai10/copy/issues/47
|
// Workaround for https://github.com/otiai10/copy/issues/47
|
||||||
fi, err := os.Lstat(src)
|
fi, err := os.Lstat(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -193,7 +239,7 @@ func CopyFile(src, dst string) (err error) {
|
|||||||
fm := fi.Mode()
|
fm := fi.Mode()
|
||||||
switch {
|
switch {
|
||||||
case fm&os.ModeNamedPipe != 0:
|
case fm&os.ModeNamedPipe != 0:
|
||||||
EnsureDir(dst)
|
EnsureDirPerm(src, dst)
|
||||||
if err := syscall.Mkfifo(dst, uint32(fi.Mode())); err != nil {
|
if err := syscall.Mkfifo(dst, uint32(fi.Mode())); err != nil {
|
||||||
return errors.Wrap(err, "failed creating pipe")
|
return errors.Wrap(err, "failed creating pipe")
|
||||||
}
|
}
|
||||||
@@ -205,6 +251,9 @@ func CopyFile(src, dst string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//filepath.Dir(src)
|
||||||
|
EnsureDirPerm(src, dst)
|
||||||
|
|
||||||
err = copy.Copy(src, dst, copy.Options{
|
err = copy.Copy(src, dst, copy.Options{
|
||||||
Sync: true,
|
Sync: true,
|
||||||
OnSymlink: func(string) copy.SymlinkAction { return copy.Shallow }})
|
OnSymlink: func(string) copy.SymlinkAction { return copy.Shallow }})
|
||||||
@@ -216,7 +265,8 @@ func CopyFile(src, dst string) (err error) {
|
|||||||
fmt.Println("warning: failed chowning", dst, err.Error())
|
fmt.Println("warning: failed chowning", dst, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
|
return doCopyXattrs(src, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsDirectory(path string) (bool, error) {
|
func IsDirectory(path string) (bool, error) {
|
||||||
|
11
tests/fixtures/perms/pkgA/0.1/build.yaml
vendored
Normal file
11
tests/fixtures/perms/pkgA/0.1/build.yaml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
image: "alpine"
|
||||||
|
unpack: true
|
||||||
|
includes:
|
||||||
|
- /foo
|
||||||
|
- /foo/bar
|
||||||
|
- /foo/bar/.keep
|
||||||
|
steps:
|
||||||
|
- mkdir -p /foo/bar
|
||||||
|
- touch /foo/bar/.keep
|
||||||
|
- chown 100:100 /foo/bar
|
||||||
|
- chown 101:101 /foo/bar/.keep
|
3
tests/fixtures/perms/pkgA/0.1/definition.yaml
vendored
Normal file
3
tests/fixtures/perms/pkgA/0.1/definition.yaml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
category: "test"
|
||||||
|
name: "perms"
|
||||||
|
version: "0.1"
|
7
tests/fixtures/perms/pkgB/0.1/build.yaml
vendored
Normal file
7
tests/fixtures/perms/pkgB/0.1/build.yaml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
image: "alpine"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- mkdir -p /foo/baz
|
||||||
|
- touch /foo/baz/.keep
|
||||||
|
- chown 100:100 /foo/baz
|
||||||
|
- chown 101:101 /foo/baz/.keep
|
3
tests/fixtures/perms/pkgB/0.1/definition.yaml
vendored
Normal file
3
tests/fixtures/perms/pkgB/0.1/definition.yaml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
category: "test"
|
||||||
|
name: "perms2"
|
||||||
|
version: "0.1"
|
79
tests/integration/16_perms.sh
Executable file
79
tests/integration/16_perms.sh
Executable file
@@ -0,0 +1,79 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export LUET_NOLOCK=true
|
||||||
|
|
||||||
|
oneTimeSetUp() {
|
||||||
|
export tmpdir="$(mktemp -d)"
|
||||||
|
}
|
||||||
|
|
||||||
|
oneTimeTearDown() {
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
}
|
||||||
|
|
||||||
|
testBuild() {
|
||||||
|
[ "$LUET_BACKEND" == "img" ] && startSkipping
|
||||||
|
mkdir $tmpdir/testbuild
|
||||||
|
luet build -d --tree "$ROOT_DIR/tests/fixtures/perms" --same-owner=true --destination $tmpdir/testbuild --compression gzip --full
|
||||||
|
buildst=$?
|
||||||
|
assertTrue 'create package perms 0.1' "[ -e '$tmpdir/testbuild/perms-test-0.1.package.tar.gz' ]"
|
||||||
|
assertEquals 'builds successfully' "$buildst" "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
testRepo() {
|
||||||
|
[ "$LUET_BACKEND" == "img" ] && startSkipping
|
||||||
|
assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
luet create-repo --tree "$ROOT_DIR/tests/fixtures/perms" \
|
||||||
|
--output $tmpdir/testbuild \
|
||||||
|
--packages $tmpdir/testbuild \
|
||||||
|
--name "test" \
|
||||||
|
--descr "Test Repo" \
|
||||||
|
--urls $tmpdir/testrootfs \
|
||||||
|
--type http
|
||||||
|
|
||||||
|
createst=$?
|
||||||
|
assertEquals 'create repo successfully' "$createst" "0"
|
||||||
|
assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
testConfig() {
|
||||||
|
[ "$LUET_BACKEND" == "img" ] && startSkipping
|
||||||
|
mkdir $tmpdir/testrootfs
|
||||||
|
cat <<EOF > $tmpdir/luet.yaml
|
||||||
|
general:
|
||||||
|
debug: true
|
||||||
|
system:
|
||||||
|
rootfs: $tmpdir/testrootfs
|
||||||
|
database_path: "/"
|
||||||
|
database_engine: "boltdb"
|
||||||
|
config_from_host: true
|
||||||
|
repositories:
|
||||||
|
- name: "main"
|
||||||
|
type: "disk"
|
||||||
|
enable: true
|
||||||
|
urls:
|
||||||
|
- "$tmpdir/testbuild"
|
||||||
|
EOF
|
||||||
|
luet config --config $tmpdir/luet.yaml
|
||||||
|
res=$?
|
||||||
|
assertEquals 'config test successfully' "$res" "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
testInstall() {
|
||||||
|
[ "$LUET_BACKEND" == "img" ] && startSkipping
|
||||||
|
$ROOT_DIR/tests/integration/bin/luet install -y --config $tmpdir/luet.yaml test/perms@0.1 test/perms2@0.1
|
||||||
|
installst=$?
|
||||||
|
assertEquals 'install test successfully' "$installst" "0"
|
||||||
|
|
||||||
|
assertTrue 'package installed perms baz' "[ -d '$tmpdir/testrootfs/foo/baz' ]"
|
||||||
|
assertTrue 'package installed perms bar' "[ -d '$tmpdir/testrootfs/foo/bar' ]"
|
||||||
|
|
||||||
|
assertContains 'perms1' "$(stat -c %u:%g $tmpdir/testrootfs/foo/baz)" "100:100"
|
||||||
|
assertContains 'perms2' "$(stat -c %u:%g $tmpdir/testrootfs/foo/bar)" "100:100"
|
||||||
|
assertContains 'perms11' "$(stat -c %u:%g $tmpdir/testrootfs/foo/baz/.keep)" "101:101"
|
||||||
|
assertContains 'perms22' "$(stat -c %u:%g $tmpdir/testrootfs/foo/bar/.keep)" "101:101"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Load shUnit2.
|
||||||
|
. "$ROOT_DIR/tests/integration/shunit2"/shunit2
|
||||||
|
|
Reference in New Issue
Block a user