Skip to content

Commit a6c3e40

Browse files
committed
Add support for entrypoint in all file formats
Add support for recognizing and setting an entrypoint in the final container image config. In particular, identify the instruction ENTRYPOINT in Containerfile-like syntax and the entrypoint field in bunnyfile. In both cases, an array of strings that contain the arguments is expected. Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
1 parent 550782d commit a6c3e40

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ kernel: # [5] Specify a prebuilt kernel
6262
from: local # [5a] Specify the source of a prebuilt kernel.
6363
path: local # [5b] The path where the kernel image resides.
6464
65-
cmd: ["hello"] # [6] The command line arguments of the app.
65+
cmd: ["app"] # [6] The command line arguments of the app
66+
entrypoint: ["init"] # [7] The entrypoint of the container
6667
6768
```
6869

@@ -85,7 +86,8 @@ The fields of `bunnyfile` in more details:
8586
| 5 | Information about a prebuilt kernel | no | - | - |
8687
| 5a | The location where the prebuilt kernel resides | no | "local", "OCI image" | - |
8788
| 5b | The path relative to the `from` field where a kernel binary resides | yes, if `from` is set | "local", "OCI image" | - |
88-
| 6 | The command line of the application | no | string | - |
89+
| 6 | The command line of the application | no | []string | - |
90+
| 7 | The entrypoint of the container | no | []string | - |
8991

9092
### The `rootfs` field
9193

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func bunnyBuilder(ctx context.Context, c client.Client) (*client.Result, error)
146146

147147
// Set some default values in the Image config
148148
// and add cmdline and Labels
149-
rc.UpdateConfig(packInst.Annots, packInst.Config.Cmd)
149+
rc.UpdateConfig(packInst.Annots, packInst.Config.Cmd, packInst.Config.Entrypoint)
150150

151151
// Apply annotations and the new config to the solver's result
152152
err = rc.ApplyConfig(packInst.Annots)

hops/image_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (rc *ResultAndConfig) GetBaseConfig(ctx context.Context, c client.Client, r
7272
return nil
7373
}
7474

75-
func (rc *ResultAndConfig) UpdateConfig(annots map[string]string, cmd []string) {
75+
func (rc *ResultAndConfig) UpdateConfig(annots map[string]string, cmd []string, entryp []string) {
7676
plat := ocispecs.Platform{
7777
Architecture: runtime.GOARCH,
7878
OS: "linux",
@@ -87,7 +87,7 @@ func (rc *ResultAndConfig) UpdateConfig(annots map[string]string, cmd []string)
8787
rc.OCIConfig.RootFS = rfs
8888
// Overwrite Cmd and entrypoint based on the values of bunnyfile
8989
rc.OCIConfig.Config.Cmd = cmd
90-
rc.OCIConfig.Config.Entrypoint = []string{}
90+
rc.OCIConfig.Config.Entrypoint = entryp
9191

9292
if rc.OCIConfig.Config.Labels == nil {
9393
rc.OCIConfig.Config.Labels = make(map[string]string)

hops/package.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ type Kernel struct {
5252
}
5353

5454
type Hops struct {
55-
Version string `yaml:"version"`
56-
Platform Platform `yaml:"platforms"`
57-
Rootfs Rootfs `yaml:"rootfs"`
58-
Kernel Kernel `yaml:"kernel"`
59-
Cmdline string `yaml:"cmdline"`
60-
Cmd []string `yaml:"cmd"`
55+
Version string `yaml:"version"`
56+
Platform Platform `yaml:"platforms"`
57+
Rootfs Rootfs `yaml:"rootfs"`
58+
Kernel Kernel `yaml:"kernel"`
59+
Cmdline string `yaml:"cmdline"`
60+
Cmd []string `yaml:"cmd"`
61+
Entrypoint []string `yaml:"entrypoint"`
6162
}
6263

6364
// A struct to represent a copy operation in the final image
@@ -287,8 +288,9 @@ func (i *PackInstructions) SetAnnotations(p Platform, cmd []string, kernelPath s
287288

288289
// UpdateConfig fills all the information given by the user for the
289290
// fileds in PackConfig.
290-
func (i *PackInstructions) UpdateConfig(cmd []string, p Platform) {
291+
func (i *PackInstructions) UpdateConfig(cmd []string, entryp []string, p Platform) {
291292
i.Config.Cmd = cmd
293+
i.Config.Entrypoint = entryp
292294
i.Config.Monitor = p.Monitor
293295
}
294296

@@ -334,7 +336,7 @@ func ToPack(h *Hops, buildContext string) (*PackInstructions, error) {
334336
return nil, fmt.Errorf("Error setting annotations: %v", err)
335337
}
336338

337-
instr.UpdateConfig(h.Cmd, h.Platform)
339+
instr.UpdateConfig(h.Cmd, h.Entrypoint, h.Platform)
338340

339341
return instr, nil
340342
}

hops/parse_file.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func ParseContainerfile(fileBytes []byte, buildContext string) (*PackInstruction
115115
}
116116
case *instructions.CmdCommand:
117117
instr.Config.Cmd = c.CmdLine
118+
case *instructions.EntrypointCommand:
119+
instr.Config.Entrypoint = c.CmdLine
118120
case instructions.Command:
119121
// Catch all other commands
120122
return nil, fmt.Errorf("Unsupported command: %s", c.Name())

0 commit comments

Comments
 (0)