1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
package sources
import (
"fmt"
"os"
"path/filepath"
dcapi "github.com/mudler/docker-companion/api"
)
type docker struct {
common
}
// Run downloads and unpacks a docker image.
func (s *docker) Run() error {
absRootfsDir, err := filepath.Abs(s.rootfsDir)
if err != nil {
return fmt.Errorf("Failed to get absolute path of %s: %w", s.rootfsDir, err)
}
// If DOCKER_REGISTRY_BASE is not set it's used default https://registry-1.docker.io
err = dcapi.DownloadAndUnpackImage(s.definition.Source.URL, absRootfsDir, &dcapi.DownloadOpts{
RegistryBase: os.Getenv("DOCKER_REGISTRY_BASE"),
RegistryUsername: os.Getenv("DOCKER_REGISTRY_BASE_USER"),
RegistryPassword: os.Getenv("DOCKER_REGISTRY_BASE_PASS"),
KeepLayers: false,
})
if err != nil {
return fmt.Errorf("Failed to download an unpack image: %w", err)
}
return nil
}
|