-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: always add tile source revision and kiln version to kiln_metada…
…ta in product template
- Loading branch information
Showing
16 changed files
with
482 additions
and
16 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
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
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 |
---|---|---|
|
@@ -12,3 +12,4 @@ stemcell_criteria: | |
version: 250.21 | ||
requires_cpi: false | ||
enable_patch_security_updates: true | ||
kiln_metadata: {} |
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
Submodule hello-tile
updated
17 files
+2 −0 | .gitattributes | |
+26 −0 | .github/tasks/bake.sh | |
+3 −19 | .github/workflows/release.yml | |
+25 −0 | .github/workflows/test.yml | |
+3 −0 | .gitignore | |
+14 −1 | README.md | |
+11 −8 | base.yml | |
+17 −0 | go.mod | |
+457 −0 | go.sum | |
+33 −33 | instance_groups/hello-server.yml | |
+1 −2 | jobs/bpm.yml | |
+1 −2 | jobs/hello-server.yml | |
+5 −0 | properties/hello.yml | |
+22 −0 | test/manifest/base_config.yml | |
+121 −0 | test/manifest/manifest_test.go | |
+3 −0 | variables/hello.yml | |
+1 −1 | version |
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,54 @@ | ||
package builder | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/crhntr/yamlutil/yamlnode" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type KilnMetadata struct { | ||
MetadataGitSHA string `yaml:"metadata_git_sha,omitempty"` | ||
KilnVersion string `yaml:"kiln_version,omitempty"` | ||
} | ||
|
||
func setKilnMetadata(in []byte, kilnMetadata KilnMetadata) ([]byte, error) { | ||
var productTemplate yaml.Node | ||
err := yaml.Unmarshal(in, &productTemplate) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse product template: %w", err) | ||
} | ||
|
||
_, hasMetadataVersionKey := yamlnode.LookupKey(&productTemplate, "metadata_version") | ||
if !hasMetadataVersionKey { | ||
return in, nil | ||
} | ||
|
||
kilnMetadataValueNode, fieldExists := yamlnode.LookupKey(&productTemplate, "kiln_metadata") | ||
if fieldExists { | ||
fmt.Println("WARNING: kiln_metadata is not set by kiln please remove it from your product template") | ||
if err := kilnMetadataValueNode.Encode(kilnMetadata); err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
var productTemplatePartial yaml.Node | ||
if err := productTemplatePartial.Encode(struct { | ||
KilnMetadata KilnMetadata `yaml:"kiln_metadata"` | ||
}{ | ||
KilnMetadata: kilnMetadata, | ||
}); err != nil { | ||
return nil, fmt.Errorf("failed to encode kiln_metadata: %w", err) | ||
} | ||
productTemplate.Content[0].Content = append(productTemplate.Content[0].Content, productTemplatePartial.Content...) | ||
} | ||
|
||
var buf bytes.Buffer | ||
enc := yaml.NewEncoder(&buf) | ||
enc.SetIndent(2) | ||
err = enc.Encode(productTemplate.Content[0]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to encode product template: %w", err) | ||
} | ||
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,31 @@ | ||
package builder | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_setKilnMetadata(t *testing.T) { | ||
for _, tt := range []struct{ Name string }{ | ||
{Name: "append_kiln_metadata"}, | ||
{Name: "replace_kiln_metadata"}, | ||
} { | ||
t.Run(tt.Name, func(t *testing.T) { | ||
inputMetadataYML, err := os.ReadFile(filepath.Join("testdata", tt.Name, "input_metadata.yml")) | ||
require.NoError(t, err) | ||
outputMetadataYML, err := os.ReadFile(filepath.Join("testdata", tt.Name, "output_metadata.yml")) | ||
require.NoError(t, err) | ||
|
||
result, err := setKilnMetadata(inputMetadataYML, KilnMetadata{ | ||
MetadataGitSHA: "some-commit-sha", | ||
KilnVersion: "some-kiln-version", | ||
}) | ||
require.NoError(t, err) | ||
assert.Equal(t, string(outputMetadataYML), string(result)) | ||
}) | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
internal/builder/testdata/append_kiln_metadata/input_metadata.yml
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,83 @@ | ||
description: Serves a "Hello World" server. | ||
icon_image: some-image | ||
form_types: [] | ||
job_types: | ||
- description: HTTP Server | ||
dynamic_ip: 0 | ||
instance_definition: | ||
configurable: true | ||
constraints: | ||
max: 1 | ||
min: 0 | ||
default: 1 | ||
label: Instances | ||
name: instances | ||
type: integer | ||
label: Server | ||
max_in_flight: 1 | ||
name: hello-server | ||
resource_definitions: | ||
- configurable: true | ||
constraints: | ||
min: 1024 | ||
default: 1024 | ||
label: RAM | ||
name: ram | ||
type: integer | ||
- configurable: true | ||
constraints: | ||
min: 2000 | ||
default: 4000 | ||
label: Ephemeral Disk | ||
name: ephemeral_disk | ||
type: integer | ||
- configurable: false | ||
constraints: | ||
min: 2000 | ||
default: 4000 | ||
label: Persistent Disk | ||
name: persistent_disk | ||
type: integer | ||
- configurable: true | ||
constraints: | ||
min: 1 | ||
default: 1 | ||
label: CPU | ||
name: cpu | ||
type: integer | ||
resource_label: Server | ||
single_az_only: true | ||
static_ip: 1 | ||
templates: | ||
- manifest: | | ||
job-properties: | ||
port: 8080 | ||
name: hello-server | ||
release: hello-release | ||
- manifest: {} | ||
name: bpm | ||
release: bpm | ||
label: Hello | ||
metadata_version: 2.7.0 | ||
minimum_version_for_upgrade: 0.1.0 | ||
name: hello | ||
product_version: 0.1.2 | ||
property_blueprints: [] | ||
provides_product_versions: | ||
- name: hello | ||
version: 0.1.2 | ||
rank: 90 | ||
releases: | ||
- file: hello-release-v0.1.4-ubuntu-xenial-621.256.tgz | ||
name: hello-release | ||
sha1: c471ac6371eb8fc24508b14d9a49a44f9a5ef98c | ||
version: v0.1.4 | ||
- file: bpm-1.1.18-ubuntu-xenial-621.256.tgz | ||
name: bpm | ||
sha1: 476c516e0644564838c025b165560bb24102fe6f | ||
version: 1.1.18 | ||
runtime_configs: [] | ||
serial: false | ||
stemcell_criteria: | ||
os: ubuntu-xenial | ||
version: "621.256" |
Oops, something went wrong.