-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from leapfrogtechnology/dev
Initial release
- Loading branch information
Showing
50 changed files
with
769 additions
and
948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package cmd | ||
|
||
// "github.com/leapfrogtechnology/shift/cli/internal/deploy" | ||
import ( | ||
"github.com/leapfrogtechnology/shift/cli/internals/deploy" | ||
) | ||
|
||
// Deploy triggers deployment for provided project. | ||
func Deploy(project string, deployment string) { | ||
// deploy.Run(project, deployment) | ||
// Deploy triggers deployment for the given environment. | ||
func Deploy(environment string) { | ||
deploy.Run(environment) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cmd | ||
|
||
import "github.com/leapfrogtechnology/shift/cli/internals/destroy" | ||
|
||
// Destroy deletes existing infrastructure | ||
func Destroy(environment string) { | ||
destroy.Run(environment) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/leapfrogtechnology/shift/cli/internals/env" | ||
) | ||
|
||
// AddEnv adds a new environment to the project. | ||
func AddEnv() { | ||
env.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package deploy | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/leapfrogtechnology/shift/core/services/slack" | ||
"github.com/leapfrogtechnology/shift/core/services/storage" | ||
"github.com/leapfrogtechnology/shift/core/utils/system" | ||
"github.com/leapfrogtechnology/shift/core/utils/system/exit" | ||
|
||
"github.com/leapfrogtechnology/shift/deployment/internals/frontend" | ||
) | ||
|
||
// Run starts deployment for the given environment | ||
func Run(environment string) { | ||
project := storage.Read() | ||
|
||
_, ok := project.Env[environment] | ||
|
||
if !ok { | ||
exit.Error(errors.New("Unknown deployment type "+"'"+environment+"'"), "Error") | ||
} | ||
|
||
slack.Notify(project.SlackURL, | ||
fmt.Sprintf("*There is a new deployment in progress.* \n Project: `%s` \n Environment: `%s` \n Started by: `%s`", | ||
project.Name, environment, system.CurrentUser()), | ||
"#1CA7FB") | ||
|
||
if strings.EqualFold(project.Type, "frontend") { | ||
frontend.Deploy(project, environment) | ||
} | ||
|
||
slack.Notify(project.SlackURL, fmt.Sprintf("*%s* succesfully deployed to *%s*. 🎉 🎉 🎉", project.Name, environment), "#04EBB8") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package destroy | ||
|
||
import ( | ||
"errors" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/leapfrogtechnology/shift/core/services/storage" | ||
"github.com/leapfrogtechnology/shift/core/utils/file" | ||
"github.com/leapfrogtechnology/shift/core/utils/system/exit" | ||
"github.com/leapfrogtechnology/shift/infrastructure/internals/terraform" | ||
) | ||
|
||
func askConfirmation(environment, projectName string) string { | ||
confirmation := "" | ||
prompt := &survey.Input{ | ||
Message: "Are you sure you want to destroy " + environment + " environment from " + projectName + " ?(Y/N): ", | ||
} | ||
survey.AskOne(prompt, &confirmation) | ||
|
||
return confirmation | ||
} | ||
|
||
// Run initializes destruction of infrastructure | ||
func Run(environment string) { | ||
project := storage.Read() | ||
_, env := project.Env[environment] | ||
|
||
if !env { | ||
const message = "Unknown Environment type " | ||
exit.Error(errors.New(message+"'"+environment+"'"), "Error") | ||
} | ||
|
||
confirmation := askConfirmation(environment, project.Name) | ||
|
||
if strings.EqualFold(confirmation, "Y") || strings.EqualFold(confirmation, "yes") { | ||
|
||
workspaceRoot := "/tmp" | ||
workspaceDir := filepath.Join(workspaceRoot, project.Name, project.Type, environment) | ||
terraformFile := workspaceDir + "/infrastructure.tf" | ||
|
||
exists := file.Exists(terraformFile) | ||
|
||
if exists { | ||
terraform.DestroyInfrastructure(workspaceDir) | ||
} else { | ||
terraform.MakeTempAndDestroy(project, environment, workspaceDir) | ||
} | ||
|
||
} else { | ||
const message = "Operation aborted" | ||
exit.Error(errors.New(message), "Cancelled") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package env | ||
|
||
import ( | ||
"github.com/AlecAivazis/survey/v2" | ||
|
||
"github.com/leapfrogtechnology/shift/cli/internals/deploy" | ||
|
||
"github.com/leapfrogtechnology/shift/core/services/storage" | ||
"github.com/leapfrogtechnology/shift/core/structs" | ||
"github.com/leapfrogtechnology/shift/core/utils/logger" | ||
"github.com/leapfrogtechnology/shift/infrastructure/internals/initialize" | ||
) | ||
|
||
func askEnvironmentName() string { | ||
environment := "" | ||
prompt := &survey.Input{ | ||
Message: "Environment Name (eg: dev): ", | ||
} | ||
survey.AskOne(prompt, &environment) | ||
|
||
return environment | ||
} | ||
|
||
// Run initializes new environment. | ||
func Run() { | ||
project := storage.Read() | ||
environment := askEnvironmentName() | ||
|
||
infraInfo := initialize.Run(project, environment) | ||
|
||
project.Env[environment] = structs.Env{ | ||
Bucket: infraInfo.Bucket, | ||
} | ||
|
||
storage.Save(project) | ||
|
||
deploy.Run(environment) | ||
|
||
logger.Info("Project Deployed At: " + infraInfo.URL) | ||
logger.Info("⏳ Stay put. It might take some time for the changes to be reflected. ⏳") | ||
} |
Oops, something went wrong.