Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Official CLI for [Depot](https://depot.dev) - you can use the CLI to build Docke
- [`depot exec`](#depot-exec)
- [`depot gocache`](#depot-gocache)
- [`depot configure-docker`](#depot-configure-docker)
- [`depot login-docker`](#depot-login-docker)
- [`depot list`](#depot-list)
- [`depot list projects`](#depot-list-projects)
- [`depot list builds`](#depot-list-builds)
Expand Down Expand Up @@ -360,6 +361,20 @@ If you want to uninstall the plugin, you can specify the `--uninstall` flag.
depot configure-docker --uninstall
```

### `depot login-docker`

Configure Docker to download from the [Depot Registry](https://depot.dev/docs/registry/overview). This command stores your user API token as a Docker credential so you can `docker pull` images from your organization's registries.

```shell
depot login-docker
```

If you want to log out, use the Docker CLI.

```shell
docker logout {orgId}.registry.depot.dev
```

### `depot list`

Interact with Depot projects and builds.
Expand Down Expand Up @@ -455,11 +470,11 @@ depot projects delete --project-id your-project-id --yes

#### Flags for `projects delete`

| Name | Description |
| -------------- | ---------------------------------------------- |
| `project-id` | The ID of the project to delete |
| `yes` | Confirm deletion without interactive prompt |
| `token` | Depot API token |
| Name | Description |
| ------------ | ------------------------------------------- |
| `project-id` | The ID of the project to delete |
| `yes` | Confirm deletion without interactive prompt |
| `token` | Depot API token |

#### `depot projects list`

Expand Down
76 changes: 76 additions & 0 deletions pkg/cmd/docker/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package docker

import (
"fmt"

"github.com/depot/cli/pkg/config"
"github.com/depot/cli/pkg/dockerclient"
"github.com/depot/cli/pkg/helpers"
configtypes "github.com/docker/cli/cli/config/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/spf13/cobra"
)

func NewCmdLoginDocker() *cobra.Command {
var (
org string
token string
)

cmd := &cobra.Command{
Use: "login-docker",
Short: "Log in Docker to the Depot registry with your user API token",
RunE: func(cmd *cobra.Command, args []string) error {
token, err := helpers.ResolveOrgAuth(cmd.Context(), token)
if err != nil {
return err
}
if token == "" {
return fmt.Errorf("missing API token, please run `depot login`")
}
Comment thread
agdphd marked this conversation as resolved.

if org == "" {
org = config.GetCurrentOrganization()
}
if org == "" {
return fmt.Errorf("No organization configured; use the --org flag or verify your project configuration")
}

dockerCli, err := dockerclient.NewDockerCLI()
if err != nil {
return err
}

serverAddress := org + ".registry.depot.dev"
Comment thread
agdphd marked this conversation as resolved.
client := dockerCli.Client()
_, err = client.RegistryLogin(cmd.Context(), registrytypes.AuthConfig{
Username: "x-token",
Password: token,
ServerAddress: serverAddress,
})
if err != nil {
return err
}

cfg := dockerCli.ConfigFile()
creds := cfg.GetCredentialsStore(serverAddress)
err = creds.Store(configtypes.AuthConfig{
Username: "x-token",
Password: token,
ServerAddress: serverAddress,
})
if err != nil {
return err
}

fmt.Println("Successfully stored Docker credentials for " + serverAddress)
return nil
},
}

flags := cmd.Flags()
flags.StringVar(&org, "org", "", "Depot organization ID")
flags.StringVar(&token, "token", "", "Depot token")

return cmd
}
1 change: 1 addition & 0 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewCmdRoot(version, buildDate string) *cobra.Command {
cmd.AddCommand(push.NewCmdPush())
cmd.AddCommand(versionCmd.NewCmdVersion(version, buildDate))
cmd.AddCommand(dockerCmd.NewCmdConfigureDocker())
cmd.AddCommand(dockerCmd.NewCmdLoginDocker())
cmd.AddCommand(registry.NewCmdRegistry())
cmd.AddCommand(org.NewCmdOrg())
cmd.AddCommand(projects.NewCmdProjects())
Expand Down
Loading