Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/project-stacker/stacker/types"
)

const DefaultShell = "/usr/bin/sh"

type BuildArgs struct {
Config types.StackerConfig
LeaveUnladen bool
Expand Down Expand Up @@ -542,7 +544,7 @@ func (b *Builder) BuildMultiple(paths []string) error {
// container, and writes it to the contianer. It checks that the script already
// have a shebang? If so, it leaves it as is, otherwise it prepends a shebang.
func generateShellForRunning(rootfs string, cmd []string, outFile string) error {
shebangLine := "#!/bin/sh -xe\n"
shebangLine := fmt.Sprintf("#!%s -xe\n", DefaultShell)
if strings.HasPrefix(cmd[0], "#!") {
shebangLine = ""
}
Expand Down
2 changes: 2 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build-env:
- https://gitlab.com/cryptsetup/cryptsetup/-/archive/v2.4.3/cryptsetup-v2.4.3.tar.gz
- https://github.com/lvmteam/lvm2/archive/refs/tags/v2_03_15.tar.gz
run: |
#!/bin/sh
# libapparmor is only in testing
head -n1 /etc/apk/repositories | sed 's/main/testing/g' >> /etc/apk/repositories

Expand Down Expand Up @@ -67,6 +68,7 @@ build:
binds:
- . -> /stacker-tree
run: |
#!/bin/sh
# golang wants somewhere to put its garbage
export HOME=/root
export GOPATH=/stacker-tree/.build/gopath
Expand Down
4 changes: 3 additions & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"

"github.com/project-stacker/stacker"
"github.com/project-stacker/stacker/squashfs"
"github.com/project-stacker/stacker/types"
Expand Down Expand Up @@ -41,7 +43,7 @@ func initCommonBuildFlags() []cli.Flag {
},
cli.BoolFlag{
Name: "shell-fail",
Usage: "exec /bin/sh inside the container if run fails (alias for --on-run-failure=/bin/sh)",
Usage: fmt.Sprintf("exec %s inside the container if run fails (alias for --on-run-failure=%s)", stacker.DefaultShell, stacker.DefaultShell),
},
cli.StringSliceFlag{
Name: "layer-type",
Expand Down
9 changes: 5 additions & 4 deletions cmd/chroot.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/pkg/errors"
Expand All @@ -27,13 +28,13 @@ var chrootCmd = cli.Command{
Usage: "variable substitution in stackerfiles, FOO=bar format",
},
},
ArgsUsage: `[tag] [cmd]
ArgsUsage: fmt.Sprintf(`[tag] [cmd]

<tag> is the built tag in the stackerfile to chroot to, or the first tag if
none is specified.

<cmd> is the command to run, or /bin/sh if none is specified. To specify cmd,
you must specify a tag.`,
<cmd> is the command to run, or %s if none is specified. To specify cmd,
you must specify a tag.`, stacker.DefaultShell),
}

func doChroot(ctx *cli.Context) error {
Expand All @@ -48,7 +49,7 @@ func doChroot(ctx *cli.Context) error {
tag = ctx.Args()[0]
}

cmd := "/bin/sh"
cmd := stacker.DefaultShell

if len(ctx.Args()) > 1 {
cmd = ctx.Args()[1]
Expand Down
5 changes: 3 additions & 2 deletions cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
"regexp"

"github.com/pkg/errors"
"github.com/project-stacker/stacker"
"github.com/urfave/cli"
)

func validateBuildFailureFlags(ctx *cli.Context) error {
if ctx.Bool("shell-fail") {
askedFor := ctx.String("on-run-failure")
if askedFor != "" && askedFor != "/bin/sh" {
if askedFor != "" && askedFor != stacker.DefaultShell {
return errors.Errorf("--shell-fail is incompatible with --on-run-failure=%s", askedFor)
}
err := ctx.Set("on-run-failure", "/bin/sh")
err := ctx.Set("on-run-failure", stacker.DefaultShell)
if err != nil {
return err
}
Expand Down