Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raulb committed Feb 19, 2022
1 parent b424507 commit 47cae3b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
37 changes: 22 additions & 15 deletions cmd/meroxa/root/apps/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/meroxa/cli/cmd/meroxa/global"
"io"
"os"
"os/exec"
Expand All @@ -16,13 +15,17 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/archive"
"github.com/meroxa/cli/cmd/meroxa/global"
"github.com/meroxa/cli/log"
turbine "github.com/meroxa/turbine/deploy"
)

const (
dockerHubUserNameEnv = "DOCKER_HUB_USERNAME"
dockerHubAccessTokenEnv = "DOCKER_HUB_ACCESS_TOKEN"
dockerHubAccessTokenEnv = "DOCKER_HUB_ACCESS_TOKEN" // nolint:gosec
goLang = "golang"
javaScript = "javascript"
nodeJS = "nodejs"
)

func buildGoApp(ctx context.Context, l log.Logger, appPath, appName string, platform bool) error {
Expand All @@ -33,7 +36,7 @@ func buildGoApp(ctx context.Context, l log.Logger, appPath, appName string, plat
}

if platform {
cmd = exec.Command("go", "build", "--tags", "platform", "-o", appName, "./...") //nolint:gosec
cmd = exec.Command("go", "build", "--tags", "platform", "-o", appName, "./...")
} else {
cmd = exec.Command("go", "build", "-o", appName, "./...")
}
Expand All @@ -48,17 +51,16 @@ func buildGoApp(ctx context.Context, l log.Logger, appPath, appName string, plat
return nil
}

func deployApp(ctx context.Context, l log.Logger, appPath, appName string, imageName string) error {
func deployApp(ctx context.Context, l log.Logger, appPath, appName, imageName string) error {
l.Info(ctx, "deploying app...\n")

cmd := exec.Command(appPath+"/"+appName, "--deploy", "--imagename", imageName)
cmd := exec.Command(appPath+"/"+appName, "--deploy", "--imagename", imageName) // nolint:gosec
accessToken, refreshToken, err := global.GetUserToken()
if err != nil {
return err
}
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("ACCESS_TOKEN=%s", accessToken))
cmd.Env = append(cmd.Env, fmt.Sprintf("REFRESH_TOKEN=%s", refreshToken))
cmd.Env = append(cmd.Env, fmt.Sprintf("ACCESS_TOKEN=%s", accessToken), fmt.Sprintf("REFRESH_TOKEN=%s", refreshToken))

stdout, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -71,21 +73,21 @@ func deployApp(ctx context.Context, l log.Logger, appPath, appName string, image
return nil
}

func buildImage(ctx context.Context, l log.Logger, path string, imageName string) error {
l.Infof(ctx, "Building image %q located at %q", imageName, path)
func buildImage(ctx context.Context, l log.Logger, pwd, imageName string) error {
l.Infof(ctx, "Building image %q located at %q", imageName, pwd)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
l.Errorf(ctx, "unable to init docker client; %s", err)
}

// Generate dockerfile
err = turbine.CreateDockerfile(path)
err = turbine.CreateDockerfile(pwd)
if err != nil {
return err
}

// Read local Dockerfile
tar, err := archive.TarWithOptions(path, &archive.TarOptions{
tar, err := archive.TarWithOptions(pwd, &archive.TarOptions{
Compression: archive.Uncompressed,
ExcludePatterns: []string{".git", "fixtures"},
})
Expand All @@ -108,7 +110,7 @@ func buildImage(ctx context.Context, l log.Logger, path string, imageName string
l.Errorf(ctx, "unable to build docker image; %s", err)
}
defer func(Body io.ReadCloser) {
err := Body.Close()
err = Body.Close()
if err != nil {
l.Errorf(ctx, "unable to close docker build response body; %s", err)
}
Expand All @@ -120,13 +122,13 @@ func buildImage(ctx context.Context, l log.Logger, path string, imageName string
return nil
}

func pushImage(ctx context.Context, l log.Logger, imageName string) error {
func pushImage(l log.Logger, imageName string) error {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return err
}
authConfig := getAuthConfig()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*120) // nolint:gomnd
defer cancel()

l.Infof(ctx, "pushing image %q to container registry", imageName)
Expand All @@ -135,7 +137,12 @@ func pushImage(ctx context.Context, l log.Logger, imageName string) error {
if err != nil {
return err
}
defer rd.Close()
defer func(rd io.ReadCloser) {
err = rd.Close()
if err != nil {
l.Error(ctx, err.Error())
}
}(rd)

_, err = io.Copy(os.Stdout, rd)
if err != nil {
Expand Down
11 changes: 5 additions & 6 deletions cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (*Deploy) Docs() builder.Docs {
}
}

func (d *Deploy) Config(config config.Config) {
d.config = config
func (d *Deploy) Config(cfg config.Config) {
d.config = cfg
}

func (d *Deploy) Flags() []builder.Flag {
Expand Down Expand Up @@ -95,7 +95,7 @@ func (d *Deploy) deployGoApp(ctx context.Context) error {
d.logger.Errorf(ctx, "unable to build image; %q\n%s", fqImageName, err)
}

err = pushImage(ctx, d.logger, fqImageName)
err = pushImage(d.logger, fqImageName)
if err != nil {
d.logger.Errorf(ctx, "unable to push image; %q\n%s", fqImageName, err)
}
Expand All @@ -115,7 +115,7 @@ func (d *Deploy) deployGoApp(ctx context.Context) error {
}

func (d *Deploy) deployJSApp(ctx context.Context) error {
cmd := exec.Command("npx", "turbine", "deploy", d.getPath())
cmd := exec.Command("npx", "turbine", "deploy", d.getPath()) // nolint:gosec

accessToken, _, err := global.GetUserToken()
if err != nil {
Expand All @@ -140,7 +140,6 @@ func (d *Deploy) Execute(ctx context.Context) error {
}

appPath := d.getPath()

appConfig, err := readConfigFile(appPath)
if err != nil {
return err
Expand All @@ -155,7 +154,7 @@ func (d *Deploy) Execute(ctx context.Context) error {
switch lang {
case "go", "golang":
return d.deployGoApp(ctx)
case "js", "javascript", "nodejs":
case "js", "javascript", nodeJS:
return d.deployJSApp(ctx)
default:
return fmt.Errorf("language %q not supported. Currently, we support \"javascript\" and \"go\"", lang)
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/root/apps/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ func (i *Init) Execute(ctx context.Context) error {
}

switch lang {
case "go", "golang":
case "go", goLang:
i.logger.Infof(ctx, "Initializing application %q in %q", name, path)
err := turbine.Init(path, name)
if err != nil {
return err
}
i.logger.Infof(ctx, "Application successfully initialized!\n"+
"You can start interacting with Meroxa in your app located at %s", path)
case "js", "javascript", "nodejs":
case "js", javaScript, "nodejs":
cmd := exec.Command("npx", "turbine", "generate", name)
stdout, err := cmd.CombinedOutput()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/root/apps/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func (r *Run) Execute(ctx context.Context) error {
}

switch lang {
case "go", "golang":
case "go", goLang:
return r.buildGoApp(ctx, appPath)
case "js", "javascript", "nodejs":
case "js", javaScript, nodeJS:
return r.buildJSApp(ctx)
default:
return fmt.Errorf("language %q not supported. Currently, we support \"javascript\" and \"go\"", lang)
Expand Down
3 changes: 1 addition & 2 deletions cmd/meroxa/root/auth/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
"strings"
"time"

"github.com/meroxa/cli/cmd/meroxa/global"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/cmd/meroxa/global"
"github.com/meroxa/cli/config"
"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go/pkg/meroxa"
Expand Down

0 comments on commit 47cae3b

Please sign in to comment.