/
build.go
109 lines (96 loc) · 2.72 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package qliksense
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"helm.sh/helm/v3/pkg/cli"
)
// This is an example. Replace thie following with whatever steps are needed to
// install required components into
const (
dockerfileLines = `
RUN echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list && \
apt-get update && \
apt-get install --no-install-recommends libgpgme11-dev libassuan-dev libbtrfs-dev libdevmapper-dev rdfind -y && \
rm -rf /var/lib/apt/lists/*
COPY --from=qlik/qliksense-cloud-tools:latest /usr/local/bin /usr/local/bin
COPY --from=qlik/qliksense-operator:latest /usr/local/bin/qliksense-operator /usr/local/bin
`
chartName = "qliksense"
chartCache = ".chartcache"
qseokVersion = "QSEOK_VERSION"
porterFile = "porter.yaml"
)
var (
settings *cli.EnvSettings
helmDir = filepath.Join("helm", "repository")
versionFile = filepath.Join("transformers", "qseokversion.yaml")
)
type porterYaml struct {
Dockerfile string `yaml:"dockerfile"`
}
type patch struct {
Target struct {
Kind string `yaml:"kind"`
LabelSelector string `yaml:"labelSelector"`
} `yaml:"target"`
Patch string `yaml:"patch"`
}
type selectivePatch struct {
APIVersion string `yaml:"apiVersion"`
Metadata struct {
Name string `yaml:"name"`
} `yaml:"metadata"`
Enabled bool `yaml:"enabled"`
Patches []patch `yaml:"patches"`
}
type helmChart struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata struct {
Name string `yaml:"name"`
} `yaml:"metadata"`
ReleaseNamespace string `yaml:"releaseNamespace"`
ChartHome string `yaml:"chartHome"`
ChartRepo string `yaml:"chartRepo"`
ChartName string `yaml:"chartName"`
ChartVersion string `yaml:"chartVersion"`
}
// Build will generate the necessary Dockerfile lines
// for an invocation image using this mixin
func (m *Mixin) Build() error {
fmt.Fprintf(m.Out, dockerfileLines)
return nil
}
// GetTransformerVersion ...
func GetTransformerVersion() (string, error) {
var patchInst patch
var bytes []byte
var err error
var selPatch selectivePatch
var chart helmChart
if _, err = os.Stat(versionFile); err != nil {
if os.IsNotExist(err) {
return "", err
}
return "", errors.Errorf("Unable to determine About file %v exists", versionFile)
}
if bytes, err = ioutil.ReadFile(versionFile); err != nil {
return "", err
}
if err = yaml.Unmarshal(bytes, &selPatch); err != nil {
return "", err
}
for _, patchInst = range selPatch.Patches {
err = yaml.Unmarshal([]byte(patchInst.Patch), &chart)
if err == nil {
if chart.ChartName == chartName {
return chart.ChartVersion, nil
}
}
}
return "", nil
}