Adds support to 3 environment variables: - WAREWULF_OCI_USERNAME: registry user username - WAREWULF_OCI_PASSWORD: registry user password - WAREWULF_OCI_NOHTTPS: disable tls requirements (for local registries) Note: This will default to ~/.docker/config.json for credentials and other docker configurations on the system when no options are specified.
50 lines
969 B
Go
50 lines
969 B
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/containers/image/v5/types"
|
|
"github.com/hpcng/warewulf/internal/pkg/config"
|
|
"github.com/hpcng/warewulf/internal/pkg/errors"
|
|
"github.com/hpcng/warewulf/internal/pkg/oci"
|
|
)
|
|
|
|
func PullURI(uri string, name string, sCtx *types.SystemContext) error {
|
|
OciBlobCacheDir := config.LocalStateDir + "/oci/blobs"
|
|
|
|
err := os.MkdirAll(OciBlobCacheDir, 0755)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if ValidName(name) == false {
|
|
return errors.New("VNFS name contains illegal characters: " + name)
|
|
}
|
|
|
|
fullPath := RootFsDir(name)
|
|
|
|
err = os.MkdirAll(fullPath, 0755)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
p, err := oci.NewPuller(
|
|
oci.OptSetBlobCachePath(OciBlobCacheDir),
|
|
oci.OptSetSystemContext(sCtx),
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if _, err := p.GenerateID(context.Background(), uri); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := p.Pull(context.Background(), uri, fullPath); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|