-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from codefresh-io/original_yaml_string-preserv…
…e-keys-order preserve keys order for original_yaml_string
- Loading branch information
Showing
8 changed files
with
175 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
terraform-provider-codefresh | ||
dist/ | ||
.vscode/ | ||
|
||
**/.terraform | ||
**/terraform.tfstate | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package codefresh | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// can be used instead the yaml.MapSlice (as an argument to yaml.Unmarshal) in order to preserve the keys order when converting to JSON later | ||
// | ||
// // Usage example: | ||
// ms := OrderedMapSlice{} | ||
// yaml.Unmarshal([]byte(originalYamlString), &ms) | ||
// orderedJson, _ := json.Marshal(ms) | ||
// | ||
// implements json.Marshaler interface | ||
type OrderedMapSlice []yaml.MapItem | ||
|
||
func (ms OrderedMapSlice) MarshalJSON() ([]byte, error) { | ||
// keep the order of keys while converting to json with json.Marshal(ms) | ||
|
||
buf := &bytes.Buffer{} | ||
buf.Write([]byte{'{'}) | ||
for i, mi := range ms { | ||
b, err := json.Marshal(&mi.Value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
buf.WriteString(fmt.Sprintf("%q:", fmt.Sprintf("%v", mi.Key))) | ||
buf.Write(b) | ||
if i < len(ms)-1 { | ||
buf.Write([]byte{','}) | ||
} | ||
} | ||
buf.Write([]byte{'}'}) | ||
return buf.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
provider "codefresh" { | ||
api_url = var.api_url | ||
token = var.token | ||
} | ||
|
||
resource "codefresh_project" "test" { | ||
name = "myproject" | ||
|
||
tags = [ | ||
"docker", | ||
] | ||
} | ||
|
||
resource "codefresh_pipeline" "test" { | ||
name = "${codefresh_project.test.name}/react-sample-app" | ||
|
||
tags = [ | ||
"production", | ||
"docker", | ||
] | ||
|
||
original_yaml_string = <<EOT | ||
version: "1.0" | ||
hooks: | ||
on_finish: | ||
steps: | ||
b: | ||
image: alpine:3.9 | ||
commands: | ||
- echo "echo cleanup step" | ||
a: | ||
image: cloudposse/slack-notifier | ||
commands: | ||
- echo "Notify slack" | ||
steps: | ||
freestyle: | ||
image: alpine | ||
commands: | ||
- sleep 10 | ||
a_freestyle: | ||
image: alpine | ||
commands: | ||
- sleep 10 | ||
- echo Hey! | ||
arguments: | ||
c: 3 | ||
a: 1 | ||
b: 2 | ||
EOT | ||
|
||
spec { | ||
concurrency = 1 | ||
priority = 5 | ||
|
||
# spec_template { | ||
# repo = "codefresh-contrib/react-sample-app" | ||
# path = "./codefresh.yml" | ||
# revision = "master" | ||
# context = "git" | ||
# } | ||
|
||
contexts = [ | ||
"context1-name", | ||
"context2-name", | ||
] | ||
|
||
trigger { | ||
branch_regex = "/.*/gi" | ||
context = "git" | ||
description = "Trigger for commits" | ||
disabled = false | ||
events = [ | ||
"push.heads" | ||
] | ||
modified_files_glob = "" | ||
name = "commits" | ||
provider = "github" | ||
repo = "codefresh-contrib/react-sample-app" | ||
type = "git" | ||
} | ||
|
||
trigger { | ||
branch_regex = "/.*/gi" | ||
context = "git" | ||
description = "Trigger for tags" | ||
disabled = false | ||
events = [ | ||
"push.tags" | ||
] | ||
modified_files_glob = "" | ||
name = "tags" | ||
provider = "github" | ||
repo = "codefresh-contrib/react-sample-app" | ||
type = "git" | ||
} | ||
|
||
variables = { | ||
MY_PIP_VAR = "value" | ||
ANOTHER_PIP_VAR = "another_value" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
api_url = "http://g.codefresh.io/api" | ||
token = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
variable api_url { | ||
type = string | ||
} | ||
|
||
variable token { | ||
type = string | ||
default = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters