Skip to content

Commit

Permalink
Merge pull request #4 from podtserkovskiy/compact_image_storage
Browse files Browse the repository at this point in the history
compact_image_storage
  • Loading branch information
Mikhail Podtserkovskiy authored Sep 15, 2020
2 parents 09ad9c6 + 9604186 commit 91f8d66
Show file tree
Hide file tree
Showing 14 changed files with 609 additions and 352 deletions.
8 changes: 6 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import (
"context"
"fmt"

fs2 "github.com/podtserkovskiy/garnerd/storage/meta/fs"

"github.com/podtserkovskiy/garnerd/storage/image/compact"
"github.com/podtserkovskiy/garnerd/storage/separated"

"github.com/docker/docker/client"
log "github.com/sirupsen/logrus"

"github.com/podtserkovskiy/garnerd/cache/lru"
"github.com/podtserkovskiy/garnerd/director"
"github.com/podtserkovskiy/garnerd/docker"
"github.com/podtserkovskiy/garnerd/mover"
"github.com/podtserkovskiy/garnerd/storage/fs"
)

func Start(maxCount int, dir string) error {
Expand All @@ -31,7 +35,7 @@ func Start(maxCount int, dir string) error {
}

log.Infof("Cache dir: %s", dir)
storage := fs.NewStorage(dir)
storage := separated.NewStorage(fs2.NewMetaCRUD(fs2.NewMetaFile(dir)), compact.NewImgStorage(dir))
err = storage.Wait(ctx)
if err != nil {
return fmt.Errorf("waiting for storage, %s", err)
Expand Down
16 changes: 16 additions & 0 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package docker

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"time"
Expand Down Expand Up @@ -89,6 +91,20 @@ func (w *Daemon) LoadDump(ctx context.Context, image io.Reader) error {
}
defer resp.Body.Close()

if resp.JSON {
jsonError := struct {
Error string `json:"error"`
}{}

if err = json.NewDecoder(resp.Body).Decode(&jsonError); err != nil {
return err
}

if len(jsonError.Error) > 0 {
return errors.New(jsonError.Error) // nolint: goerr113
}
}

return nil
}

Expand Down
13 changes: 2 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@ require (
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/hashicorp/golang-lru v0.5.4
github.com/magiconair/properties v1.8.2 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/spf13/afero v1.3.4 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1 // indirect
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect
gopkg.in/ini.v1 v1.60.1 // indirect
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
golang.org/x/sys v0.0.0-20200915084602-288bc346aa39 // indirect
)
197 changes: 7 additions & 190 deletions go.sum

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions storage/image/compact/kamikaze_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package compact

import (
"io/ioutil"
"os"
)

// kamikazeFile removes itself on Closing.
type kamikazeFile struct {
file *os.File
}

func (t *kamikazeFile) Seek(offset int64, whence int) (int64, error) {
return t.file.Seek(offset, whence)
}

func newKamikazeFile() (*kamikazeFile, error) {
file, err := ioutil.TempFile("", "")
if err != nil {
return nil, err
}

return &kamikazeFile{file: file}, nil
}

func (t *kamikazeFile) Write(p []byte) (n int, err error) {
return t.file.Write(p)
}

func (t *kamikazeFile) Read(p []byte) (n int, err error) {
return t.file.Read(p)
}

func (t *kamikazeFile) Close() error {
closeErr := t.file.Close()
removeErr := os.Remove(t.file.Name())
if closeErr != nil {
return closeErr
}
if removeErr != nil {
return closeErr
}

return nil
}
Loading

0 comments on commit 91f8d66

Please sign in to comment.