Skip to content

Commit

Permalink
feat: Add more information about steps taken when deploying an applic…
Browse files Browse the repository at this point in the history
…ation (#399)

* feat: Add more information about steps taken

* feat: improve deployment output

* fix: vulnerability

* fix: cilint
  • Loading branch information
raulb authored Aug 5, 2022
1 parent 881b6dc commit e06ce79
Show file tree
Hide file tree
Showing 176 changed files with 8,990 additions and 1,846 deletions.
2 changes: 1 addition & 1 deletion cmd/meroxa/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func buildCommandWithExecute(cmd *cobra.Command, c Command) {
}
}

// nolint:funlen,gocyclo // this function has a big switch statement, can't get around that
//nolint:funlen,gocyclo // this function has a big switch statement, can't get around that
func buildCommandWithFlags(cmd *cobra.Command, c Command) {
v, ok := c.(CommandWithFlags)
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/global/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func userInfoStale() bool {
}

duration := time.Now().UTC().Sub(updatedAt)
return duration.Hours() > 24 // nolint:gomnd
return duration.Hours() > 24 //nolint:gomnd
}

func GetCLIUserInfo() (actor, actorUUID string, err error) {
Expand All @@ -64,7 +64,7 @@ func GetCLIUserInfo() (actor, actorUUID string, err error) {

if noUserInfo(actor, actorUUID) || userInfoStale() {
// call api to fetch
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) // nolint:gomnd
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) //nolint:gomnd
defer cancel()

m, err := NewClient()
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/global/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func readConfig() (*viper.Viper, error) {
configDir = filepath.Join(configDir, "meroxa")

// create subdirectory if it doesn't exist, otherwise viper will complain
err = os.MkdirAll(configDir, 0755) // nolint:gomnd
err = os.MkdirAll(configDir, 0755) //nolint:gomnd
if err != nil {
return nil, fmt.Errorf("could not create meroxa config directory: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func RegisterGlobalFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&flagCLIConfigFile, "cli-config-file", "", "meroxa configuration file")
cmd.PersistentFlags().StringVar(&flagAPIURL, "api-url", "", "API url")
cmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "display any debugging information")
cmd.PersistentFlags().DurationVar(&flagTimeout, "timeout", time.Second*10, "set the duration of the client timeout in seconds") // nolint:gomnd,lll
cmd.PersistentFlags().DurationVar(&flagTimeout, "timeout", time.Second*10, "set the duration of the client timeout in seconds") //nolint:gomnd,lll

if err := cmd.PersistentFlags().MarkHidden("api-url"); err != nil {
panic(fmt.Sprintf("could not mark flag as hidden: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/global/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ func publishEvent(event cased.AuditEvent) {

// The process will wait 30 seconds to publish all events to Cased before
// exiting the process.
cased.Flush(30 * time.Second) // nolint:gomnd
cased.Flush(30 * time.Second) //nolint:gomnd
}
4 changes: 1 addition & 3 deletions cmd/meroxa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ Copyright © 2022 Meroxa Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
4 changes: 2 additions & 2 deletions cmd/meroxa/root/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ func (a *API) Logger(logger log.Logger) {
}

func (a *API) ParseArgs(args []string) error {
if len(args) < 2 { // nolint:gomnd
if len(args) < 2 { //nolint:gomnd
return errors.New("requires METHOD and PATH")
}

a.args.Method = strings.ToUpper(args[0]) // so either a method such as `get` or `GET` works
a.args.Path = args[1]

if len(args) > 2 { // nolint:gomnd
if len(args) > 2 { //nolint:gomnd
a.args.Body = args[2]
}

Expand Down
42 changes: 29 additions & 13 deletions cmd/meroxa/root/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (

const (
dockerHubUserNameEnv = "DOCKER_HUB_USERNAME"
dockerHubAccessTokenEnv = "DOCKER_HUB_ACCESS_TOKEN" // nolint:gosec
dockerHubAccessTokenEnv = "DOCKER_HUB_ACCESS_TOKEN" //nolint:gosec
pollDuration = 2 * time.Second
)

Expand Down Expand Up @@ -190,10 +190,12 @@ func (d *Deploy) uploadSource(ctx context.Context, appPath, url string) error {
var err error

if d.lang == GoLang {
d.logger.StartSpinner("\t", fmt.Sprintf("Creating Dockerfile before uploading source in %s", appPath))
err = turbine.CreateDockerfile("", appPath)
if err != nil {
return err
}
d.logger.StopSpinnerWithStatus("Dockerfile created", log.Successful)
}

dFile := fmt.Sprintf("turbine-%s.tar.gz", d.appName)
Expand All @@ -209,6 +211,8 @@ func (d *Deploy) uploadSource(ctx context.Context, appPath, url string) error {
return err
}

d.logger.StartSpinner("\t", fmt.Sprintf(" Creating %q in %q to upload to our build service...", appPath, dFile))

fileToWrite, err := os.OpenFile(dFile, os.O_CREATE|os.O_RDWR, os.FileMode(0777)) //nolint:gomnd
defer func(fileToWrite *os.File) {
err = fileToWrite.Close()
Expand All @@ -223,13 +227,16 @@ func (d *Deploy) uploadSource(ctx context.Context, appPath, url string) error {
if _, err = io.Copy(fileToWrite, &buf); err != nil {
return err
}
d.logger.StopSpinnerWithStatus(fmt.Sprintf("%q successfully created in %q", dFile, appPath), log.Successful)

if d.lang == GoLang {
d.logger.StartSpinner("\t", fmt.Sprintf("Removing Dockerfile created for your application in %s...", appPath))
// We clean up Dockerfile as last step
err = os.Remove(filepath.Join(appPath, "Dockerfile"))
if err != nil {
return err
}
d.logger.StopSpinnerWithStatus("Dockerfile removed", log.Successful)
}

err = d.uploadFile(ctx, dFile, url)
Expand All @@ -238,13 +245,21 @@ func (d *Deploy) uploadSource(ctx context.Context, appPath, url string) error {
}

if d.lang == Python {
output, err := turbinePY.CleanUpApp(appPath)
var output string
output, err = turbinePY.CleanUpApp(appPath)
if err != nil {
fmt.Printf("warning: failed to clean up app at %s: %v %s\n", appPath, err, output)
}
}
// remove .tar.gz file
return os.Remove(dFile)
d.logger.StartSpinner("\t", fmt.Sprintf(" Removing %q...", dFile))
err = os.Remove(dFile)
if err != nil {
d.logger.StopSpinnerWithStatus(fmt.Sprintf("\t Something went wrong trying to remove %q", dFile), log.Failed)
return err
}
d.logger.StopSpinnerWithStatus(fmt.Sprintf("%q removed", dFile), log.Successful)
return nil
}

func (d *Deploy) uploadFile(ctx context.Context, filePath, url string) error {
Expand Down Expand Up @@ -289,7 +304,7 @@ func (d *Deploy) uploadFile(ctx context.Context, filePath, url string) error {
defer res.Body.Close()
}

d.logger.StopSpinnerWithStatus("Source uploaded!", log.Successful)
d.logger.StopSpinnerWithStatus("Source uploaded", log.Successful)
return nil
}

Expand All @@ -302,7 +317,7 @@ func (d *Deploy) getPlatformImage(ctx context.Context, appPath string) (string,
d.logger.StopSpinnerWithStatus("\t", log.Failed)
return "", err
}
d.logger.StopSpinnerWithStatus("Platform source fetched!", log.Successful)
d.logger.StopSpinnerWithStatus("Platform source fetched", log.Successful)

err = d.uploadSource(ctx, appPath, s.PutUrl)
if err != nil {
Expand Down Expand Up @@ -332,7 +347,7 @@ func (d *Deploy) getPlatformImage(ctx context.Context, appPath string) (string,
d.logger.StopSpinnerWithStatus(msg, log.Failed)
return "", fmt.Errorf("build with uuid %q errored", b.Uuid)
case "complete":
d.logger.StopSpinnerWithStatus(fmt.Sprintf("Successfully built Process image! (%q)", build.Uuid), log.Successful)
d.logger.StopSpinnerWithStatus(fmt.Sprintf("Successfully built process image (%q)\n", build.Uuid), log.Successful)
return build.Image, nil
}
time.Sleep(pollDuration)
Expand Down Expand Up @@ -361,7 +376,7 @@ func (d *Deploy) deployApp(ctx context.Context, imageName, gitSha string) error
d.logger.StopSpinnerWithStatus("Deployment failed to create Application\n\n", log.Failed)
return err
}
d.logger.StopSpinnerWithStatus("Deploy complete!", log.Successful)
d.logger.StopSpinnerWithStatus("Deploy complete", log.Successful)

dashboardURL := fmt.Sprintf("https://dashboard.meroxa.io/apps/%s/detail", app.UUID)
output := fmt.Sprintf("\t%s Application %q successfully created!\n\n ✨ To visualize your application visit %s",
Expand Down Expand Up @@ -392,7 +407,7 @@ func (d *Deploy) buildApp(ctx context.Context) error {
d.logger.StopSpinnerWithStatus("\t", log.Failed)
return err
}
d.logger.StopSpinnerWithStatus("Application built!", log.Successful)
d.logger.StopSpinnerWithStatus("Application built", log.Successful)
return nil
}

Expand All @@ -419,7 +434,7 @@ func (d *Deploy) getAppImage(ctx context.Context) (string, error) {

// If no need to build, return empty imageName which won't be utilized by the deploy process anyways
if !needsToBuild {
d.logger.StopSpinnerWithStatus("No need to create process image...", log.Successful)
d.logger.StopSpinnerWithStatus("No need to create process image...\n", log.Successful)
return "", nil
}

Expand Down Expand Up @@ -470,7 +485,7 @@ func (d *Deploy) validate(ctx context.Context) error {
return err
}

d.lang, err = turbineCLI.GetLangFromAppJSON(d.path)
d.lang, err = turbineCLI.GetLangFromAppJSON(ctx, d.logger, d.path)
if err != nil {
return err
}
Expand All @@ -480,7 +495,7 @@ func (d *Deploy) validate(ctx context.Context) error {
return err
}

d.appName, err = turbineCLI.GetAppNameFromAppJSON(d.path)
d.appName, err = turbineCLI.GetAppNameFromAppJSON(ctx, d.logger, d.path)
if err != nil {
return err
}
Expand Down Expand Up @@ -518,7 +533,7 @@ func (d *Deploy) getResourceCheckErrorMessage(ctx context.Context, resourceNames
}

func (d *Deploy) checkResourceAvailability(ctx context.Context) error {
resourceCheckMessage := fmt.Sprintf("Checking resource availability for application %q (%s) before deployment...", d.appName, d.lang)
resourceCheckMessage := fmt.Sprintf(" Checking resource availability for application %q (%s) before deployment...", d.appName, d.lang)

d.logger.StartSpinner("\t", resourceCheckMessage)

Expand Down Expand Up @@ -556,7 +571,7 @@ func (d *Deploy) checkResourceAvailability(ctx context.Context) error {
}

func (d *Deploy) prepareAppForDeployment(ctx context.Context) error {
d.logger.Infof(ctx, "Preparing application %q (%s) for deployment...", d.appName, d.lang)
d.logger.Infof(ctx, "Deploying application %q...", d.appName)

// After this point, CLI will package it up and will build it
err := d.buildApp(ctx)
Expand Down Expand Up @@ -608,6 +623,7 @@ func (d *Deploy) tearDownExistingResources(ctx context.Context) error {
}

func (d *Deploy) Execute(ctx context.Context) error {
d.logger.Info(ctx, "Validating your app.json...")
err := d.validate(ctx)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/apps/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *Run) Execute(ctx context.Context) error {
if err != nil {
return err
}
lang, err := turbineCLI.GetLang(r.flags.Lang, r.path)
lang, err := turbineCLI.GetLang(ctx, r.logger, r.flags.Lang, r.path)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/config/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (e *Describe) obfuscate(key, value string) string {
return value
}

if len(value) < 5 { // nolint:gomnd
if len(value) < 5 { //nolint:gomnd
// hide whole text
return strings.Repeat("*", len(value))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *Set) normalizeKey(key string) string {
func (s *Set) validateAndAssignKeyValue(kv string) error {
nkv := strings.Split(kv, "=")

if len(nkv) != 2 { // nolint:gomnd
if len(nkv) != 2 { //nolint:gomnd
return fmt.Errorf("a key=value needs to contain at least and only one `=` sign")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/connectors/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestConnectFlags(t *testing.T) {
}
}

// nolint:funlen
//nolint:funlen
func TestConnectExecution(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/environments/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Create struct {
Type string `long:"type" usage:"environment type, when not specified"`
Provider string `long:"provider" usage:"environment cloud provider to use"`
Region string `long:"region" usage:"environment region"`
Config []string `short:"c" long:"config" usage:"environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret)"` // nolint:lll
Config []string `short:"c" long:"config" usage:"environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_secret_access_key=my_access_secret)"` //nolint:lll
}

envCfg map[string]interface{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/environments/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *Repair) ParseArgs(args []string) error {
}

func (r *Repair) Execute(ctx context.Context) error {
environment, err := r.client.PerformActionOnEnvironment(ctx, r.args.NameOrUUID, &meroxa.RepairEnvironmentInput{Action: meroxa.EnvironmentActionRepair}) // nolint:lll
environment, err := r.client.PerformActionOnEnvironment(ctx, r.args.NameOrUUID, &meroxa.RepairEnvironmentInput{Action: meroxa.EnvironmentActionRepair}) //nolint:lll
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/environments/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Update struct {

flags struct {
Name string `long:"name" usage:"updated environment name, when specified"`
Config []string `short:"c" long:"config" usage:"updated environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret)"` // nolint:lll
Config []string `short:"c" long:"config" usage:"updated environment configuration based on type and provider (e.g.: --config aws_access_key_id=my_access_key --config aws_access_secret=my_access_secret)"` //nolint:lll
}

envCfg map[string]interface{}
Expand Down
8 changes: 4 additions & 4 deletions cmd/meroxa/turbine_cli/golang/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func RunDeployApp(ctx context.Context, l log.Logger, appPath, imageName, appName
var cmd *exec.Cmd

if imageName != "" {
cmd = exec.Command(appPath+"/"+appName, "--deploy", "--imagename", imageName, "--gitsha", gitSha) // nolint:gosec
cmd = exec.Command(appPath+"/"+appName, "--deploy", "--imagename", imageName, "--gitsha", gitSha) //nolint:gosec
} else {
cmd = exec.Command(appPath+"/"+appName, "--deploy", "--gitsha", gitSha) // nolint:gosec
cmd = exec.Command(appPath+"/"+appName, "--deploy", "--gitsha", gitSha) //nolint:gosec
}

accessToken, refreshToken, err := global.GetUserToken()
Expand All @@ -41,7 +41,7 @@ func RunDeployApp(ctx context.Context, l log.Logger, appPath, imageName, appName
func GetResourceNames(ctx context.Context, l log.Logger, appPath, appName string) ([]string, error) {
var names []string

cmd := exec.Command(appPath+"/"+appName, "--listresources") // nolint:gosec
cmd := exec.Command(appPath+"/"+appName, "--listresources") //nolint:gosec

output, err := cmd.CombinedOutput()
stringifiedOutput := string(output)
Expand All @@ -62,7 +62,7 @@ func GetResourceNames(ctx context.Context, l log.Logger, appPath, appName string
// NeedsToBuild reads from the Turbine application to determine whether it needs to be built or not
// this is currently based on the number of functions.
func NeedsToBuild(appPath, appName string) (bool, error) {
cmd := exec.Command(appPath+"/"+appName, "--listfunctions") // nolint:gosec
cmd := exec.Command(appPath+"/"+appName, "--listfunctions") //nolint:gosec

accessToken, refreshToken, err := global.GetUserToken()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/turbine_cli/local_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (ld *LocalDeploy) pushImage(l log.Logger, imageName string) error {
return err
}
authConfig := ld.getAuthConfig()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*120) // nolint:gomnd
ctx, cancel := context.WithTimeout(context.Background(), time.Second*120) //nolint:gomnd
defer cancel()

l.Infof(ctx, "pushing image %q to container registry", imageName)
Expand Down
Loading

0 comments on commit e06ce79

Please sign in to comment.