This repository was archived by the owner on Jul 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Package app provides experimental utilities to make Compose files more
2+ // reusable and sharable.
3+ //
4+ // The `cmd/docker-app` package generates the `docker-app` binary,
5+ // see https://github.com/docker/app for more information about it.
6+ //
7+ // It can also be used as a library to be integrated in your tools.
8+ // Usage examples are provided inline with their full documentation.
19package app
Original file line number Diff line number Diff line change 1+ package app
2+
3+ import (
4+ "fmt"
5+ "os"
6+
7+ "github.com/docker/app/loader"
8+ "github.com/docker/app/render"
9+ yaml "gopkg.in/yaml.v2"
10+ )
11+
12+ func Example () {
13+ // Load the file (single-file format, there is multiple format)
14+ f , err := os .Open ("./examples/hello-world/hello-world.dockerapp" )
15+ if err != nil {
16+ panic ("cannot read application" )
17+ }
18+ defer f .Close ()
19+ app , err := loader .LoadFromSingleFile ("myApp" , f )
20+ if err != nil {
21+ panic ("cannot load application" )
22+ }
23+ // Render the app to a composefile format, using some user provided settings
24+ c , err := render .Render (app , map [string ]string {
25+ "text" : "hello examples!" ,
26+ })
27+ if err != nil {
28+ panic ("cannot render application" )
29+ }
30+ // Marshal it to yaml (to display it)
31+ s , err := yaml .Marshal (c )
32+ if err != nil {
33+ panic ("cannot marshall the composefile in yaml" )
34+ }
35+ fmt .Print (string (s ))
36+ // Output: version: "3.6"
37+ // services:
38+ // hello:
39+ // command:
40+ // - -text
41+ // - hello examples!
42+ // image: hashicorp/http-echo
43+ // ports:
44+ // - mode: ingress
45+ // target: 5678
46+ // published: 8080
47+ // protocol: tcp
48+ }
You can’t perform that action at this time.
0 commit comments