Permalink
Browse files

pkg/osutil: remove dependency on pkg/env

pkg/osutil started depending on pkg/env in
c55c860 , when we added
DefaultLetsEncryptCache(), because it behaves differently whether we're
on GCE or not.

This in turn made pkg/osutil depend on
cloud.google.com/go/compute/metadata and a couple of others. This, in
itself, was not so bad since the main user of pkg/osutil,
server/camlistored already depends on all these same dependencies
anyway.

However, pkg/types/camtypes depends on pkg/osutil (although maybe it
shouldn't) because it calls osutil.UserClientConfigPath() for an error
message.

And finally, in app/publisher/js - which is some Go code meant as input
for gopherjs, so that it gets compiled into javascript that we include
in the publisher web page - we depend on pkg/types/camtypes for some
search query results.

So as of c55c860, we "leaked" a couple
of additional and unnecessary dependencies into the gopherjs generated
code. That made the minified output unnoticeably grow, and apparently
had no other adverse effect, so we didn't notice.

That is, until we landed b0b6a0a, which
updated a ton of vendored dependencies, most of them in
cloud.google.com/go and google.golang.org/api. And interestingly, the
update made cloud.google.com/go/compute/metadata depend on a lot of
these other dependencies. This had two noticeable consequences:

1) The (unminified) generated js code grew from 6.1M to 8.2M, which in
itself is super bad already.

2) The js code actually stopped working. For some reason (that I can't
explain, and will probably leave to the GopherJS devs if they're
interested), the members/functions that we export to the javascript
namespace with gopherjs (typically with a
js.Global.Set("ExportedNameForFoo", FooFunc)), are not visible anymore,
which of course breaks everything.

Therefore, this CL fixes this issue by simply doing what we knew we
should have done from the start:

we now let pkg/osutil/gce (which already depends on pkg/env) itself
register a LetsEncryptCacheFunc into pkg/osutil, which removes the need
for pkg/osutil to depend on pkg/env.

Change-Id: Ie8f33e9cb873919dd1728068dd8a5d0170282f88
  • Loading branch information...
mpl committed Jan 17, 2017
1 parent abc6561 commit 668ca6996780d8bca4b76069e97d30f0f45b5cbe
Showing with 16 additions and 3 deletions.
  1. +3 −0 pkg/osutil/gce/gce.go
  2. +13 −3 pkg/osutil/paths.go
@@ -47,6 +47,9 @@ func init() {
}
return path.Clean("/gcs/" + strings.TrimPrefix(v, "gs://"))
})
osutil.RegisterLetsEncryptCacheFunc(func() string {
return "/tmp/camli-letsencrypt.cache"
})
jsonconfig.RegisterFunc("_gce_instance_meta", func(c *jsonconfig.ConfigParser, v []interface{}) (interface{}, error) {
if len(v) != 1 {
return nil, errors.New("only 1 argument supported after _gce_instance_meta")
@@ -25,7 +25,6 @@ import (
"sync"
"camlistore.org/pkg/buildinfo"
"camlistore.org/pkg/env"
"go4.org/jsonconfig"
)
@@ -216,11 +215,22 @@ func DefaultTLSKey() string {
return filepath.Join(CamliConfigDir(), "tls.key")
}
// RegisterLetsEncryptCacheFunc registers a func f to return the path to the
// default Let's Encrypt cache.
// It may skip by returning the empty string.
func RegisterLetsEncryptCacheFunc(f func() string) {
letsEncryptCacheFuncs = append(letsEncryptCacheFuncs, f)
}
var letsEncryptCacheFuncs []func() string
// DefaultLetsEncryptCache returns the path to the default Let's Encrypt cache
// directory (or file, depending on the ACME implementation).
func DefaultLetsEncryptCache() string {
if env.OnGCE() {
return "/tmp/camli-letsencrypt.cache"
for _, f := range letsEncryptCacheFuncs {
if v := f(); v != "" {
return v
}
}
return filepath.Join(CamliConfigDir(), "letsencrypt.cache")
}

0 comments on commit 668ca69

Please sign in to comment.