-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
buildctl
import and export cache to use GitHub env variables
Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
- Loading branch information
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
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
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,33 @@ | ||
package build | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/moby/buildkit/client" | ||
) | ||
|
||
// loadGithubEnv verify that url and token attributes exists in the | ||
// cache. | ||
// If not, it will search for $ACTIONS_RUNTIME_TOKEN and $ACTIONS_CACHE_URL | ||
// environments variables and add it to cache Options | ||
// Since it works for both import and export | ||
func loadGithubEnv(cache client.CacheOptionsEntry) (client.CacheOptionsEntry, error) { | ||
if _, ok := cache.Attrs["url"]; !ok { | ||
url, ok := os.LookupEnv("ACTIONS_CACHE_URL") | ||
if !ok { | ||
return cache, errors.New("cache with type gha requires url parameter or $ACTIONS_CACHE_URL") | ||
} | ||
cache.Attrs["url"] = url | ||
} | ||
|
||
if _, ok := cache.Attrs["token"]; !ok { | ||
token, ok := os.LookupEnv("ACTIONS_RUNTIME_TOKEN") | ||
if !ok { | ||
return cache, errors.New("cache with type gha requires token parameter or $ACTIONS_RUNTIME_TOKEN") | ||
} | ||
cache.Attrs["token"] = token | ||
} | ||
return cache, nil | ||
} |