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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ deploy

# Configfiles
config.json
shift.json

# artifacts
artifact
10 changes: 0 additions & 10 deletions cli/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"os"

"github.com/urfave/cli"
Expand All @@ -23,15 +22,6 @@ func Initialize(info *Info) error {
app.Usage = info.Description

app.Commands = []cli.Command{
{
Name: "infrastructure",
Description: "Initialize",
Aliases: nil,
Usage: "Initialize your Application",
Action: func(c *cli.Context) {
fmt.Println("Shift Shift shift")
},
},
cli.Command{
Name: "setup",
Action: func(ctx *cli.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

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

// Setup prompts user for required information for creating a project.
Expand Down
103 changes: 33 additions & 70 deletions cli/internal/setup/setup.go → cli/internals/setup/setup.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package setup

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/AlecAivazis/survey/v2"
"github.com/leapfrogtechnology/shift/cli/internal/config"
"github.com/leapfrogtechnology/shift/core/platforms/aws"
"github.com/leapfrogtechnology/shift/core/services/storage"
"github.com/leapfrogtechnology/shift/core/structs"
)

type projectDetails struct {
ProjectName string
}

type deploymentDetails struct {
DeploymentName string
CloudProvider string
Profile string
Region string
DeploymentType string
Environment string
}

type frontendBuildInformation struct {
BuildCommand string
DistFolder string
DistFolder string
}

type backendBuildInformation struct {
Expand All @@ -33,26 +31,6 @@ type backendBuildInformation struct {
DockerfilePath string
}

type deployment struct {
Name string `json:"name"`
Platform string `json:"platform"`
Profile string `json:"profile"`
Region string `json:"region"`
Type string `json:"type"`
BuildCommand string `json:"buildCommand"`
DistFolder string `json:"distFolder"`
Port string `json:"port"`
HealthCheckPath string `json:"healthCheckPath"`
SlackURL string `json:"slackURL"`
DockerFilePath string `json:"dockerFilePath"`
}

// Project defines the overall structure for a project deployment.
type Project struct {
ProjectName string `json:"projectName"`
Deployment deployment `json:"deployment"`
}

func askProjectDetails() *projectDetails {
questions := []*survey.Question{
{
Expand All @@ -75,12 +53,6 @@ func askProjectDetails() *projectDetails {

func askDeploymentDetails() *deploymentDetails {
questions := []*survey.Question{
{
Name: "deploymentName",
Prompt: &survey.Input{
Message: "Deployment Name:",
},
},
{
Name: "cloudProvider",
Prompt: &survey.Select{
Expand All @@ -92,28 +64,34 @@ func askDeploymentDetails() *deploymentDetails {
Name: "Profile",
Prompt: &survey.Select{
Message: "Chose Aws Profile:",
Options: config.GetProfiles(),
Options: aws.GetProfiles(),
},
},
{
Name: "Region",
Prompt: &survey.Select{
Message: "Region:",
Options: config.GetRegions(),
Options: aws.GetRegions(),
},
},
{
Name: "deploymentType",
Prompt: &survey.Select{
Message: "Choose Deployment Type:",
Message: "Choose Deployment Type: ",
Options: []string{"Frontend", "Backend"},
},
},
{
Name: "environment",
Prompt: &survey.Input{
Message: "Environment name: ",
},
},
}

answers := &deploymentDetails{}
err := survey.Ask(questions, answers)
answers.Region = config.GetRegionCode(answers.Region)
answers.Region = aws.GetRegionCode(answers.Region)

if err != nil {
fmt.Println(err)
Expand All @@ -124,16 +102,10 @@ func askDeploymentDetails() *deploymentDetails {

func askFrontendBuildInformation() *frontendBuildInformation {
questions := []*survey.Question{
{
Name: "buildCommand",
Prompt: &survey.Input{
Message: "Build Command: ",
},
},
{
Name: "distFolder",
Prompt: &survey.Input{
Message: "Distribution Folder: ",
Message: "Build Directory: ",
},
},
}
Expand Down Expand Up @@ -208,35 +180,26 @@ func Run() {

slackEndpoint := askSlackEndpoint()

projectRequest := Project{
ProjectName: projectDetails.ProjectName,
Deployment: deployment{
Name: deploymentDetails.DeploymentName,
Platform: deploymentDetails.CloudProvider,
Profile: deploymentDetails.Profile,
Region: deploymentDetails.Region,
Type: deploymentDetails.DeploymentType,
BuildCommand: frontendBuildInformation.BuildCommand,
DistFolder: frontendBuildInformation.DistFolder,
Port: backendBuildInformation.Port,
HealthCheckPath: backendBuildInformation.HealthCheckPath,
SlackURL: slackEndpoint,
DockerFilePath: backendBuildInformation.DockerfilePath,
projectRequest := structs.Project{
Name: projectDetails.ProjectName,
Platform: deploymentDetails.CloudProvider,
Profile: deploymentDetails.Profile,
Region: deploymentDetails.Region,
Type: deploymentDetails.DeploymentType,
DistDir: frontendBuildInformation.DistFolder,
Port: backendBuildInformation.Port,
HealthCheckPath: backendBuildInformation.HealthCheckPath,
SlackURL: slackEndpoint,
DockerFilePath: backendBuildInformation.DockerfilePath,
Env: map[string]structs.Env{
deploymentDetails.Environment: structs.Env{},
},
}

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

// fmt.Println(string(projectRequestJSON))

jsonData, _ := json.MarshalIndent(projectRequest, "", " ")

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

_ = ioutil.WriteFile(fileName, jsonData, 0644)
// 1. Save project details to shift.json.
storage.Save(projectRequest)

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

// 3. Deploy to infrastructure code here.
// 3. Deploy to created infrastructure.
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package aws

import (
"bufio"
Expand Down
38 changes: 15 additions & 23 deletions core/services/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/leapfrogtechnology/shift/deployment/domain/project"
"github.com/leapfrogtechnology/shift/core/structs"
)

type deployment map[string]project.Response

// Data is stored as shift.json.
type Data map[string]deployment

var saveFilePath = "/var/lib/shift"

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

// Read parses data from shift.json
func Read() Data {
data, err := ioutil.ReadFile(saveFilePath + "/shift.json")
func Read() structs.Project {
currentDir, _ := os.Getwd()
fileName := currentDir + "/shift.json"
data, err := ioutil.ReadFile(fileName)

failOnError(err, "Error reading file.")

jsonData := Data{}
jsonData := structs.Project{}

json.Unmarshal(data, &jsonData)

Expand All @@ -36,18 +33,13 @@ func Read() Data {
}

// Save persists project data in shift.json.
func Save(project project.Response) {
jsonData := Read()

if _, exists := jsonData[project.ProjectName]; exists {
jsonData[project.ProjectName][project.Deployment.Name] = project
} else {
jsonData[project.ProjectName] = deployment{
project.Deployment.Name: project,
}
}
func Save(project structs.Project) {
jsonData, _ := json.MarshalIndent(project, " ", " ")

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

data, _ := json.MarshalIndent(jsonData, "", " ")
error := ioutil.WriteFile(fileName, jsonData, 0644)

ioutil.WriteFile(saveFilePath+"/shift.json", data, 0644)
failOnError(error, "Could not save to file.")
}
22 changes: 22 additions & 0 deletions core/structs/structs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package structs

// Env defines the structure for a single environment
type Env struct {
Bucket string `json:"bucket"`
Cluster string `json:"cluster"`
}

// Project defines the overall structure for a project deployment.
type Project struct {
Name string `json:"name"`
Platform string `json:"platform"`
Profile string `json:"profile"`
Region string `json:"region"`
Type string `json:"type"`
DistDir string `json:"distDir"`
SlackURL string `json:"slackURL"`
Port string `json:"port"`
DockerFilePath string `json:"dockerFilePath"`
HealthCheckPath string `json:"healthCheckPath"`
Env map[string]Env `json:"env"`
}
5 changes: 3 additions & 2 deletions core/utils/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package logger

import (
"github.com/logrusorgru/aurora"
"log"

"github.com/logrusorgru/aurora"
)

func FailOnError(err error, msg string) {
if err != nil {
log.Fatalf("Fatal\n%s: %s",aurora.Red(msg), aurora.Red(err))
log.Fatalf("Fatal\n%s: %s", aurora.Red(msg), aurora.Red(err))
}
}

Expand Down
4 changes: 3 additions & 1 deletion deployment/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ go 1.12
require (
github.com/aws/aws-sdk-go v1.23.13
github.com/briandowns/spinner v1.6.1
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4 // indirect
github.com/gabriel-vasile/mimetype v0.3.18
github.com/go-resty/resty/v2 v2.0.0
github.com/h2non/filetype v1.0.10
github.com/leapfrogtechnology/shift v0.0.0-20191011080539-d37d585f7cf4
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b // indirect
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
)
Loading