forked from docker/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
48 lines (45 loc) · 1.09 KB
/
examples_test.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
package app
import (
"fmt"
"os"
"github.com/docker/app/loader"
"github.com/docker/app/render"
yaml "gopkg.in/yaml.v2"
)
func Example() {
// Load the file (single-file format, there is multiple format)
f, err := os.Open("./examples/hello-world/hello-world.dockerapp")
if err != nil {
panic("cannot read application")
}
defer f.Close()
app, err := loader.LoadFromSingleFile("myApp", f)
if err != nil {
panic("cannot load application: " + err.Error())
}
// Render the app to a composefile format, using some user provided parameters
c, err := render.Render(app, map[string]string{
"text": "hello examples!",
}, nil)
if err != nil {
panic("cannot render application")
}
// Marshal it to yaml (to display it)
s, err := yaml.Marshal(c)
if err != nil {
panic("cannot marshall the composefile in yaml")
}
fmt.Print(string(s))
// Output: version: "3.6"
// services:
// hello:
// command:
// - -text
// - hello examples!
// image: hashicorp/http-echo
// ports:
// - mode: ingress
// target: 5678
// published: 8080
// protocol: tcp
}