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
6 changes: 2 additions & 4 deletions cli/cmd/deploy.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package cmd

import (
"github.com/leapfrogtechnology/shift/cli/internal/deploy"
)
// "github.com/leapfrogtechnology/shift/cli/internal/deploy"

// Deploy triggers deployment for provided project.
func Deploy(project string, deployment string) {
deploy.Run(project, deployment)
// deploy.Run(project, deployment)
}
13 changes: 10 additions & 3 deletions cli/internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package setup
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/AlecAivazis/survey/v2"
)
Expand Down Expand Up @@ -201,11 +203,16 @@ func Run() {
},
}

projectRequestJSON, _ := json.Marshal(projectRequest)
// projectRequestJSON, _ := json.Marshal(projectRequest)

fmt.Println(string(projectRequestJSON))
// fmt.Println(string(projectRequestJSON))

// 1. Save json code here.
jsonData, _ := json.MarshalIndent(projectRequest, "", " ")

currentDir, _ := os.Getwd()
fileName := currentDir + "/shift.json"

_ = ioutil.WriteFile(fileName, jsonData, 0644)

// 2. Run infrastructre code here and save to JSON again

Expand Down
32 changes: 0 additions & 32 deletions infrastructure/infrastructure/infrastrucutre.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,5 @@ func InitializeBackend(ClientArgs []byte) (string, error) {
}
logger.LogOutput(string(out))

// Deployment

//runErr := backend.Deploy(out)
//if runErr != nil {
// logger.LogError(runErr, "Could not Deploy the changes")
//} else {
// logger.LogOutput("Successfully deployed")
//}
//s := spinner.New(spinner.CharSets[11], 100*time.Millisecond) // Build our new spinner
//s.Prefix = " "
//s.Suffix = " Deploying"
//_ = s.Color("cyan", "bold")
//s.Start()
//region := "us-east-1"
//cloneUrl := "https://" + result.Deployment.GitToken + "@" + result.Deployment.CloneUrl[8:]
//command := fmt.Sprintf("rm -rf code && git clone %s code && $(AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s aws ecr get-login --no-include-email --region %s) && docker build/%s code -t %s && docker push %s && terraform apply -var repo_url=%s -var port=%s --auto-approve", cloneUrl, result.Deployment.AccessKey, result.Deployment.SecretKey, region, result.Deployment.DockerFilePath,result.Data.RepoUrl.Value, result.Data.RepoUrl.Value, result.Data.RepoUrl.Value, result.Deployment.Port)
//logger.LogInfo(command)
//cmd := exec.Command("bash", "-c", command)
//cmd.Dir = workspaceDir
//var stdout bytes.Buffer
//var stderr bytes.Buffer
//cmd.Stdout = &stdout
//cmd.Stderr = &stderr
//runError := cmd.Run()
//if runError != nil {
// logger.LogError(runError, stderr.String())
// s.Stop()
//} else {
// logger.LogOutput(stdout.String())
// s.Stop()
//}

return string(out), err
}
39 changes: 10 additions & 29 deletions infrastructure/internals/initialize.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
package internals

import (
"github.com/leapfrogtechnology/shift/core/services/mq"
"errors"
"github.com/leapfrogtechnology/shift/core/utils/logger"
"github.com/leapfrogtechnology/shift/infrastructure/infrastructure"
"github.com/streadway/amqp"
"log"
)

func Initialize() {
conn, err := amqp.Dial(mq.GenerateQueueUrl())
logger.FailOnError(err, "Failed to Connect to Message Queue")
defer conn.Close()
ch, err := conn.Channel()
logger.FailOnError(err, "Failed to open a channel")
defer ch.Close()
messages := mq.Consume(ch, "Infrastructure")
forever := make(chan bool)
go func() {
for message := range messages {
log.Printf("Received a message: %s", message.MessageId)
infrastructureInfo, err := infrastrucuture.Initialize(message.Body)
if err != nil {
logger.LogError(err, "Cannot Init Infrastructure")
} else {
logger.LogOutput(infrastructureInfo)
err = mq.Publish([]byte(infrastructureInfo), ch, "Deployment")
if err != nil {
logger.LogError(err, "Cannot Publish Output")
}
}
}
}()
logger.LogInfo("[*] Waiting for messages. To exit Press Ctrl+C")
<-forever
func Initialize(details string) (string, error) {
infrastructureInfo, err := infrastrucuture.Initialize([]byte(details))
if err != nil {
logger.LogError(err, "Cannot Init Infrastructure")
return "", errors.New("issue Initializing the infrastructure")
} else {
logger.LogOutput(infrastructureInfo)
return infrastructureInfo, nil
}
}
20 changes: 16 additions & 4 deletions infrastructure/shift-infrastructure.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package main
package infrastructure

import "github.com/leapfrogtechnology/shift/infrastructure/internals"
import (
"errors"
"github.com/leapfrogtechnology/shift/core/utils/logger"
"github.com/leapfrogtechnology/shift/infrastructure/internals"
"github.com/leapfrogtechnology/shift/infrastructure/utils"
)

func main() {
internals.Initialize()
func Initialize(details string) (string, error) {
if !utils.CommandExists("terraform") {
logger.FailOnError(errors.New("terraform does not exist"), "Please install terraform on your device")
}
infrastructureInfo, err := internals.Initialize(details)
if err != nil {
logger.FailOnError(err, "Failed to Init Infrastructure")
}
return infrastructureInfo, err
}
8 changes: 8 additions & 0 deletions infrastructure/utils/command-exists.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package utils

import "os/exec"

func CommandExists(command string) bool {
_, err := exec.LookPath(command)
return err == nil
}