generated from getporter/skeletor
/
build.go
56 lines (42 loc) · 1.36 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
package mysql
import (
"fmt"
"get.porter.sh/porter/pkg/exec/builder"
yaml "gopkg.in/yaml.v2"
)
// BuildInput represents stdin passed to the mixin for the build command.
type BuildInput struct {
Config MixinConfig
}
// MixinConfig represents configuration that can be set on the mysql mixin in porter.yaml
// mixins:
// - mysql:
// clientVersion: "v0.0.0"
type MixinConfig struct {
ClientVersion string `yaml:"clientVersion,omitempty"`
}
// This is an example. Replace the following with whatever steps are needed to
// install required components into
const dockerfileLines = `RUN apt-get update && \
apt-get install mysql-client -y`
// Build will generate the necessary Dockerfile lines
// for an invocation image using this mixin
func (m *Mixin) Build() error {
// Create new Builder.
var input BuildInput
err := builder.LoadAction(m.Context, "", func(contents []byte) (interface{}, error) {
err := yaml.Unmarshal(contents, &input)
return &input, err
})
if err != nil {
return err
}
suppliedClientVersion := input.Config.ClientVersion
if suppliedClientVersion != "" {
m.ClientVersion = suppliedClientVersion
}
fmt.Fprintf(m.Out, dockerfileLines)
// Example of pulling and defining a client version for your mixin
// fmt.Fprintf(m.Out, "\nRUN curl https://get.helm.sh/helm-%s-linux-amd64.tar.gz --output helm3.tar.gz", m.ClientVersion)
return nil
}