Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ dist/
/*.sh

ploy
generated/
.DS_Store
109 changes: 109 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package cmd

import (
"fmt"
"html/template"
"os"
"strings"
"io/ioutil"

"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"embed"
)

//go:embed templates/*
var templatesFS embed.FS

type HtmlTemplate struct {
Title string
ID string `yaml:"id"`
Version string `yaml:"version"`
Type string `yaml:"type"`
Repository string `yaml:"repository"`
}

type Deployments struct {
Title string `yaml:"name"`
Deployments []HtmlTemplate `yaml:"deployments"`
}

func Generate(envFile string) error {
var deployments Deployments

yamlData, err := ioutil.ReadFile(envFile)
if err != nil {
return fmt.Errorf("error loading deployments file: %s", err)
}

// unmarshal the environment YAML data into the deployments struct
err = yaml.Unmarshal(yamlData, &deployments)
if err != nil {
return fmt.Errorf("Error parsing YAML file: %s", err)
}

// read the env.html template file
htmlTemplate, err := templatesFS.ReadFile("templates/env.html")
if err != nil {
return fmt.Errorf("Error loading env.html template file: %s", err)
}

// parse the HTML template
tmpl, err := template.New("env").Parse(string(htmlTemplate))
if err != nil {
return fmt.Errorf("Error parsing HTML template: %s", err)
}

// create the output file
os.MkdirAll("generated", os.ModePerm)
outFile, err := os.Create(fmt.Sprintf("generated/%s.html", strings.Split(envFile, ".")[0]))
if err != nil {
return fmt.Errorf("Error creating output file: %s", err)
}
defer outFile.Close()

// execute the HTML template
err = tmpl.Execute(outFile, deployments)
if err != nil {
return fmt.Errorf("Error executing HTML template: %s", err)
}

return nil
}

// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "generate [env-file]",
Short: "Generate deployment dashboard HTML file",
Long: `Generate deployment dashboard HTML file based on the specified environment YAML file.`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("Usage: ploy generate [yaml-file]")
}

envFile := args[0]

err := Generate(envFile)
if err != nil {
return err
}

fmt.Println("HTML file generated successfully.")

return nil
},
}

func init() {
rootCmd.AddCommand(generateCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// generateCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// generateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
124 changes: 124 additions & 0 deletions cmd/templates/env.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>{{.Title}}</title>
<style>
/* page style */
body {
background-color: black;
color: white;
position: relative;
font-family: 'Inter', sans-serif;
}

/* Style the table */
table {
border-collapse: separate;
overflow: hidden;
margin: 0 auto;
}

th,
td {
border: 1px solid white;
padding: 0.5rem;
}

/* Style the status column */
td.status {
font-size: 1.5rem;
text-align: center;
vertical-align: middle;
}

/* Green checkmark */
td.status .bg-green {
color: #2a9d8f;
}

/* Red checkmark */
td.status .bg-red {
color: #e76f51;
}

/* Hover effect on table rows */
tbody tr:hover {
background-color: #1e313b;
}

/* Style the link in version column */
td.version a {
color: #3182ce;
font-weight: bold;
text-decoration: underline;
}

/* Style the logo */
#logo {
position: absolute;
top: 1rem;
left: 1rem;
}
</style>
<!-- Import Tailwind CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.7/tailwind.min.css" />
</head>

<body>
<div id="logo">
<svg width="200" height="50" viewBox="0 0 950 245" xmlns="http://www.w3.org/2000/svg">
<path
d="M343.232 205.606C330.232 205.606 318.802 203.141 308.941 198.21C299.229 193.28 291.683 186.182 286.304 176.919C281.075 167.655 278.385 156.822 278.236 144.421H302.889C303.039 156.673 306.7 166.235 313.871 173.108C321.043 179.982 330.98 183.418 343.68 183.418C355.035 183.418 364.225 180.803 371.247 175.574C378.419 170.195 382.005 163.247 382.005 154.73C382.005 147.409 379.315 141.731 373.937 137.697C368.707 133.513 361.386 131.422 351.972 131.422H331.129C321.118 131.422 312.303 129.554 304.682 125.818C297.062 122.083 291.086 116.854 286.753 110.13C282.569 103.257 280.477 95.4124 280.477 86.5969C280.477 77.0343 282.942 68.5923 287.873 61.2709C292.953 53.9496 300.051 48.3465 309.165 44.4617C318.279 40.4274 328.813 38.4103 340.766 38.4103C360.041 38.4103 375.281 43.4905 386.487 53.6507C397.694 63.811 403.67 78.0802 404.417 96.4583H379.764C379.166 84.6545 375.505 75.7642 368.782 69.7876C362.207 63.6616 352.72 60.5986 340.318 60.5986C329.411 60.5986 320.819 62.8398 314.544 67.3223C308.268 71.8047 305.131 77.8561 305.131 85.4763C305.131 92.3494 307.521 97.803 312.303 101.837C317.233 105.722 323.808 107.664 332.025 107.664H352.869C369.603 107.664 382.752 111.773 392.315 119.991C401.877 128.209 406.659 139.415 406.659 153.61C406.659 163.919 404.044 173.034 398.814 180.953C393.585 188.722 386.189 194.774 376.626 199.107C367.063 203.44 355.932 205.606 343.232 205.606Z"
fill="white" />
<path
d="M474.964 203.589C464.505 203.589 455.017 201.199 446.5 196.417C437.983 191.487 431.26 184.838 426.329 176.47C421.548 167.954 419.157 158.466 419.157 148.007C419.157 137.548 421.548 128.06 426.329 119.543C431.26 111.026 437.983 104.377 446.5 99.596C455.017 94.6653 464.505 92.2 474.964 92.2C485.423 92.2 494.911 94.6653 503.427 99.596C512.093 104.377 518.817 111.026 523.598 119.543C528.529 128.06 530.994 137.548 530.994 148.007C530.994 158.466 528.529 167.954 523.598 176.47C518.817 184.838 512.168 191.487 503.651 196.417C495.135 201.199 485.572 203.589 474.964 203.589ZM474.964 180.729C483.779 180.729 491.101 177.666 496.928 171.54C502.755 165.264 505.669 157.42 505.669 148.007C505.669 138.444 502.755 130.6 496.928 124.474C491.101 118.198 483.779 115.061 474.964 115.061C466.148 115.061 458.827 118.198 453 124.474C447.322 130.6 444.483 138.444 444.483 148.007C444.483 157.569 447.322 165.414 453 171.54C458.827 177.666 466.148 180.729 474.964 180.729Z"
fill="white" />
<path
d="M593.038 203.589C578.694 203.589 567.189 199.331 558.523 190.814C549.857 182.298 545.524 170.867 545.524 156.523V94.4412H570.85V154.73C570.85 163.098 572.718 169.448 576.453 173.781C580.338 178.114 585.866 180.28 593.038 180.28C599.911 180.28 605.141 178.114 608.727 173.781C612.462 169.448 614.33 163.172 614.33 154.954V94.4412H639.656V156.747C639.656 165.862 637.639 174.005 633.604 181.177C629.72 188.199 624.266 193.728 617.243 197.762C610.221 201.647 602.152 203.589 593.038 203.589Z"
fill="white" />
<path
d="M657.586 135.904C657.586 122.606 661.321 111.998 668.792 104.078C676.412 96.1595 686.647 92.2 699.497 92.2H720.564V116.854H703.979C696.658 116.854 691.279 118.721 687.842 122.457C684.555 126.043 682.912 131.87 682.912 139.938V201.348H657.586V135.904Z"
fill="white" />
<path
d="M784.004 180.729C789.98 180.729 795.135 179.235 799.468 176.246C803.95 173.108 807.387 168.626 809.778 162.799L832.862 171.764C829.127 181.476 822.852 189.245 814.036 195.073C805.221 200.75 795.135 203.589 783.779 203.589C773.171 203.589 763.608 201.199 755.092 196.417C746.724 191.636 740.15 185.062 735.369 176.694C730.737 168.178 728.421 158.615 728.421 148.007C728.421 137.398 730.812 127.836 735.593 119.319C740.374 110.802 746.948 104.153 755.316 99.3719C763.683 94.5906 773.171 92.2 783.779 92.2C795.583 92.2 805.968 95.3377 814.932 101.613C824.047 107.889 830.322 116.181 833.759 126.491L811.571 137.697C809.927 130.973 806.491 125.594 801.261 121.56C796.031 117.376 790.279 115.285 784.004 115.285C775.188 115.285 767.941 118.348 762.264 124.474C756.586 130.6 753.747 138.444 753.747 148.007C753.747 157.569 756.586 165.414 762.264 171.54C767.941 177.666 775.188 180.729 784.004 180.729Z"
fill="white" />
<path
d="M950 148.007C950 151.593 949.925 154.73 949.776 157.42H869.316C870.959 164.891 874.321 170.718 879.401 174.901C884.481 179.085 890.682 181.177 898.003 181.177C904.279 181.177 909.434 180.131 913.468 178.039C917.502 175.798 920.64 172.436 922.881 167.954L944.397 176.47C940.213 184.838 934.013 191.487 925.795 196.417C917.577 201.199 908.388 203.589 898.228 203.589C887.619 203.589 878.206 201.273 869.988 196.641C861.77 191.86 855.345 185.286 850.713 176.919C846.082 168.402 843.766 158.765 843.766 148.007C843.766 137.249 846.082 127.686 850.713 119.319C855.345 110.802 861.77 104.153 869.988 99.3719C878.206 94.5906 887.544 92.2 898.003 92.2C907.716 92.2 916.531 94.6653 924.45 99.596C932.369 104.527 938.57 111.25 943.052 119.767C947.684 128.284 950 137.697 950 148.007ZM924.674 137.697C923.778 131.123 920.789 125.669 915.709 121.336C910.779 116.854 904.877 114.612 898.003 114.612C890.832 114.612 884.631 116.704 879.401 120.888C874.321 124.922 870.959 130.525 869.316 137.697H924.674Z"
fill="white" />
<path
d="M175.132 45.3821C158.279 38.4784 138.989 35.0265 117.262 35.0265C95.5359 35.0265 75.9414 38.3768 58.479 45.0775C70.459 15.0258 90.0535 0 117.262 0C144.878 0 164.167 15.1274 175.132 45.3821ZM58.479 45.0775C50.763 64.9766 46.905 90.6627 46.905 122.136C46.905 154.015 51.3721 180.209 60.3064 200.717C41.0165 194.625 26.0922 184.98 15.5335 171.782C5.17782 158.584 0 142.035 0 122.136C0 104.673 5.0763 89.3429 15.2289 76.1445C25.5845 62.743 40.0012 52.3874 58.479 45.0775ZM232.393 122.136C232.393 142.035 227.317 158.584 217.164 171.782C207.011 184.777 192.493 194.422 173.609 200.717C181.935 179.803 186.097 153.609 186.097 122.136C186.097 90.2566 182.442 64.6721 175.132 45.3821C193.001 52.4889 207.011 62.743 217.164 76.1445C227.317 89.5459 232.393 104.876 232.393 122.136ZM60.3064 200.717C76.1445 205.996 95.1298 208.636 117.262 208.636C138.38 208.636 157.162 205.996 173.609 200.717C168.127 214.524 160.614 225.185 151.071 232.698C141.73 240.414 130.461 244.271 117.262 244.271C104.064 244.271 92.6932 240.414 83.1498 232.698C73.8094 225.185 66.1949 214.524 60.3064 200.717Z"
fill="white" />
</svg>
</div>
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
<h1 class="text-3xl font-bold text-center mb-4">{{.Title}}</h1>
<div class="overflow-hidden">
<table class="min-w-full">
<thead>
<tr class="bg-gray-700">
<th class="px-4 py-2 text-left uppercase">Type</th>
<th class="px-4 py-2 text-left uppercase">Service Name</th>
<th class="px-4 py-2 text-left uppercase">Deployed Version</th>
<th class="px-4 py-2 text-left uppercase">Status</th>
</tr>
</thead>
<tbody>
{{range .Deployments}}
<tr>
<td class="border px-4 py-2">{{.Type}}</td>
<td class="border px-4 py-2">{{.ID}}</td>
<td class="border px-4 py-2 version"><a href="{{.Repository}}/tree/{{.Version}}">{{.Version}}</a></td>
<td class="border px-4 py-2 status"><span class="bg-green">&#x2713;</span></td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
</body>

</html>