1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +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
import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
"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() {
pflag.StringVar(&options.OutputSuffix, "output-suffix", "", "Suffix of the generated manifest files")
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)
}
// 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
templateOptions := TemplateOptions{
Version: strings.TrimSpace(string(version)),
@ -420,32 +445,24 @@ func main() {
// Save output
if output.Len() > 0 {
outputDir, err := filepath.Abs(filepath.Join("bin", "charts", templateGroup.ChartName, "templates"))
if err != nil {
log.Fatalf("Failed to get absolute output dir: %v\n", err)
tarPath := path.Join(templateGroup.ChartName, "templates", group+".yaml")
hdr := &tar.Header{
Name: tarPath,
Mode: 0644,
Size: int64(output.Len()),
}
outputPath := filepath.Join(outputDir, group+".yaml")
if err := os.MkdirAll(outputDir, 0755); err != nil {
log.Fatalf("Failed to create output directory: %v\n", err)
tw := chartTars[templateGroup.ChartName]
if err := tw.WriteHeader(hdr); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile(outputPath, output.Bytes(), 0644); err != nil {
log.Fatalf("Failed to write output file: %v\n", err)
if _, err := tw.Write(output.Bytes()); err != nil {
log.Fatal(err)
}
}
}
}
// 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 name, templateSource := range chartTemplates {
output := &bytes.Buffer{}
@ -456,17 +473,45 @@ func main() {
t.Execute(output, templateOptions)
// Save output
outputDir, err := filepath.Abs(filepath.Join("bin", "charts", groupName))
if err != nil {
log.Fatalf("Failed to get absolute output dir: %v\n", err)
tarPath := path.Join(groupName, name)
hdr := &tar.Header{
Name: tarPath,
Mode: 0644,
Size: int64(output.Len()),
}
outputPath := filepath.Join(outputDir, name)
if err := os.MkdirAll(outputDir, 0755); err != nil {
log.Fatalf("Failed to create output directory: %v\n", err)
tw := chartTars[groupName]
if err := tw.WriteHeader(hdr); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile(outputPath, output.Bytes(), 0644); err != nil {
log.Fatalf("Failed to write output file: %v\n", err)
if _, err := tw.Write(output.Bytes()); err != nil {
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)
}
}
}