Skip to content

Commit

Permalink
manage default builspecs if not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
cplee committed Mar 8, 2017
1 parent 08e7ac2 commit 0bf728d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Refer to the wiki for complete details on the configuration of `mu.yml` and the
* **[Environments](https://github.com/stelligent/mu/wiki/Environments)** - managing VPCs, ECS clusters, container instances and ALBs
* **[Services](https://github.com/stelligent/mu/wiki/Services)** - managing ECS service configuration
* **[Pipelines](https://github.com/stelligent/mu/wiki/Pipelines)** - managing continuous delivery pipelines
* **[CLI](https://github.com/stelligent/mu/wiki/CLI)** - details about using the CLI
* **[Custom CloudFormation](https://github.com/stelligent/mu/wiki/Custom-CloudFormation)** - details about customizing the CloudFormation that is generated by mu.

# Contributing

Expand Down
27 changes: 25 additions & 2 deletions templates/assets.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions templates/assets/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 0.1

phases:
build:
commands:
- echo '...replace with real build commands...'

artifacts:
files:
- '**/*'

7 changes: 5 additions & 2 deletions templates/assets/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Parameters:
Type: String
Default: "mu-linux-amd64"
Description: The name of the mu file to download to install
DefaultBuildspec:
Type: String
Description: The default buildspec to use
MuFile:
Type: String
Description: Path to mu.yml, relative to GitHubRepo
Expand Down Expand Up @@ -206,7 +209,7 @@ Resources:
- mu -c ${MuFile} env up ${TestEnv} || echo "Skipping update of environment"
- mu -c ${MuFile} svc deploy ${TestEnv} -t latest
- mu env show ${TestEnv} -f json > env.json
- mv buildspec-test.yml buildspec.yml || echo "version: 0.1\nphases:\nartifacts:\n files:\n - '**/*'\n" > buildspec.yml
- mv buildspec-test.yml buildspec.yml || echo "${DefaultBuildspec}" > buildspec.yml
artifacts:
files:
- '**/*'
Expand Down Expand Up @@ -252,7 +255,7 @@ Resources:
- mu -c ${MuFile} env up ${ProdEnv} || echo "Skipping update of environment"
- mu -c ${MuFile} svc deploy ${ProdEnv} -t latest
- mu env show ${ProdEnv} -f json > env.json
- mv buildspec-prod.yml buildspec.yml || echo "version: 0.1\nphases:\nartifacts:\n files:\n - '**/*'\n" > buildspec.yml
- mv buildspec-prod.yml buildspec.yml || echo "${DefaultBuildspec}" > buildspec.yml
artifacts:
files:
- '**/*'
Expand Down
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from 0a0bc7 to 488fcf
25 changes: 24 additions & 1 deletion workflows/config_init.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package workflows

import (
"bytes"
"fmt"
"github.com/stelligent/mu/common"
"github.com/stelligent/mu/templates"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
Expand All @@ -28,14 +30,20 @@ func (workflow *configWorkflow) configInitialize(config *common.Config, createEn
basedir = config.Basedir
}

// unless force is set, don't overwrite...make sure files don't exist
if forceOverwrite == false {
log.Debugf("Checking for existing config file at %s/mu.yml", basedir)
// don't overwrite...make sure file doesn't exist
if _, err := os.Stat(fmt.Sprintf("%s/mu.yml", basedir)); err == nil {
return fmt.Errorf("Config file already exists - '%s/mu.yml'. Use --force to overwrite", basedir)
}

log.Debugf("Checking for existing buildspec file at %s/buildspec.yml", basedir)
if _, err := os.Stat(fmt.Sprintf("%s/buildspec.yml", basedir)); err == nil {
return fmt.Errorf("buildspec file already exists - '%s/buildspec.yml'. Use --force to overwrite", basedir)
}
}

// write config
config.Service.Port = listenPort
config.Service.Name = config.Repo.Name
config.Service.PathPatterns = []string{"/*"}
Expand All @@ -59,6 +67,21 @@ func (workflow *configWorkflow) configInitialize(config *common.Config, createEn
return err
}

// write buildspec
buildspec, err := templates.NewTemplate("buildspec.yml", nil, nil)
if err != nil {
return err
}
buildspecBytes := new(bytes.Buffer)
buildspecBytes.ReadFrom(buildspec)

log.Noticef("Writing builspec to '%s/buildspec.yml'", basedir)

err = ioutil.WriteFile(fmt.Sprintf("%s/buildspec.yml", basedir), buildspecBytes.Bytes(), 0600)
if err != nil {
return err
}

return nil
}
}
10 changes: 10 additions & 0 deletions workflows/pipeline_upsert.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package workflows

import (
"bytes"
"fmt"
"github.com/stelligent/mu/common"
"github.com/stelligent/mu/templates"
Expand Down Expand Up @@ -103,6 +104,15 @@ func (workflow *pipelineWorkflow) pipelineUpserter(tokenProvider func(bool) stri
pipelineParams["MuDownloadBaseurl"] = workflow.pipelineConfig.MuBaseurl
}

// get default buildspec
buildspec, err := templates.NewTemplate("buildspec.yml", nil, nil)
if err != nil {
return err
}
buildspecBytes := new(bytes.Buffer)
buildspecBytes.ReadFrom(buildspec)
pipelineParams["DefaultBuildspec"] = buildspecBytes.String()

version := workflow.pipelineConfig.MuVersion
if version == "" {
version = common.GetVersion()
Expand Down

0 comments on commit 0bf728d

Please sign in to comment.