-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
speed up module bootstrapping … (#26)
* update vendor * speed up module bootstrapping Before we were doing a fetch on the module every time. On fast broadband this is like 3-4 sec. But on tethering it is 100sec+. This diff adds caching for modules and cached speed is negligable. I couldn't directly use the terraform because it isn't well encapsulated, so this diff means we don't support terraform registry modules and we only invaliate the cache on new versions of fogg. This is ok because we only support the 1 hardcoded module for now. * improve error handling
- Loading branch information
Showing
110 changed files
with
119 additions
and
118,402 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package util | ||
|
||
import ( | ||
"crypto/sha256" | ||
"os" | ||
"path/filepath" | ||
|
||
getter "github.com/hashicorp/go-getter" | ||
"github.com/hashicorp/terraform/config" | ||
homedir "github.com/mitchellh/go-homedir" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func DownloadModule(cacheDir, source string) (string, error) { | ||
pwd, e := os.Getwd() | ||
if e != nil { | ||
return "", errors.Wrap(e, "could not get pwd") | ||
} | ||
s, e := getter.Detect(source, pwd, getter.Detectors) | ||
if e != nil { | ||
return "", errors.Wrap(e, "could not detect module type") | ||
} | ||
|
||
storage := &getter.FolderStorage{ | ||
StorageDir: cacheDir, | ||
} | ||
h := sha256.New() | ||
_, e = h.Write([]byte(VersionCacheKey())) | ||
if e != nil { | ||
return "", errors.Wrap(e, "could not hash") | ||
} | ||
_, e = h.Write([]byte(source)) | ||
if e != nil { | ||
return "", errors.Wrap(e, "could not hash") | ||
} | ||
hash := string(h.Sum(nil)) | ||
|
||
e = storage.Get(hash, s, false) | ||
if e != nil { | ||
return "", e | ||
} | ||
d, _, e := storage.Dir(hash) | ||
if e != nil { | ||
return "", errors.Wrap(e, "could not get module storage dir") | ||
} | ||
return d, nil | ||
} | ||
|
||
func DownloadAndParseModule(mod string) (*config.Config, error) { | ||
homedir, e := homedir.Dir() | ||
if e != nil { | ||
return nil, errors.Wrap(e, "unable to find homedir") | ||
} | ||
|
||
dir := filepath.Join(homedir, ".fogg", "cache") | ||
|
||
d, e := DownloadModule(dir, mod) | ||
if e != nil { | ||
return nil, errors.Wrap(e, "unable to download module") | ||
} | ||
return config.LoadDir(d) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package util | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDownloadModule(t *testing.T) { | ||
dir, e := ioutil.TempDir("", "fogg") | ||
assert.Nil(t, e) | ||
|
||
d, e := DownloadModule(dir, "./test-module") | ||
assert.Nil(t, e) | ||
assert.NotNil(t, d) | ||
assert.NotEmpty(t, d) | ||
// TODO more asserts | ||
} | ||
|
||
func TestDownloadAndParseModule(t *testing.T) { | ||
c, e := DownloadAndParseModule("./test-module") | ||
assert.Nil(t, e) | ||
assert.NotNil(t, c) | ||
assert.NotNil(t, c.Variables) | ||
assert.NotNil(t, c.Outputs) | ||
assert.Len(t, c.Variables, 2) | ||
assert.Len(t, c.Outputs, 2) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.