working commit

This commit is contained in:
2026-02-04 12:32:54 +02:00
parent 24b9acd678
commit 219a4cb890
17 changed files with 736 additions and 43 deletions
+17 -15
View File
@@ -1,4 +1,4 @@
package client
package auxutar
import (
"archive/tar"
@@ -8,16 +8,18 @@ import (
"strings"
)
func archiveDir(srcDir, dstPath string) error {
var err error
srcDir = filepath.Clean(srcDir)
dstPath = filepath.Clean(dstPath)
// TODO: file and dir modes
err = os.MkdirAll(filepath.Dir(dstPath), 0755)
func Archive(srcdir, dstpath string) error {
var err error
srcdir = filepath.Clean(srcdir)
dstpath = filepath.Clean(dstpath)
err = os.MkdirAll(filepath.Dir(dstpath), 0755)
if err != nil {
return err
}
tarFile, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640)
tarFile, err := os.OpenFile(dstpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640)
if err != nil {
return err
}
@@ -26,7 +28,7 @@ func archiveDir(srcDir, dstPath string) error {
tarWriter := tar.NewWriter(tarFile)
defer tarWriter.Close()
walker := func(filePath string, fileInfo os.FileInfo, err error) error {
walker := func(filename string, fileInfo os.FileInfo, err error) error {
if err != nil {
return err
}
@@ -37,14 +39,14 @@ func archiveDir(srcDir, dstPath string) error {
if err != nil {
return err
}
header.Name = strings.TrimPrefix(filePath, filepath.Clean(srcDir))
header.Name = strings.TrimPrefix(filename, filepath.Clean(srcdir))
header.Name = strings.TrimPrefix(header.Name, string(filepath.Separator))
err = tarWriter.WriteHeader(header)
if err != nil {
return err
}
file, err := os.Open(filePath)
file, err := os.Open(filename)
if err != nil {
return err
}
@@ -55,20 +57,20 @@ func archiveDir(srcDir, dstPath string) error {
}
return nil
}
err = filepath.Walk(srcDir, walker)
err = filepath.Walk(srcdir, walker)
if err != nil {
return err
}
return err
}
func unarchive(filePath, dstDir string) error {
func Unarchive(filename, dstdir string) error {
var err error
err = os.MkdirAll(dstDir, 0755)
err = os.MkdirAll(dstdir, 0755)
if err != nil {
return err
}
file, err := os.OpenFile(filePath, os.O_RDONLY, 0)
file, err := os.OpenFile(filename, os.O_RDONLY, 0)
if err != nil {
return err
}
@@ -85,7 +87,7 @@ func unarchive(filePath, dstDir string) error {
case header == nil:
continue
}
target := filepath.Join(dstDir, header.Name)
target := filepath.Join(dstdir, header.Name)
target = filepath.Clean(target)
//fileInfo := header.FileInfo()
switch header.Typeflag {
+1
View File
@@ -44,6 +44,7 @@ func TestImageLife(t *testing.T) {
}
stopFunc := func() {
time.Sleep(5 * time.Second)
srv.Service().Stop()
svcWG.Wait()
err = <-errPipe
+3 -1
View File
@@ -5,6 +5,8 @@ import (
"os"
"time"
"mstore/pkg/auxutar"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
@@ -63,7 +65,7 @@ func (cli *Client) PullImage(ctx context.Context, filepath, imagepath string, ti
if err != nil {
return err
}
err = archiveDir(dstdir, filepath)
err = auxutar.Archive(dstdir, filepath)
if err != nil {
return err
}
+7 -2
View File
@@ -6,6 +6,8 @@ import (
"os"
"time"
"mstore/pkg/auxutar"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
@@ -57,20 +59,23 @@ func (cli *Client) PushImage(ctx context.Context, filepath, imagepath string, ti
}
dstdir := makeTmpFileName(filepath)
err = unarchive(filepath, dstdir)
err = auxutar.Unarchive(filepath, dstdir)
if err != nil {
os.RemoveAll(dstdir)
return err
}
image, err := imageLoader(dstdir)
if err != nil {
os.RemoveAll(dstdir)
return err
}
err = crane.Push(image, imagepath, options...)
if err != nil {
return err
}
err = os.RemoveAll(dstdir)
if err != nil {
return err
}
return err
}