Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 7d0034a

Browse files
authored
Merge pull request #134 from mnottale/init-single-comments
init: Add section comments in single-file mode.
2 parents 550dfe1 + c1ab755 commit 7d0034a

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

e2e/testdata/init-singlefile.dockerapp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This section contains your application metadata.
12
version: 0.1.0
23
name: tac
34
description: my cool app
@@ -11,11 +12,13 @@ targets:
1112
kubernetes: true
1213

1314
--
15+
# This section contains the Compose file that describes your application services.
1416
services:
1517
nginx:
1618
image: nginx:${NGINX_VERSION}
1719
command: nginx $NGINX_ARGS
1820

1921
--
22+
# This section contains the default values for your application settings.
2023
NGINX_ARGS: FILL ME
2124
NGINX_VERSION: latest

examples/hello-world/README.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ $ ls -l
1414
-rw-r--r-- 1 README.md
1515
-rw-r--r-- 1 hello-world.dockerapp
1616
$ cat hello-world.dockerapp
17-
#
18-
# Metadata.
19-
#
17+
# This section contains your application metadata.
2018
version: 0.1.0
2119
name: hello-world
2220
description: ""
@@ -28,16 +26,12 @@ targets:
2826
kubernetes: true
2927

3028
--
31-
#
32-
# Services.
33-
#
29+
# This section contains the Compose file that describes your application services.
3430
version: "3.6"
3531
services: {}
3632

3733
--
38-
#
39-
# Settings.
40-
#
34+
# This section contains the default values for your application settings.
4135
```
4236

4337
Open `hello-world.dockerapp` with your favorite text editor.
@@ -56,9 +50,7 @@ Add a service `hello` to the `services` section.
5650
```yml
5751
[...]
5852
---
59-
#
60-
# Services.
61-
#
53+
# This section contains the Compose file that describes your application services.
6254
services:
6355
hello:
6456
image: hashicorp/http-echo
@@ -80,9 +72,7 @@ In the settings section, add every variables with the default value you want, e.
8072
```yml
8173
[...]
8274
---
83-
#
84-
# Settings.
85-
#
75+
# This section contains the default values for your application settings.
8676
port: 8080
8777
text: hello world!
8878
```

packager/init.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import (
1515
"gopkg.in/yaml.v2"
1616
)
1717

18+
func prependToFile(filename, text string) {
19+
content, _ := ioutil.ReadFile(filename)
20+
content = []byte(text + string(content))
21+
ioutil.WriteFile(filename, content, 0644)
22+
}
23+
1824
// Init is the entrypoint initialization function.
1925
// It generates a new application package based on the provided parameters.
2026
func Init(name string, composeFile string, description string, maintainers []string, singleFile bool) error {
@@ -52,6 +58,10 @@ func Init(name string, composeFile string, description string, maintainers []str
5258
return nil
5359
}
5460
// Merge as a single file
61+
// Add some helfpful comments to distinguish the sections
62+
prependToFile(filepath.Join(dirName, "docker-compose.yml"), "# This section contains the Compose file that describes your application services.\n")
63+
prependToFile(filepath.Join(dirName, "settings.yml"), "# This section contains the default values for your application settings.\n")
64+
prependToFile(filepath.Join(dirName, "metadata.yml"), "# This section contains your application metadata.\n")
5565
temp := "_temp_dockerapp__.dockerapp"
5666
err = os.Rename(dirName, temp)
5767
if err != nil {

0 commit comments

Comments
 (0)