Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

# Built Go Packages
shift
shift-infrastructure
deploy

# Configfiles
config.json
Expand Down
18 changes: 15 additions & 3 deletions cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@ func Initialize(info *Info) error {
cli.Command{
Name: "deploy",
Action: func(ctx *cli.Context) error {
project := ctx.Args().Get(0)
deployment := ctx.Args().Get(1)
environment := ctx.Args().Get(0)

Deploy(project, deployment)
Deploy(environment)

return nil
},
},
cli.Command{
Name: "add",
Subcommands: []cli.Command{
{
Name: "env",
Action: func(ctx *cli.Context) error {
AddEnv()

return nil
},
},
},
},
}

return app.Run(os.Args)
Expand Down
10 changes: 6 additions & 4 deletions cli/cmd/deploy.go
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)
}
10 changes: 10 additions & 0 deletions cli/cmd/env.go
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()
}
36 changes: 36 additions & 0 deletions cli/internals/deploy/deploy.go
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")
}
41 changes: 41 additions & 0 deletions cli/internals/env/env.go
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. ⏳")
}
17 changes: 16 additions & 1 deletion cli/internals/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"fmt"

"github.com/AlecAivazis/survey/v2"
"github.com/leapfrogtechnology/shift/core/platforms/aws"
"github.com/leapfrogtechnology/shift/cli/internals/deploy"
"github.com/leapfrogtechnology/shift/core/services/platforms/aws"
"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"
)

type projectDetails struct {
Expand Down Expand Up @@ -200,6 +203,18 @@ func Run() {
storage.Save(projectRequest)

// 2. Run infrastructre code and save to JSON again with updated information.
infraInfo := initialize.Run(projectRequest, deploymentDetails.Environment)

// 3. Save Infrastructure details to shift.json.
projectRequest.Env[deploymentDetails.Environment] = structs.Env{
Bucket: infraInfo.Bucket,
}

storage.Save(projectRequest)

// 3. Deploy to created infrastructure.
deploy.Run(deploymentDetails.Environment)

logger.Info("Project Deployed At: " + infraInfo.URL)
logger.Info("⏳ Stay put. It might take some time for the changes to be reflected. ⏳")
}
31 changes: 31 additions & 0 deletions core/services/platforms/aws/aws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package aws

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
)

func failOnError(err error, msg string) {
if err != nil {
panic(fmt.Sprintf("%s: %s", msg, err))
}
}

// GetSession returns Session for AWS.
func GetSession(profile string, region string) *session.Session {
sess, err := session.NewSessionWithOptions(session.Options{
Profile: profile,
SharedConfigState: session.SharedConfigEnable,
Config: aws.Config{
Region: aws.String(region),
},
})

if err != nil {
failOnError(err, "Couldnot connect to AWS.")
}

return sess
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"sort"
"strings"

"github.com/leapfrogtechnology/shift/utils/system/exit"
"github.com/leapfrogtechnology/shift/core/utils/system/exit"
)

func handle(err error) {
if err != nil {
exit.Error(err)
exit.Error(err, "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/leapfrogtechnology/shift/deployment/utils/http"
"github.com/leapfrogtechnology/shift/core/utils/http"
)

// Notify sends data to slack webhook url
Expand Down
6 changes: 6 additions & 0 deletions core/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ type Project struct {
HealthCheckPath string `json:"healthCheckPath"`
Env map[string]Env `json:"env"`
}

// Frontend defined the output for frontend infrastructure
type Frontend struct {
Bucket string `json:"bucket"`
URL string `json:"url"`
}
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions core/utils/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ func LogOutput(msg string) {
func LogInfo(msg string) {
log.Println(aurora.Blue(msg))
}

// Log logs msg with default color.
func Log(msg string) {
log.Println(msg)
}

// Success logs msg with green color.
func Success(msg string) {
log.Println(aurora.Green(msg))
}

// Info logs msg with blue color.
func Info(msg string) {
log.Println(aurora.Cyan(msg))
}

// Error logs msg with Red color.
func Error(err error, msg string) {
log.Printf("%s: %s", aurora.Red(msg), aurora.Red(err))
}
File renamed without changes.
14 changes: 14 additions & 0 deletions core/utils/system/exit/exit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package exit

import (
"os"

"github.com/leapfrogtechnology/shift/core/utils/logger"
)

// Error exits the application by showing the given message.
func Error(err error, msg string) {
logger.Error(err, msg)

os.Exit(1)
}
10 changes: 10 additions & 0 deletions core/utils/system/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package system

import "os/user"

// CurrentUser gives the username of the current user.
func CurrentUser() string {
user, _ := user.Current()

return user.Username
}
Empty file removed deployment/.gitkeep
Empty file.
Loading