Skip to content

Commit

Permalink
added github actions to CI and terraform generator
Browse files Browse the repository at this point in the history
  • Loading branch information
zthomas committed Nov 9, 2019
1 parent 83a1374 commit 63287b0
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cmd/generate.go
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/commitdev/commit0/internal/generate/kubernetes"
"github.com/commitdev/commit0/internal/generate/proto"
"github.com/commitdev/commit0/internal/generate/react"
"github.com/commitdev/commit0/internal/generate/terraform"
"github.com/commitdev/commit0/internal/templator"
"github.com/commitdev/commit0/internal/util"
"github.com/gobuffalo/packr/v2"
Expand Down Expand Up @@ -70,6 +71,12 @@ var generateCmd = &cobra.Command{
kubernetes.Generate(t, cfg, &wg)
}

// TODO we'll need to completely revamp the templating system eventually
if cfg.Infrastructure.AWS.Cognito.Deploy == true {
log.Println(aurora.Cyan(emoji.Sprintf("Generating Terraform")))
terraform.Generate(t, cfg, &wg)
}

// @TODO : This strucuture probably needs to be adjusted. Probably too generic.
switch cfg.Frontend.Framework {
case React:
Expand Down
5 changes: 5 additions & 0 deletions internal/config/config.go
Expand Up @@ -77,13 +77,18 @@ type aws struct {
AccountId string `yaml:"accountId"`
Region string
EKS eks
Cognito cognito
}

type eks struct {
ClusterName string `yaml:"clusterName"`
Deploy bool
}

type cognito struct {
Deploy bool
}

func LoadConfig(filePath string) *Commit0Config {
config := &Commit0Config{}
data, err := ioutil.ReadFile(filePath)
Expand Down
4 changes: 4 additions & 0 deletions internal/generate/ci/generate.go
Expand Up @@ -46,6 +46,10 @@ func Generate(t *templator.CITemplator, cfg *config.Commit0Config, ciConfig conf
ciConfigPath = basePath
ciFilename = ".travis.yml"
ciTemp = t.TravisCI
case "github":
ciConfigPath = fmt.Sprintf("%s/%s", basePath, ".github/")
ciFilename = "config.yml"
ciTemp = t.CircleCI
default:
return &CIGenerationError{"Unsupported CI System", ciConfig}
}
Expand Down
14 changes: 14 additions & 0 deletions internal/generate/terraform/generate.go
@@ -0,0 +1,14 @@
package terraform

import (
"sync"

"github.com/commitdev/commit0/internal/config"
"github.com/commitdev/commit0/internal/templator"
)

func Generate(t *templator.Templator, cfg *config.Commit0Config, wg *sync.WaitGroup) {
data := templator.GenericTemplateData{*cfg}

t.Terraform.TemplateFiles(data, false, wg)
}
8 changes: 8 additions & 0 deletions internal/templator/templator.go
Expand Up @@ -15,6 +15,7 @@ type CITemplator struct {
CircleCI *template.Template
TravisCI *template.Template
Jenkins *template.Template
Github *template.Template
}

// DockerTemplator contains the templates relevent to docker
Expand Down Expand Up @@ -48,6 +49,7 @@ type Templator struct {
React *DirectoryTemplator
Kubernetes *DirectoryTemplator
CI *CITemplator
Terraform *DirectoryTemplator
}

func NewTemplator(box *packr.Box) *Templator {
Expand All @@ -61,6 +63,7 @@ func NewTemplator(box *packr.Box) *Templator {
Readme: NewSingleFileTemplator(box, "util/README.tmpl"),
Docker: NewDockerFileTemplator(box),
React: NewEJSDirectoryTemplator(box, "react"),
Terraform: NewEJSDirectoryTemplator(box, "terraform"),
Kubernetes: NewDirectoryTemplator(box, "kubernetes"),
CI: NewCITemplator(box),
}
Expand Down Expand Up @@ -114,10 +117,15 @@ func NewCITemplator(box *packr.Box) *CITemplator {
jenkinsTemplateSource, _ := box.FindString("ci/Jenkinsfile.tmpl")
jenkinsTemplate, _ := template.New("CIConfig").Parse(jenkinsTemplateSource)

githubTemplateSource, _ := box.FindString("ci/github.tmpl")
// Github also uses double curly braces for their templates
githubTemplate, _ := template.New("CIConfig").Delims("<%=", "%>").Parse(githubTemplateSource)

return &CITemplator{
CircleCI: circleciTemplate,
TravisCI: travisciTemplate,
Jenkins: jenkinsTemplate,
Github: githubTemplate,
}
}

Expand Down
29 changes: 29 additions & 0 deletions templates/ci/github.tmpl
@@ -0,0 +1,29 @@
name: Build and Deploy

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

# https://github.com/marketplace/actions/setup-node-js-for-use-with-actions
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '12.x'

- run: npm install

- run: npm test

- run: npm run build

- name: upload build artifacts
uses: actions/upload-artifact@v1
with:
name: build
path: build
1 change: 0 additions & 1 deletion templates/commit0/commit0.tmpl
Expand Up @@ -17,7 +17,6 @@ frontend:
framework: react
ci:
system: circleci
buildTag: 1234
app:
name: {{.}}

Expand Down
3 changes: 3 additions & 0 deletions templates/terraform/main.tf
@@ -0,0 +1,3 @@
provider "aws" {

}

0 comments on commit 63287b0

Please sign in to comment.