-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nydusify: small improvements for mount & check subcommands
- Add `--prefetch` option for enabling full image data prefetch. - Support `HTTP_PROXY` / `HTTPS_PROXY` env for enabling proxy for nydusd. - Change nydusd log level to `warn` for mount & check subcommands. Signed-off-by: Yan Song <[email protected]>
- Loading branch information
Showing
6 changed files
with
79 additions
and
42 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,57 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/distribution/reference" | ||
dockerconfig "github.com/docker/cli/cli/config" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type RegistryBackendConfig struct { | ||
Scheme string `json:"scheme"` | ||
Host string `json:"host"` | ||
Repo string `json:"repo"` | ||
Auth string `json:"auth,omitempty"` | ||
SkipVerify bool `json:"skip_verify,omitempty"` | ||
Proxy BackendProxyConfig `json:"proxy"` | ||
} | ||
|
||
type BackendProxyConfig struct { | ||
URL string `json:"url"` | ||
Fallback bool `json:"fallback"` | ||
PingURL string `json:"ping_url"` | ||
} | ||
|
||
func NewRegistryBackendConfig(parsed reference.Named, insecure bool) (RegistryBackendConfig, error) { | ||
proxyURL := os.Getenv("HTTP_PROXY") | ||
if proxyURL == "" { | ||
proxyURL = os.Getenv("HTTPS_PROXY") | ||
} | ||
|
||
backendConfig := RegistryBackendConfig{ | ||
Scheme: "https", | ||
Host: reference.Domain(parsed), | ||
Repo: reference.Path(parsed), | ||
SkipVerify: insecure, | ||
Proxy: BackendProxyConfig{ | ||
URL: proxyURL, | ||
Fallback: true, | ||
}, | ||
} | ||
|
||
config := dockerconfig.LoadDefaultConfigFile(os.Stderr) | ||
authConfig, err := config.GetAuthConfig(backendConfig.Host) | ||
if err != nil { | ||
return backendConfig, errors.Wrap(err, "get docker registry auth config") | ||
} | ||
var auth string | ||
if authConfig.Username != "" && authConfig.Password != "" { | ||
auth = base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", authConfig.Username, authConfig.Password))) | ||
} | ||
backendConfig.Auth = auth | ||
|
||
return backendConfig, nil | ||
} |
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