Azure / draft

A day 0 tool for getting your app on k8s fast
MIT License
515 stars 61 forks source link

add dryrun capability to `create` command #166

Closed davidgamero closed 1 year ago

davidgamero commented 1 year ago

Description

add two new flags that allow dry run executions of the draft info that return a dry run summary in json format including the auto-detected language, values of the variables in the draft config, and a list of files to be written

the --dry-run flag enables a dry run, printing the JSON summary at the end of the normal execution, and uses a custom dryrunwriter to satisfy the templateWriter interface.

the additional, optional --dry-run-file flag allows writing exclusively the JSON dry run summary to a file, since piping the output of the create command with dry run enabled includes the normal status messages which makes it un-parsable as pure JSON.

Use Case

This new feature further enhances consumption of draft in a binary-wrapping pattern by allowing a wrapper to leverage the linguist-powered language detection, and detect file modifications prior to running draft create.

Currently, the aks-devx-tools uses this consumption pattern, and will have better access to build upon draft using this dry run capability.

Example Output

{
  "variables": {
    "APPNAME": "testapp",
    "BUILDERVERSION": "null",
    "IMAGENAME": "testapp",
    "LANGUAGE": "gomodule",  // Note that this variable is in addition to the draft config variables
    "NAMESPACE": "default",
    "PORT": "1323",
    "SERVICEPORT": "80",
    "VERSION": "1.18"
  },
  "filesToWrite": [
    "langtest/.dockerignore",
    "langtest/Dockerfile",
    "langtest/charts/.helmignore",
    "langtest/charts/Chart.yaml",
    "langtest/charts/production.yaml",
    "langtest/charts/templates/_helpers.tpl",
    "langtest/charts/templates/deployment.yaml",
    "langtest/charts/templates/namespace.yaml",
    "langtest/charts/templates/service.yaml",
    "langtest/charts/values.yaml"
  ]
}

Fixes # (issue) Feature # (details)

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. Is it a breaking change which will impact consuming tool(s).

Checklist: