1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-15 17:51:03 +00:00

Package charts as tgz file

This commit is contained in:
Ewout Prangsma 2018-08-10 12:09:08 +02:00
parent 1f7a925060
commit 7b49f6e44f
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698

View file

@ -23,12 +23,15 @@
package main package main
import ( import (
"archive/tar"
"bytes" "bytes"
"compress/gzip"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"path"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -148,6 +151,19 @@ Storage:
` `
) )
var (
chartTemplateGroups = map[string]chartTemplates{
"kube-arangodb": chartTemplates{
"Chart.yaml": kubeArangoDBChartTemplate,
"values.yaml": kubeArangoDBValuesTemplate,
},
"kube-arangodb-storage": chartTemplates{
"Chart.yaml": kubeArangoDBStorageChartTemplate,
"values.yaml": kubeArangoDBStorageValuesTemplate,
},
}
)
func init() { func init() {
pflag.StringVar(&options.OutputSuffix, "output-suffix", "", "Suffix of the generated manifest files") pflag.StringVar(&options.OutputSuffix, "output-suffix", "", "Suffix of the generated manifest files")
pflag.StringVar(&options.TemplatesDir, "templates-dir", "manifests/templates", "Directory containing manifest templates") pflag.StringVar(&options.TemplatesDir, "templates-dir", "manifests/templates", "Directory containing manifest templates")
@ -234,6 +250,15 @@ func main() {
log.Fatalf("Failed to read VERSION file: %v", err) log.Fatalf("Failed to read VERSION file: %v", err)
} }
// Prepare chart tars
chartTarBufs := make(map[string]*bytes.Buffer)
chartTars := make(map[string]*tar.Writer)
for groupName := range chartTemplateGroups {
buf := &bytes.Buffer{}
chartTarBufs[groupName] = buf
chartTars[groupName] = tar.NewWriter(buf)
}
// Process templates // Process templates
templateOptions := TemplateOptions{ templateOptions := TemplateOptions{
Version: strings.TrimSpace(string(version)), Version: strings.TrimSpace(string(version)),
@ -420,32 +445,24 @@ func main() {
// Save output // Save output
if output.Len() > 0 { if output.Len() > 0 {
outputDir, err := filepath.Abs(filepath.Join("bin", "charts", templateGroup.ChartName, "templates")) tarPath := path.Join(templateGroup.ChartName, "templates", group+".yaml")
if err != nil { hdr := &tar.Header{
log.Fatalf("Failed to get absolute output dir: %v\n", err) Name: tarPath,
Mode: 0644,
Size: int64(output.Len()),
} }
outputPath := filepath.Join(outputDir, group+".yaml") tw := chartTars[templateGroup.ChartName]
if err := os.MkdirAll(outputDir, 0755); err != nil { if err := tw.WriteHeader(hdr); err != nil {
log.Fatalf("Failed to create output directory: %v\n", err) log.Fatal(err)
} }
if err := ioutil.WriteFile(outputPath, output.Bytes(), 0644); err != nil { if _, err := tw.Write(output.Bytes()); err != nil {
log.Fatalf("Failed to write output file: %v\n", err) log.Fatal(err)
} }
} }
} }
} }
// Build Chart files // Build Chart files
chartTemplateGroups := map[string]chartTemplates{
"kube-arangodb": chartTemplates{
"Chart.yaml": kubeArangoDBChartTemplate,
"values.yaml": kubeArangoDBValuesTemplate,
},
"kube-arangodb-storage": chartTemplates{
"Chart.yaml": kubeArangoDBStorageChartTemplate,
"values.yaml": kubeArangoDBStorageValuesTemplate,
},
}
for groupName, chartTemplates := range chartTemplateGroups { for groupName, chartTemplates := range chartTemplateGroups {
for name, templateSource := range chartTemplates { for name, templateSource := range chartTemplates {
output := &bytes.Buffer{} output := &bytes.Buffer{}
@ -456,17 +473,45 @@ func main() {
t.Execute(output, templateOptions) t.Execute(output, templateOptions)
// Save output // Save output
outputDir, err := filepath.Abs(filepath.Join("bin", "charts", groupName)) tarPath := path.Join(groupName, name)
if err != nil { hdr := &tar.Header{
log.Fatalf("Failed to get absolute output dir: %v\n", err) Name: tarPath,
Mode: 0644,
Size: int64(output.Len()),
} }
outputPath := filepath.Join(outputDir, name) tw := chartTars[groupName]
if err := os.MkdirAll(outputDir, 0755); err != nil { if err := tw.WriteHeader(hdr); err != nil {
log.Fatalf("Failed to create output directory: %v\n", err) log.Fatal(err)
} }
if err := ioutil.WriteFile(outputPath, output.Bytes(), 0644); err != nil { if _, err := tw.Write(output.Bytes()); err != nil {
log.Fatalf("Failed to write output file: %v\n", err) log.Fatal(err)
} }
} }
} }
// Save charts
for groupName, tw := range chartTars {
if err := tw.Close(); err != nil {
log.Fatal(err)
}
// Gzip tarball
tarBytes := chartTarBufs[groupName].Bytes()
output := &bytes.Buffer{}
gw := gzip.NewWriter(output)
if _, err := gw.Write(tarBytes); err != nil {
log.Fatal(err)
}
gw.Close()
outputDir, err := filepath.Abs("bin/charts")
if err != nil {
log.Fatalf("Failed to get absolute output dir: %v\n", err)
}
outputPath := filepath.Join(outputDir, groupName+".tgz")
if err := os.MkdirAll(outputDir, 0755); err != nil {
log.Fatalf("Failed to create output directory: %v\n", err)
}
if err := ioutil.WriteFile(outputPath, output.Bytes(), 0644); err != nil {
log.Fatalf("Failed to write output file: %v\n", err)
}
}
} }