Conversation
|
Looks great @wsutina! |
2eeefdb to
a6af831
Compare
| } | ||
|
|
||
| type HermitConfig struct { | ||
| BaseURL string `hcl:"base-url" help:"Base URL for internal redirects to github-releases strategy (e.g., http://localhost:8080)."` |
There was a problem hiding this comment.
| BaseURL string `hcl:"base-url" help:"Base URL for internal redirects to github-releases strategy (e.g., http://localhost:8080)."` | |
| BaseURL string `hcl:"base-url" help:"Base URL for internal redirects to github-releases strategy (e.g., http://localhost:8080)." default:"${CACHEW_URL}"` |
There was a problem hiding this comment.
If we set this default, 99% of the time it won't need to be explicitly configured.
There was a problem hiding this comment.
I wonder if this should have /github as the suffix too... I suspect that would be more flexible. ie. "${CACHEW_URL}/github"
There was a problem hiding this comment.
Is this what you mean?
My understanding is github-base-url will control where we redirect:
- If it sets to
${CACHEW_URL}/github.com-- it will go togithub-releasestrategy - If it sets to github.com -- it will go to github.com directly
| // redirectToGitHubReleases delegates to github-releases strategy using NoOpCache | ||
| // to avoid double caching (github-releases will cache the actual response). |
| } | ||
|
|
||
| // expandStructStrings expands environment variables in string fields of a struct. | ||
| func expandStructStrings(v any, vars map[string]string) { |
There was a problem hiding this comment.
What is this for? The config package already expands envars in the HCL.
There was a problem hiding this comment.
I think config in envar expansion works only hcl file but not for default in struct. For example
BaseURL string `hcl:"base-url" help:"Base URL for internal redirects to github-releases strategy" default:"$${CACHEW_URL}"`
results in
INF Hermit strategy initialized base_url=$${CACHEW_URL}
There was a problem hiding this comment.
This already works, you can see it used with github-release:
github-releases {
token = "${GITHUB_TOKEN}"There was a problem hiding this comment.
The var expansion works but if we want the default to be set in the config only:
cachew.hcl
hermit { } <-- no value
hermit.go
type HermitConfig struct {
GitHubBaseURL string `hcl:"github-base-url,optional" help:"Base URL for GitHub release redirects" default:"${CACHEW_URL}/github.com"`
}
and hcl is empty, the var expansion doesn't get called.
There was a problem hiding this comment.
Closing the loop. To addressed this, a change is made to alecthomas/hcl#46 to accept default transformer + fa8bc7c
- Defaults to ${CACHEW_URL}/github.com (uses github-releases strategy)
- Can override to https://github.com (direct to real GitHub)
09dde54 to
62a9437
Compare
62a9437 to
fa8bc7c
Compare
✍️ Changes
The Hermit strategy accepts requests at
/hermit/{host}/{path...}and acts as a smart router:/releases/download/) are redirected to the existing github-releases strategy using an internal HTTP call with NoOpCache to avoid double caching🧪 Testing
GitHub releases (
hermit install mk-6.0.1)Cache miss

Cache hit

All other sources (
hermit install go-1.17.3)Cache Miss

Cache Hit
