-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable offline install of labs projects #2049
base: main
Are you sure you want to change the base?
Changes from all commits
98bdd8d
c514cca
41313db
870003d
4ed82de
d846c91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,15 @@ import ( | |
) | ||
|
||
type installable interface { | ||
Install(ctx context.Context) error | ||
Install(ctx context.Context, offlineInstall bool) error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a property on the installable, not a function argument. |
||
} | ||
|
||
type devInstallation struct { | ||
*Project | ||
*cobra.Command | ||
} | ||
|
||
func (d *devInstallation) Install(ctx context.Context) error { | ||
func (d *devInstallation) Install(ctx context.Context, offlineInstall bool) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, not needed here. |
||
if d.Installer == nil { | ||
return nil | ||
} | ||
|
@@ -54,7 +54,7 @@ func (d *devInstallation) Install(ctx context.Context) error { | |
return d.Installer.runHook(d.Command) | ||
} | ||
|
||
func NewInstaller(cmd *cobra.Command, name string) (installable, error) { | ||
func NewInstaller(cmd *cobra.Command, name string, offlineInstall bool) (installable, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bool should be a property on the |
||
if name == "." { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
|
@@ -75,14 +75,17 @@ func NewInstaller(cmd *cobra.Command, name string) (installable, error) { | |
version = "latest" | ||
} | ||
f := &fetcher{name} | ||
version, err := f.checkReleasedVersions(cmd, version) | ||
|
||
version, err := f.checkReleasedVersions(cmd, version, offlineInstall) | ||
if err != nil { | ||
return nil, fmt.Errorf("version: %w", err) | ||
} | ||
prj, err := f.loadRemoteProjectDefinition(cmd, version) | ||
|
||
prj, err := f.loadRemoteProjectDefinition(cmd, version, offlineInstall) | ||
if err != nil { | ||
return nil, fmt.Errorf("remote: %w", err) | ||
} | ||
|
||
return &installer{ | ||
Project: prj, | ||
version: version, | ||
|
@@ -92,11 +95,11 @@ func NewInstaller(cmd *cobra.Command, name string) (installable, error) { | |
|
||
func NewUpgrader(cmd *cobra.Command, name string) (*installer, error) { | ||
f := &fetcher{name} | ||
version, err := f.checkReleasedVersions(cmd, "latest") | ||
version, err := f.checkReleasedVersions(cmd, "latest", false) | ||
if err != nil { | ||
return nil, fmt.Errorf("version: %w", err) | ||
} | ||
prj, err := f.loadRemoteProjectDefinition(cmd, version) | ||
prj, err := f.loadRemoteProjectDefinition(cmd, version, false) | ||
if err != nil { | ||
return nil, fmt.Errorf("remote: %w", err) | ||
} | ||
|
@@ -115,15 +118,16 @@ type fetcher struct { | |
name string | ||
} | ||
|
||
func (f *fetcher) checkReleasedVersions(cmd *cobra.Command, version string) (string, error) { | ||
func (f *fetcher) checkReleasedVersions(cmd *cobra.Command, version string, offlineInstall bool) (string, error) { | ||
ctx := cmd.Context() | ||
cacheDir, err := PathInLabs(ctx, f.name, "cache") | ||
if err != nil { | ||
return "", err | ||
} | ||
// `databricks labs isntall X` doesn't know which exact version to fetch, so first | ||
// we fetch all versions and then pick the latest one dynamically. | ||
versions, err := github.NewReleaseCache("databrickslabs", f.name, cacheDir).Load(ctx) | ||
var versions github.Versions | ||
versions, err = github.NewReleaseCache("databrickslabs", f.name, cacheDir, offlineInstall).Load(ctx) | ||
if err != nil { | ||
return "", fmt.Errorf("versions: %w", err) | ||
} | ||
|
@@ -140,9 +144,21 @@ func (f *fetcher) checkReleasedVersions(cmd *cobra.Command, version string) (str | |
return version, nil | ||
} | ||
|
||
func (i *fetcher) loadRemoteProjectDefinition(cmd *cobra.Command, version string) (*Project, error) { | ||
func (i *fetcher) loadRemoteProjectDefinition(cmd *cobra.Command, version string, offlineInstall bool) (*Project, error) { | ||
ctx := cmd.Context() | ||
raw, err := github.ReadFileFromRef(ctx, "databrickslabs", i.name, version, "labs.yml") | ||
var raw []byte | ||
var err error | ||
if !offlineInstall { | ||
raw, err = github.ReadFileFromRef(ctx, "databrickslabs", i.name, version, "labs.yml") | ||
} else { | ||
libDir, file_err := PathInLabs(ctx, i.name, "lib") | ||
if file_err != nil { | ||
return nil, file_err | ||
} | ||
fileName := filepath.Join(libDir, "labs.yml") | ||
raw, err = os.ReadFile(fileName) | ||
} | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("read labs.yml from GitHub: %w", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert.