Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
codepope committed Jun 18, 2020
2 parents b1b1295 + e9f9cd1 commit b53e70f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ brew install superfly/tap/flyctl
To upgrade to the latest version:

```bash
brew upgrade superfly/tap/flyctl
brew upgrade flyctl
```

## Install Script
Expand All @@ -24,19 +24,15 @@ Download `flyctl` and install into
Installing the latest version:

```bash
curl https://get.fly.io/flyctl.sh | sh
curl -L https://fly.io/install.sh | sh
```

Installing a specific version:

```bash
curl https://get.fly.io/flyctl.sh | sh -s v0.0.1
curl -L https://fly.io/install.sh | sh -s v0.0.1
```

Install into a bin directory other than `/usr/local/bin`:
```bash
BIN_DIR=~/.bin curl https://get.fly.io/flyctl.sh | sh
```
## Downloading from GitHub

Download the appropriate version from the [Releases](https://github.com/superfly/flyctl/releases) page of the `flyctl` GitHub repository.
Expand Down
37 changes: 30 additions & 7 deletions cmd/auth.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package cmd

import (
"errors"
"fmt"
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/docker"
"os"
"os/exec"
"time"

"github.com/pkg/errors"
"github.com/superfly/flyctl/docstrings"
"github.com/superfly/flyctl/internal/client"

Expand Down Expand Up @@ -246,18 +247,40 @@ func runAuthToken(ctx *cmdctx.CmdContext) error {
func runAuthDocker(ctx *cmdctx.CmdContext) error {
cc := createCancellableContext()

dockerClient, err := docker.NewDockerClient()
binary, err := exec.LookPath("docker")
if err != nil {
return fmt.Errorf("Docker daemon unavailable: %s", err)
return errors.Wrap(err, "docker cli not found - make sure it's installed and try again")
}

token, _ := ctx.GlobalConfig.GetString(flyctl.ConfigAPIToken)
authConfig := docker.RegistryAuth(token)
if _, err := dockerClient.Client().RegistryLogin(cc, authConfig); err != nil {
token, _ := cc.GlobalConfig.GetString(flyctl.ConfigAPIToken)

cmd := exec.CommandContext(ctx, binary, "login", "--username=x", "--password-stdin", "registry.fly.io")
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
go func() {
defer stdin.Close()
fmt.Fprint(stdin, token)
}()

if err := cmd.Wait(); err != nil {
return err
}

if !cmd.ProcessState.Success() {
output, err := cmd.CombinedOutput()
if err != nil {
return err
}
fmt.Println(output)
return errors.New("error authenticating with registry.fly.io")
}

fmt.Fprintln(ctx.Out, "Authentication successful. You can now tag and push images to registry.fly.io/{your-app}")
fmt.Println("Authentication successful. You can now tag and push images to registry.fly.io/{your-app}")

return nil
}
4 changes: 2 additions & 2 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ func CheckManifest(ctx context.Context, imageRef string, token string) (*dockerp

func RegistryAuth(token string) types.AuthConfig {
return types.AuthConfig{
Username: token,
Password: "x",
Username: "x",
Password: token,
ServerAddress: "registry.fly.io",
}
}
Expand Down

0 comments on commit b53e70f

Please sign in to comment.