package docker import ( b64 "encoding/base64" "fmt" "ledo/app/modules/aws_ledo" "ledo/app/modules/context" "net/url" "os" ) func trimLeftChars(s string, n int) string { m := 0 for i := range s { if m >= n { return s[i:] } m++ } return s[:0] } func DockerEcrLogin(ctx *context.LedoContext) error { ecr, err := aws_ledo.EcrLogin() if err != nil { fmt.Println("Ecr login error: %s", err) os.Exit(1) } password := *ecr.AuthorizationData[0].AuthorizationToken ecrUrl := *ecr.AuthorizationData[0].ProxyEndpoint sDec, _ := b64.StdEncoding.DecodeString(password) registryAddr, err := url.Parse(ecrUrl) if err != nil { fmt.Printf("Ecr endpoint addr parse error: %s", err) os.Exit(1) } ctx.ExecCmdSilent("docker", []string{"login", "-u", "AWS", "-p", string(trimLeftChars(string(sDec), 4)), registryAddr.Host}) return nil }