From 26951f6794f91a52bedf282899c26fea2d1b5d0b Mon Sep 17 00:00:00 2001 From: David Gamero Date: Fri, 24 Feb 2023 15:36:49 -0500 Subject: [PATCH 1/9] add some binary wrapping info and go package example --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index c53b5f7c..cff6e5dd 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,46 @@ curl -fsSL https://raw.githubusercontent.com/Azure/draft/main/scripts/install.sh * Windows isn't currently supported (you can use WSL) + +## Draft as a Dependency + +If you are looking to leverage Draft's file generation capabilities and templating within another project instead of using the CLI, you have two options: importing the Draft go packages, and wrapping the binary + +### Importing Draft Go Packages +This option will provide the cleanest integration, as it directly builds Draft into your project. However, it requires that your project is written in Go. + +Dockerfiles can be generated using the following methods: +```go +import ( + "github.com/Azure/draft/pkg/languages" + "github.com/Azure/draft/template" + "github.com/Azure/draft/templatewriter" +) + +// generateDockerfile generates a Dockerfile using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +func generateDockerfile(w templatewriter.TemplateWriter,dockerfileOutputPath string, dockerfileInputs map[string]string) error { + l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, dockerfileOutputPath) + generationLanguage := strings.ToLower(properties.GetGenerationLanguage().String()) + err = l.CreateDockerfileForLanguage(generationLanguage, dockerfileInputs, prFileWriter) + if err != nil { + return fmt.Errorf("failed to generate dockerfile: %e", err) + } + return nil +} +``` + +### Wrapping the Binary +For projects written in languages other than Go, or for projects that prefer to not import the packages directly, you can wrap the Draft binary. + +We recommend pinning a specific version of Draft and only updating after reviewing new releases' changelogs, but starting with release v1.0 Draft will no longer be in prerelease, and we will use semver and not introduce breaking changes in minor or patch releases. + +Several features have been implemented to make consuming draft as easy as possible: +- `draft info` prints supported language and field information in json format for easy parsing +- `--dry-run` and `--dry-run-file` flags can be used on the `create` command to generate a summary of the files that would be written to disk, and the variables that would be used in the templates +- `draft update` accepts takes a repeatable `--variable` flag that can be used to set template variables +- `draft create` takes a `--create-config` flag that can be used to input variables through a yaml file instead of interactively + + ## Contributing Draft is fully compatible with [Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/draft). We strongly encourage contributions to make Draft available to other cloud providers 😊! From 0647b22311a275ceff463213af7f6752b9e0fcc4 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Mon, 27 Feb 2023 12:30:27 -0500 Subject: [PATCH 2/9] add consumption patterns to readme --- README.md | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cff6e5dd..81c05787 100644 --- a/README.md +++ b/README.md @@ -182,23 +182,44 @@ This option will provide the cleanest integration, as it directly builds Draft i Dockerfiles can be generated using the following methods: ```go import ( - "github.com/Azure/draft/pkg/languages" + "github.com/Azure/draft/pkg/languages" "github.com/Azure/draft/template" "github.com/Azure/draft/templatewriter" ) -// generateDockerfile generates a Dockerfile using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. -func generateDockerfile(w templatewriter.TemplateWriter,dockerfileOutputPath string, dockerfileInputs map[string]string) error { +// WriteDockerfile generates a Dockerfile using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +func WriteDockerfile(w templatewriter.TemplateWriter,dockerfileOutputPath string, dockerfileInputs map[string]string) error { l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, dockerfileOutputPath) generationLanguage := strings.ToLower(properties.GetGenerationLanguage().String()) - err = l.CreateDockerfileForLanguage(generationLanguage, dockerfileInputs, prFileWriter) + + err := l.CreateDockerfileForLanguage(generationLanguage, dockerfileInputs, prFileWriter) if err != nil { - return fmt.Errorf("failed to generate dockerfile: %e", err) + return fmt.Errorf("failed to generate dockerfile: %e", err) } return nil } ``` +Deployment files can be generated using the following methods: +```go +import ( + "github.com/Azure/draft/pkg/deployments" + "github.com/Azure/draft/template" +) + +// WriteDeploymentFiles generates Deployment Files using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +func WriteDeploymentFiles(properties *devHubTypes.ArtifactGenerationProperties, deploymentOutputPath string, prFileWriter *PRFiles, deploymentInputs map[string]string, deploymentType string) error { + d := deployments.CreateDeploymentsFromEmbedFS(template.Deployments, deploymentOutputPath) + + err = d.CopyDeploymentFiles(deploymentType, deploymentInputs, prFileWriter) + if err != nil { + return fmt.Errorf("failed to generate manifest: %e", err) + } + return nil +} + +``` + ### Wrapping the Binary For projects written in languages other than Go, or for projects that prefer to not import the packages directly, you can wrap the Draft binary. From ee199b46007e2beab15e1f86850a2ab3e67c03e3 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Mon, 27 Feb 2023 14:31:18 -0500 Subject: [PATCH 3/9] add examples package for generation and readme info --- README.md | 42 ++----------------------- examples/deployment.go | 20 ++++++++++++ examples/deployment_test.go | 56 +++++++++++++++++++++++++++++++++ examples/dockerfile.go | 20 ++++++++++++ examples/dockerfile_test.go | 62 +++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 40 deletions(-) create mode 100644 examples/deployment.go create mode 100644 examples/deployment_test.go create mode 100644 examples/dockerfile.go create mode 100644 examples/dockerfile_test.go diff --git a/README.md b/README.md index 81c05787..9999492b 100644 --- a/README.md +++ b/README.md @@ -179,46 +179,9 @@ If you are looking to leverage Draft's file generation capabilities and templati ### Importing Draft Go Packages This option will provide the cleanest integration, as it directly builds Draft into your project. However, it requires that your project is written in Go. -Dockerfiles can be generated using the following methods: -```go -import ( - "github.com/Azure/draft/pkg/languages" - "github.com/Azure/draft/template" - "github.com/Azure/draft/templatewriter" -) - -// WriteDockerfile generates a Dockerfile using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. -func WriteDockerfile(w templatewriter.TemplateWriter,dockerfileOutputPath string, dockerfileInputs map[string]string) error { - l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, dockerfileOutputPath) - generationLanguage := strings.ToLower(properties.GetGenerationLanguage().String()) - - err := l.CreateDockerfileForLanguage(generationLanguage, dockerfileInputs, prFileWriter) - if err != nil { - return fmt.Errorf("failed to generate dockerfile: %e", err) - } - return nil -} -``` - -Deployment files can be generated using the following methods: -```go -import ( - "github.com/Azure/draft/pkg/deployments" - "github.com/Azure/draft/template" -) - -// WriteDeploymentFiles generates Deployment Files using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. -func WriteDeploymentFiles(properties *devHubTypes.ArtifactGenerationProperties, deploymentOutputPath string, prFileWriter *PRFiles, deploymentInputs map[string]string, deploymentType string) error { - d := deployments.CreateDeploymentsFromEmbedFS(template.Deployments, deploymentOutputPath) - - err = d.CopyDeploymentFiles(deploymentType, deploymentInputs, prFileWriter) - if err != nil { - return fmt.Errorf("failed to generate manifest: %e", err) - } - return nil -} +Dockerfiles can be generated following the example in `examples/dockerfile.go` -``` +Deployment files can be generated following the example in `examples/deployment.go` ### Wrapping the Binary For projects written in languages other than Go, or for projects that prefer to not import the packages directly, you can wrap the Draft binary. @@ -231,7 +194,6 @@ Several features have been implemented to make consuming draft as easy as possib - `draft update` accepts takes a repeatable `--variable` flag that can be used to set template variables - `draft create` takes a `--create-config` flag that can be used to input variables through a yaml file instead of interactively - ## Contributing Draft is fully compatible with [Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/draft). We strongly encourage contributions to make Draft available to other cloud providers 😊! diff --git a/examples/deployment.go b/examples/deployment.go new file mode 100644 index 00000000..b5dc26d4 --- /dev/null +++ b/examples/deployment.go @@ -0,0 +1,20 @@ +package examples + +import ( + "fmt" + + "github.com/Azure/draft/pkg/deployments" + "github.com/Azure/draft/pkg/templatewriter" + "github.com/Azure/draft/template" +) + +// WriteDeploymentFiles generates Deployment Files using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +func WriteDeploymentFiles(deploymentOutputPath string, w templatewriter.TemplateWriter, deploymentInputs map[string]string, deploymentType string) error { + d := deployments.CreateDeploymentsFromEmbedFS(template.Deployments, deploymentOutputPath) + + err := d.CopyDeploymentFiles(deploymentType, deploymentInputs, w) + if err != nil { + return fmt.Errorf("failed to generate manifest: %e", err) + } + return nil +} diff --git a/examples/deployment_test.go b/examples/deployment_test.go new file mode 100644 index 00000000..e0efeca7 --- /dev/null +++ b/examples/deployment_test.go @@ -0,0 +1,56 @@ +package examples + +import ( + "fmt" + "testing" + + "github.com/Azure/draft/pkg/templatewriter/writers" +) + +func TestWriteDeploymentFiles(t *testing.T) { + filewriter := writers.FileMapWriter{} + outputPath := "test/path" + + testCases := []struct { + name string + inputVariables map[string]string + deploymentType string + expectError bool + }{ + { + name: "Test Valid Manifests Deployment Generation", + inputVariables: map[string]string{ + "PORT": "8080", + "APPNAME": "testapp", + "SERVICEPORT": "8080", + "NAMESPACE": "testnamespace", + "IMAGENAME": "testimage", + "IMAGETAG": "latest", + }, + deploymentType: "manifests", + expectError: false, + }, + { + name: "Test Invalid Manifests Deployment Generation", + inputVariables: map[string]string{ + "PORT": "8080", + }, + deploymentType: "manifests", + expectError: true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := WriteDeploymentFiles(outputPath, &filewriter, tc.inputVariables, tc.deploymentType) + errored := err != nil + if err != nil { + fmt.Printf("WriteDeploymentFiles failed: %e\n", err) + } + if errored != tc.expectError { + t.Errorf("WriteDeploymentFiles failed: expected error %t, got %t", tc.expectError, errored) + t.Fail() + } + }) + } +} diff --git a/examples/dockerfile.go b/examples/dockerfile.go new file mode 100644 index 00000000..eec334d5 --- /dev/null +++ b/examples/dockerfile.go @@ -0,0 +1,20 @@ +package examples + +import ( + "fmt" + + "github.com/Azure/draft/pkg/languages" + "github.com/Azure/draft/pkg/templatewriter" + "github.com/Azure/draft/template" +) + +// WriteDockerfile generates a Dockerfile using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +func WriteDockerfile(w templatewriter.TemplateWriter, dockerfileOutputPath string, dockerfileInputs map[string]string, generationLanguage string) error { + l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, dockerfileOutputPath) + + err := l.CreateDockerfileForLanguage(generationLanguage, dockerfileInputs, w) + if err != nil { + return fmt.Errorf("failed to generate dockerfile: %e", err) + } + return nil +} diff --git a/examples/dockerfile_test.go b/examples/dockerfile_test.go new file mode 100644 index 00000000..42551cd5 --- /dev/null +++ b/examples/dockerfile_test.go @@ -0,0 +1,62 @@ +package examples + +import ( + "fmt" + "testing" + + "github.com/Azure/draft/pkg/templatewriter/writers" +) + +func TestWriteDockerfile(t *testing.T) { + templateWriter := writers.FileMapWriter{} + outputPath := "test/path" + + testCases := []struct { + name string + inputVariables map[string]string + generationLanguage string + expectError bool + }{ + + { + name: "Test Valid Go Dockerfile Generation", + inputVariables: map[string]string{ + "PORT": "8080", + "VERSION": "1.20", + }, + generationLanguage: "go", + expectError: false, + }, + { + name: "Test Invalid Go Dockerfile Generation", + inputVariables: map[string]string{ + "PORT": "8080", + }, + generationLanguage: "go", + expectError: true, + }, + { + name: "Test Invalid GenerationLanguage", + inputVariables: map[string]string{ + "PORT": "8080", + "VERSION": "1.20", + }, + generationLanguage: "invalid", + expectError: true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := WriteDockerfile(&templateWriter, outputPath, tc.inputVariables, tc.generationLanguage) + errored := err != nil + if err != nil { + fmt.Printf("WriteDockerfile failed: %e\n", err) + } + if errored != tc.expectError { + t.Errorf("WriteDockerfile failed: expected error %t, got %t", tc.expectError, errored) + t.Fail() + } + }) + } +} From ea8ae861d9b7d4071292a890709d55ac4bab9f49 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Mon, 27 Feb 2023 14:35:05 -0500 Subject: [PATCH 4/9] rename package to singular example --- {examples => example}/deployment.go | 2 +- {examples => example}/deployment_test.go | 2 +- {examples => example}/dockerfile.go | 2 +- {examples => example}/dockerfile_test.go | 2 +- pkg/linguist/data/vendor.yml | 2 +- pkg/linguist/static.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename {examples => example}/deployment.go (97%) rename {examples => example}/deployment_test.go (98%) rename {examples => example}/dockerfile.go (97%) rename {examples => example}/dockerfile_test.go (98%) diff --git a/examples/deployment.go b/example/deployment.go similarity index 97% rename from examples/deployment.go rename to example/deployment.go index b5dc26d4..20e64735 100644 --- a/examples/deployment.go +++ b/example/deployment.go @@ -1,4 +1,4 @@ -package examples +package example import ( "fmt" diff --git a/examples/deployment_test.go b/example/deployment_test.go similarity index 98% rename from examples/deployment_test.go rename to example/deployment_test.go index e0efeca7..dcb09de5 100644 --- a/examples/deployment_test.go +++ b/example/deployment_test.go @@ -1,4 +1,4 @@ -package examples +package example import ( "fmt" diff --git a/examples/dockerfile.go b/example/dockerfile.go similarity index 97% rename from examples/dockerfile.go rename to example/dockerfile.go index eec334d5..245a5b7c 100644 --- a/examples/dockerfile.go +++ b/example/dockerfile.go @@ -1,4 +1,4 @@ -package examples +package example import ( "fmt" diff --git a/examples/dockerfile_test.go b/example/dockerfile_test.go similarity index 98% rename from examples/dockerfile_test.go rename to example/dockerfile_test.go index 42551cd5..b5329452 100644 --- a/examples/dockerfile_test.go +++ b/example/dockerfile_test.go @@ -1,4 +1,4 @@ -package examples +package example import ( "fmt" diff --git a/pkg/linguist/data/vendor.yml b/pkg/linguist/data/vendor.yml index 26348732..9f23e4cb 100644 --- a/pkg/linguist/data/vendor.yml +++ b/pkg/linguist/data/vendor.yml @@ -328,7 +328,7 @@ - (^|/)extjs/docs/ - (^|/)extjs/builds/ - (^|/)extjs/cmd/ -- (^|/)extjs/examples/ +- (^|/)extjs/example/ - (^|/)extjs/locale/ - (^|/)extjs/packages/ - (^|/)extjs/plugins/ diff --git a/pkg/linguist/static.go b/pkg/linguist/static.go index 95a882d0..8af3e025 100644 --- a/pkg/linguist/static.go +++ b/pkg/linguist/static.go @@ -7741,7 +7741,7 @@ xBase: - (^|/)extjs/docs/ - (^|/)extjs/builds/ - (^|/)extjs/cmd/ -- (^|/)extjs/examples/ +- (^|/)extjs/example/ - (^|/)extjs/locale/ - (^|/)extjs/packages/ - (^|/)extjs/plugins/ From db01d3a4b7f1e6b8d2e34dd62895b4b876c79edb Mon Sep 17 00:00:00 2001 From: David Gamero Date: Mon, 27 Feb 2023 14:45:27 -0500 Subject: [PATCH 5/9] update text --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 9999492b..7ea8d00f 100644 --- a/README.md +++ b/README.md @@ -186,8 +186,6 @@ Deployment files can be generated following the example in `examples/deployment. ### Wrapping the Binary For projects written in languages other than Go, or for projects that prefer to not import the packages directly, you can wrap the Draft binary. -We recommend pinning a specific version of Draft and only updating after reviewing new releases' changelogs, but starting with release v1.0 Draft will no longer be in prerelease, and we will use semver and not introduce breaking changes in minor or patch releases. - Several features have been implemented to make consuming draft as easy as possible: - `draft info` prints supported language and field information in json format for easy parsing - `--dry-run` and `--dry-run-file` flags can be used on the `create` command to generate a summary of the files that would be written to disk, and the variables that would be used in the templates From 201eff39ad54cb0852938aba01e09747fffddbe9 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Tue, 28 Feb 2023 11:34:47 -0500 Subject: [PATCH 6/9] update dockerfile example with usage call --- example/dockerfile.go | 43 +++++++++++++++++++++++++++++++++++++- example/dockerfile_test.go | 7 +++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/example/dockerfile.go b/example/dockerfile.go index 245a5b7c..346ff9e8 100644 --- a/example/dockerfile.go +++ b/example/dockerfile.go @@ -5,10 +5,11 @@ import ( "github.com/Azure/draft/pkg/languages" "github.com/Azure/draft/pkg/templatewriter" + "github.com/Azure/draft/pkg/templatewriter/writers" "github.com/Azure/draft/template" ) -// WriteDockerfile generates a Dockerfile using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +// WriteDockerfile generates a Dockerfile and dockerignore using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. func WriteDockerfile(w templatewriter.TemplateWriter, dockerfileOutputPath string, dockerfileInputs map[string]string, generationLanguage string) error { l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, dockerfileOutputPath) @@ -18,3 +19,43 @@ func WriteDockerfile(w templatewriter.TemplateWriter, dockerfileOutputPath strin } return nil } + +// WriteDockerfileExample shows how to set up a fileWriter and generate a fileMap using WriteDockerfile +func WriteDockerfileExample() error { + // Create a file map + fileMap := make(map[string][]byte) + + // Create a template writer that writes to the file map + w := writers.FileMapWriter{ + FileMap: fileMap, + } + + // Select the language to generate the Dockerfile for (must correspond to a directory in the template/dockerfiles directory) + generationLanguage := "go" + + // Create a map of inputs to the template (must correspond to the inputs in the template/dockerfiles//draft.yaml file) + dockerfileInputs := map[string]string{ + "PORT": "8080", + "VERSION": "1.20", + } + + // Set the output path for the Dockerfile + outputPath := "./" + + // Write the Dockerfile + err := WriteDockerfile(&w, outputPath, dockerfileInputs, generationLanguage) + if err != nil { + return err + } + + // Read written files from the file map + fmt.Printf("Files written in WriteDockerfileExample:\n") + for filePath, fileContents := range fileMap { + if fileContents == nil { + return fmt.Errorf("file contents for %s is nil", filePath) + } + fmt.Printf(" %s\n", filePath) // Print the file path + } + + return nil +} diff --git a/example/dockerfile_test.go b/example/dockerfile_test.go index b5329452..624f9952 100644 --- a/example/dockerfile_test.go +++ b/example/dockerfile_test.go @@ -60,3 +60,10 @@ func TestWriteDockerfile(t *testing.T) { }) } } + +func TestWriteDockerfileExample(t *testing.T) { + err := WriteDockerfileExample() + if err != nil { + t.Errorf("WriteDockerfileExample failed: %e", err) + } +} From eb044c81e4cf68debd928f2307feed1f91bb6932 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Fri, 3 Mar 2023 15:58:59 -0500 Subject: [PATCH 7/9] deployment examples --- example/deployment.go | 47 +++++++++++++++++++++++++++++++++++++- example/deployment_test.go | 2 +- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/example/deployment.go b/example/deployment.go index 20e64735..ffc2ed34 100644 --- a/example/deployment.go +++ b/example/deployment.go @@ -5,11 +5,12 @@ import ( "github.com/Azure/draft/pkg/deployments" "github.com/Azure/draft/pkg/templatewriter" + "github.com/Azure/draft/pkg/templatewriter/writers" "github.com/Azure/draft/template" ) // WriteDeploymentFiles generates Deployment Files using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. -func WriteDeploymentFiles(deploymentOutputPath string, w templatewriter.TemplateWriter, deploymentInputs map[string]string, deploymentType string) error { +func WriteDeploymentFiles(w templatewriter.TemplateWriter, deploymentOutputPath string, deploymentInputs map[string]string, deploymentType string) error { d := deployments.CreateDeploymentsFromEmbedFS(template.Deployments, deploymentOutputPath) err := d.CopyDeploymentFiles(deploymentType, deploymentInputs, w) @@ -18,3 +19,47 @@ func WriteDeploymentFiles(deploymentOutputPath string, w templatewriter.Template } return nil } + +// WriteDeploymentFilesExample shows how to set up a fileWriter and generate a fileMap using WriteDeploymentFiles +func WriteDeploymentFilesExample() error { + // Create a file map + fileMap := make(map[string][]byte) + + // Create a template writer that writes to the file map + w := writers.FileMapWriter{ + FileMap: fileMap, + } + + // Select the deployment type to generate the files for (must correspond to a directory in the template/deployments directory) + deploymentType := "manifests" + + // Create a map of inputs to the template (must correspond to the inputs in the template/deployments//draft.yaml file) + deploymentInputs := map[string]string{ + "PORT": "8080", + "APPNAME": "example-app", + "SERVICEPORT": "8080", + "NAMESPACE": "example-namespace", + "IMAGENAME": "example-image", + "IMAGETAG": "latest", + } + + // Set the output path for the deployment files + outputPath := "./" + + // Write the deployment files + err := WriteDeploymentFiles(&w, outputPath, deploymentInputs, deploymentType) + if err != nil { + return err + } + + // Read written files from the file map + fmt.Printf("Files written in WriteDeploymentFilesExample:\n") + for filePath, fileContents := range fileMap { + if fileContents == nil { + return fmt.Errorf("file contents for %s is nil", filePath) + } + fmt.Printf(" %s\n", filePath) // Print the file path + } + + return nil +} diff --git a/example/deployment_test.go b/example/deployment_test.go index dcb09de5..af24ebec 100644 --- a/example/deployment_test.go +++ b/example/deployment_test.go @@ -42,7 +42,7 @@ func TestWriteDeploymentFiles(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - err := WriteDeploymentFiles(outputPath, &filewriter, tc.inputVariables, tc.deploymentType) + err := WriteDeploymentFiles(&filewriter, outputPath, tc.inputVariables, tc.deploymentType) errored := err != nil if err != nil { fmt.Printf("WriteDeploymentFiles failed: %e\n", err) From 4baf59afa0e70a3e5212684265bfaef0cb05ede2 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Fri, 3 Mar 2023 16:02:29 -0500 Subject: [PATCH 8/9] run deployments example --- example/deployment_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/example/deployment_test.go b/example/deployment_test.go index af24ebec..67a0238e 100644 --- a/example/deployment_test.go +++ b/example/deployment_test.go @@ -54,3 +54,11 @@ func TestWriteDeploymentFiles(t *testing.T) { }) } } + +func TestWriteDeploymentFilesExample(t *testing.T) { + err := WriteDockerfileExample() + if err != nil { + t.Errorf("WriteDockerfileExample failed: %e", err) + t.Fail() + } +} From e0e58d25758e28479f192cace9fe03de35be33f9 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Mon, 6 Mar 2023 17:50:41 -0500 Subject: [PATCH 9/9] add draft.yaml paths --- example/deployment.go | 2 +- example/deployment_test.go | 2 +- example/dockerfile.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/deployment.go b/example/deployment.go index ffc2ed34..6ded0084 100644 --- a/example/deployment.go +++ b/example/deployment.go @@ -9,7 +9,7 @@ import ( "github.com/Azure/draft/template" ) -// WriteDeploymentFiles generates Deployment Files using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +// WriteDeploymentFiles generates Deployment Files using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file in templates/deployments/[deployType] for the template inputs. func WriteDeploymentFiles(w templatewriter.TemplateWriter, deploymentOutputPath string, deploymentInputs map[string]string, deploymentType string) error { d := deployments.CreateDeploymentsFromEmbedFS(template.Deployments, deploymentOutputPath) diff --git a/example/deployment_test.go b/example/deployment_test.go index 67a0238e..d604093a 100644 --- a/example/deployment_test.go +++ b/example/deployment_test.go @@ -56,7 +56,7 @@ func TestWriteDeploymentFiles(t *testing.T) { } func TestWriteDeploymentFilesExample(t *testing.T) { - err := WriteDockerfileExample() + err := WriteDeploymentFilesExample() if err != nil { t.Errorf("WriteDockerfileExample failed: %e", err) t.Fail() diff --git a/example/dockerfile.go b/example/dockerfile.go index 346ff9e8..c6cd6789 100644 --- a/example/dockerfile.go +++ b/example/dockerfile.go @@ -9,7 +9,7 @@ import ( "github.com/Azure/draft/template" ) -// WriteDockerfile generates a Dockerfile and dockerignore using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file for the template inputs. +// WriteDockerfile generates a Dockerfile and dockerignore using Draft, writing to a Draft TemplateWriter. See the corresponding draft.yaml file in templates/dockerfiles/[language] for the template inputs. func WriteDockerfile(w templatewriter.TemplateWriter, dockerfileOutputPath string, dockerfileInputs map[string]string, generationLanguage string) error { l := languages.CreateLanguagesFromEmbedFS(template.Dockerfiles, dockerfileOutputPath)