diff --git a/README.md b/README.md index 4ec3a7f..40ba8f8 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,15 @@ To configure your username and password run: bocker config set ``` +If you want to run bocker on server where there's no keyring tool installed, set the following environment variables: + +```sh +export DOCKER_USERNAME= +export DOCKER_PASSWORD= +``` + +`bocker` will prefer environment variables over the keyring. + ![bocker config](https://vhs.charm.sh/vhs-6w65TVtSWeJqk5oGv5N9cp.gif) ### List existing backups diff --git a/pkg/config/config.go b/pkg/config/config.go index 614bcc4..5945e93 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -96,6 +96,10 @@ func SetKey(service, secret string) error { // GetKey retrieves a key from the OS keyring func GetKey(service string) (string, error) { + if os.Getenv("DOCKER_PASSWORD") != "" { + return os.Getenv("DOCKER_PASSWORD"), nil + } + // get password secret, err := keyring.Get(service, AppName) if err != nil { @@ -110,6 +114,10 @@ func GetKey(service string) (string, error) { func GetUsername() (*Username, error) { var username Username + if os.Getenv("DOCKER_USERNAME") != "" { + return &Username{Username: os.Getenv("DOCKER_USERNAME")}, nil + } + dir, err := xdg.ConfigFile(AppName) if err != nil { return nil, err