Skip to content

Commit

Permalink
Backend Template Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sparshadotel committed Sep 13, 2019
1 parent 9ea6dd2 commit 590c56c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
63 changes: 33 additions & 30 deletions infrastructure/infrastructure/infrastrucutre.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package infrastrucuture

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/briandowns/spinner"
"github.com/leapfrogtechnology/shift/core/utils/logger"
"github.com/leapfrogtechnology/shift/infrastructure/internal/terraform"
backendHaArchitecture "github.com/leapfrogtechnology/shift/infrastructure/internal/terraform/templates/providers/aws/backend-ha-architecture"
frontendArchitecture "github.com/leapfrogtechnology/shift/infrastructure/internal/terraform/templates/providers/aws/frontend-architecture"
"github.com/leapfrogtechnology/shift/infrastructure/internals/terraform"
backendHaArchitecture "github.com/leapfrogtechnology/shift/infrastructure/internals/terraform/templates/providers/aws/backend-ha-architecture"
frontendArchitecture "github.com/leapfrogtechnology/shift/infrastructure/internals/terraform/templates/providers/aws/frontend-architecture"
"github.com/leapfrogtechnology/shift/infrastructure/utils"
"io/ioutil"
"os/exec"
"path/filepath"
"strings"
"time"
)

func Initialize(ClientArgs []byte) (string, error) {
Expand Down Expand Up @@ -119,29 +115,36 @@ func InitializeBackend(ClientArgs []byte) (string, error) {
logger.LogOutput(string(out))

// Deployment
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()
}

//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
}
2 changes: 1 addition & 1 deletion infrastructure/internals/initialize.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package internals

import (
"github.com/leapfrogtechnology/shift/core/services/mq"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ variable "health_check_path" {
variable "repo_name" {
type = "string"
default = "leapfrogtechnology/shift-ui"
{% if info.Client.Deployment.RepoName %}
default = "{{ info.Client.Deployment.RepoName }}"
{% else %}
default = "leapfrogtechnology/shift-ui:latest"
{% endif %}
}
// Provider Initialization
Expand Down Expand Up @@ -368,7 +372,7 @@ resource "aws_iam_role_policy_attachment" "attach-tasks-execution" {
}
variable "container_port" {
default = 80
default = {{ info.Client.Deployment.Port }}
}
data "template_file" "container_definition" {
Expand All @@ -391,7 +395,7 @@ module "fargate" {
fargate_autoscaling_role_arn = aws_iam_role.ECSAutoScalingRole.arn
fargate_task_execution_role_arn = aws_iam_role.ECSTasksExecutionRole.arn
fargate_container_definitions = data.template_file.container_definition.rendered
fargate_container_port = 80
fargate_container_port = var.container_port
fargate_subnets = aws_subnet.private.*.id
vpc_id = aws_vpc.main.id
tags = var.tags
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/shift-infrastructure.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import "github.com/leapfrogtechnology/shift/infrastructure/internal"
import "github.com/leapfrogtechnology/shift/infrastructure/internals"

func main() {
internal.Initialize()
internals.Initialize()
}
1 change: 1 addition & 0 deletions infrastructure/utils/mq-structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type deployment struct {
HealthCheckPath string `json:"healthCheckPath"`
DockerFilePath string `json:"dockerFilePath"`
SlackURL string `json:"slackURL"`
RepoName string `json:"repoName"`
}
type Client struct {
Project string `json:"projectName"`
Expand Down

0 comments on commit 590c56c

Please sign in to comment.