Skip to content

Commit 3baba64

Browse files
authored
fix(ci): convert ci is failing due to perms (#439)
* fix(convert): expose docker vols are substituted args Currently, docker vols are mapped 1:1 between host and container, which is probably not we want. Now, they will be exposed as substituted vars. Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> * chore(go.mod): update cli to github.com/urfave/cli/v2 Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> * fix(cli): "--substitute" args have priority over "--substitute-file" Args substitution can happen via "--substitute" and "--substitute-file", so behavior can become unpredictable. Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com> --------- Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
1 parent e78c22b commit 3baba64

File tree

20 files changed

+190
-155
lines changed

20 files changed

+190
-155
lines changed

.github/workflows/convert.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ jobs:
3535
git clone https://github.com/alpinelinux/docker-alpine.git
3636
chmod -R a+rwx docker-alpine
3737
cd docker-alpine
38-
mkdir -p /out
39-
chmod -R a+rwx /out
38+
TEMPDIR=$(mktemp -d)
4039
stacker convert --docker-file Dockerfile --output-file stacker.yaml --substitute-file stacker-subs.yaml
41-
stacker build -f stacker.yaml --substitute-file stacker-subs.yaml --substitute IMAGE=alpine
40+
stacker build -f stacker.yaml --substitute-file stacker-subs.yaml --substitute IMAGE=alpine --substitute STACKER_VOL1="$TEMPDIR"
4241
stacker publish -f stacker.yaml --substitute-file stacker-subs.yaml --substitute IMAGE=alpine --skip-tls --url docker://${REGISTRY_URL} --layer alpine --tag latest
4342
rm -f stacker.yaml stacker-subs.yaml
4443
stacker clean

cmd/stacker/build.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"fmt"
55

6-
"github.com/urfave/cli"
6+
cli "github.com/urfave/cli/v2"
77
"stackerbuild.io/stacker/pkg/squashfs"
88
"stackerbuild.io/stacker/pkg/stacker"
99
"stackerbuild.io/stacker/pkg/types"
@@ -20,53 +20,54 @@ var buildCmd = cli.Command{
2020
func initBuildFlags() []cli.Flag {
2121
return append(
2222
initCommonBuildFlags(),
23-
cli.StringFlag{
24-
Name: "stacker-file, f",
25-
Usage: "the input stackerfile",
26-
Value: "stacker.yaml",
23+
&cli.StringFlag{
24+
Name: "stacker-file",
25+
Aliases: []string{"f"},
26+
Usage: "the input stackerfile",
27+
Value: "stacker.yaml",
2728
})
2829
}
2930

3031
func initCommonBuildFlags() []cli.Flag {
3132
return []cli.Flag{
32-
cli.BoolFlag{
33+
&cli.BoolFlag{
3334
Name: "no-cache",
3435
Usage: "don't use the previous build cache",
3536
},
36-
cli.StringSliceFlag{
37+
&cli.StringSliceFlag{
3738
Name: "substitute",
3839
Usage: "variable substitution in stackerfiles, FOO=bar format",
3940
},
40-
cli.StringFlag{
41+
&cli.StringFlag{
4142
Name: "substitute-file",
4243
Usage: "file containing variable substitution in stackerfiles, 'FOO: bar' yaml format",
4344
},
44-
cli.StringFlag{
45+
&cli.StringFlag{
4546
Name: "on-run-failure",
4647
Usage: "command to run inside container if run fails (useful for inspection)",
4748
},
48-
cli.BoolFlag{
49+
&cli.BoolFlag{
4950
Name: "shell-fail",
5051
Usage: fmt.Sprintf("exec %s inside the container if run fails (alias for --on-run-failure=%s)", stacker.DefaultShell, stacker.DefaultShell),
5152
},
52-
cli.StringSliceFlag{
53+
&cli.StringSliceFlag{
5354
Name: "layer-type",
5455
Usage: "set the output layer type (supported values: tar, squashfs); can be supplied multiple times",
55-
Value: &cli.StringSlice{"tar"},
56+
Value: cli.NewStringSlice("tar"),
5657
},
57-
cli.BoolFlag{
58+
&cli.BoolFlag{
5859
Name: "no-squashfs-verity",
5960
Usage: "do not append dm-verity data to squashfs archives",
6061
},
61-
cli.BoolFlag{
62+
&cli.BoolFlag{
6263
Name: "require-hash",
6364
Usage: "require all remote imports to have a hash provided in stackerfiles",
6465
},
65-
cli.BoolFlag{
66+
&cli.BoolFlag{
6667
Name: "order-only",
6768
Usage: "show the build order without running the actual build",
6869
},
69-
cli.StringFlag{
70+
&cli.StringFlag{
7071
Name: "annotations-namespace",
7172
Usage: "set OCI annotations namespace in the OCI image manifest",
7273
Value: "io.stackeroci",

cmd/stacker/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/pkg/errors"
99
"github.com/pkg/xattr"
10-
"github.com/urfave/cli"
10+
cli "github.com/urfave/cli/v2"
1111
"stackerbuild.io/stacker/pkg/log"
1212
"stackerbuild.io/stacker/pkg/overlay"
1313
"stackerbuild.io/stacker/pkg/stacker"

cmd/stacker/chroot.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66

77
"github.com/pkg/errors"
8-
"github.com/urfave/cli"
8+
cli "github.com/urfave/cli/v2"
99
"stackerbuild.io/stacker/pkg/container"
1010
"stackerbuild.io/stacker/pkg/log"
1111
"stackerbuild.io/stacker/pkg/stacker"
@@ -18,12 +18,13 @@ var chrootCmd = cli.Command{
1818
Aliases: []string{"exec"},
1919
Action: doChroot,
2020
Flags: []cli.Flag{
21-
cli.StringFlag{
22-
Name: "stacker-file, f",
23-
Usage: "the input stackerfile",
24-
Value: "stacker.yaml",
21+
&cli.StringFlag{
22+
Name: "stacker-file",
23+
Aliases: []string{"f"},
24+
Usage: "the input stackerfile",
25+
Value: "stacker.yaml",
2526
},
26-
cli.StringSliceFlag{
27+
&cli.StringSliceFlag{
2728
Name: "substitute",
2829
Usage: "variable substitution in stackerfiles, FOO=bar format",
2930
},
@@ -45,14 +46,14 @@ func doChroot(ctx *cli.Context) error {
4546
defer locks.Unlock()
4647

4748
tag := ""
48-
if len(ctx.Args()) > 0 {
49-
tag = ctx.Args()[0]
49+
if ctx.Args().Len() > 0 {
50+
tag = ctx.Args().Get(0)
5051
}
5152

5253
cmd := stacker.DefaultShell
5354

54-
if len(ctx.Args()) > 1 {
55-
cmd = ctx.Args()[1]
55+
if ctx.Args().Len() > 1 {
56+
cmd = ctx.Args().Get(1)
5657
}
5758

5859
file := ctx.String("f")

cmd/stacker/clean.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55

66
"github.com/pkg/errors"
7-
"github.com/urfave/cli"
7+
cli "github.com/urfave/cli/v2"
88
"stackerbuild.io/stacker/pkg/log"
99
"stackerbuild.io/stacker/pkg/stacker"
1010
)
@@ -14,7 +14,7 @@ var cleanCmd = cli.Command{
1414
Usage: "cleans up after a `stacker build`",
1515
Action: doClean,
1616
Flags: []cli.Flag{
17-
cli.BoolFlag{
17+
&cli.BoolFlag{
1818
Name: "all",
1919
Usage: "no-op; this used to do soemthing, and is left in for compatibility",
2020
},

cmd/stacker/convert.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"log"
55

6-
"github.com/urfave/cli"
6+
cli "github.com/urfave/cli/v2"
77
"stackerbuild.io/stacker/pkg/stacker"
88
)
99

@@ -18,20 +18,23 @@ var convertCmd = cli.Command{
1818
func initConvertFlags() []cli.Flag {
1919
return append(
2020
initCommonConvertFlags(),
21-
cli.StringFlag{
22-
Name: "docker-file, i",
23-
Usage: "the input Dockerfile",
24-
Value: "Dockerfile",
21+
&cli.StringFlag{
22+
Name: "docker-file",
23+
Aliases: []string{"i"},
24+
Usage: "the input Dockerfile",
25+
Value: "Dockerfile",
2526
},
26-
cli.StringFlag{
27-
Name: "output-file, o",
28-
Usage: "the output stacker file",
29-
Value: "stacker.yaml",
27+
&cli.StringFlag{
28+
Name: "output-file",
29+
Aliases: []string{"o"},
30+
Usage: "the output stacker file",
31+
Value: "stacker.yaml",
3032
},
31-
cli.StringFlag{
32-
Name: "substitute-file, s",
33-
Usage: "the output file containing detected substitutions",
34-
Value: "stacker-subs.yaml",
33+
&cli.StringFlag{
34+
Name: "substitute-file",
35+
Aliases: []string{"s"},
36+
Usage: "the output file containing detected substitutions",
37+
Value: "stacker-subs.yaml",
3538
},
3639
)
3740
}

cmd/stacker/gc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/urfave/cli"
4+
cli "github.com/urfave/cli/v2"
55
"stackerbuild.io/stacker/pkg/stacker"
66
)
77

cmd/stacker/grab.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66

77
"github.com/pkg/errors"
8-
"github.com/urfave/cli"
8+
cli "github.com/urfave/cli/v2"
99
"stackerbuild.io/stacker/pkg/stacker"
1010
)
1111

cmd/stacker/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/opencontainers/umoci"
1111
"github.com/opencontainers/umoci/oci/casext"
1212
"github.com/pkg/errors"
13-
"github.com/urfave/cli"
13+
cli "github.com/urfave/cli/v2"
1414
stackeroci "stackerbuild.io/stacker/pkg/oci"
1515
)
1616

cmd/stacker/internal_go.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"github.com/pkg/errors"
11-
"github.com/urfave/cli"
11+
cli "github.com/urfave/cli/v2"
1212
"golang.org/x/sys/unix"
1313
"stackerbuild.io/stacker/pkg/atomfs"
1414
"stackerbuild.io/stacker/pkg/lib"
@@ -19,43 +19,43 @@ import (
1919
var internalGoCmd = cli.Command{
2020
Name: "internal-go",
2121
Hidden: true,
22-
Subcommands: []cli.Command{
23-
cli.Command{
22+
Subcommands: []*cli.Command{
23+
&cli.Command{
2424
Name: "cp",
2525
Action: doCP,
2626
},
27-
cli.Command{
27+
&cli.Command{
2828
Name: "chmod",
2929
Action: doChmod,
3030
},
31-
cli.Command{
31+
&cli.Command{
3232
Name: "chown",
3333
Action: doChown,
3434
},
35-
cli.Command{
35+
&cli.Command{
3636
Name: "check-aa-profile",
3737
Action: doCheckAAProfile,
3838
},
3939
/*
4040
* these are not actually used by stacker, but are entrypoints
4141
* to the code for use in the test suite.
4242
*/
43-
cli.Command{
43+
&cli.Command{
4444
Name: "testsuite-check-overlay",
4545
Action: doTestsuiteCheckOverlay,
4646
},
47-
cli.Command{
47+
&cli.Command{
4848
Name: "copy",
4949
Action: doImageCopy,
5050
},
51-
cli.Command{
51+
&cli.Command{
5252
Name: "atomfs",
53-
Subcommands: []cli.Command{
54-
cli.Command{
53+
Subcommands: []*cli.Command{
54+
&cli.Command{
5555
Name: "mount",
5656
Action: doAtomfsMount,
5757
},
58-
cli.Command{
58+
&cli.Command{
5959
Name: "umount",
6060
Action: doAtomfsUmount,
6161
},
@@ -95,52 +95,52 @@ func doTestsuiteCheckOverlay(ctx *cli.Context) error {
9595
}
9696

9797
func doImageCopy(ctx *cli.Context) error {
98-
if len(ctx.Args()) != 2 {
98+
if ctx.Args().Len() != 2 {
9999
return errors.Errorf("wrong number of args")
100100
}
101101

102102
return lib.ImageCopy(lib.ImageCopyOpts{
103-
Src: ctx.Args()[0],
104-
Dest: ctx.Args()[1],
103+
Src: ctx.Args().Get(0),
104+
Dest: ctx.Args().Get(1),
105105
Progress: os.Stdout,
106106
})
107107
}
108108

109109
func doCP(ctx *cli.Context) error {
110-
if len(ctx.Args()) != 2 {
110+
if ctx.Args().Len() != 2 {
111111
return errors.Errorf("wrong number of args")
112112
}
113113

114114
return lib.CopyThing(
115-
ctx.Args()[0],
116-
ctx.Args()[1],
115+
ctx.Args().Get(0),
116+
ctx.Args().Get(1),
117117
)
118118
}
119119

120120
func doChmod(ctx *cli.Context) error {
121-
if len(ctx.Args()) != 2 {
121+
if ctx.Args().Len() != 2 {
122122
return errors.Errorf("wrong number of args")
123123
}
124124

125125
return lib.Chmod(
126-
ctx.Args()[0],
127-
ctx.Args()[1],
126+
ctx.Args().Get(0),
127+
ctx.Args().Get(1),
128128
)
129129
}
130130

131131
func doChown(ctx *cli.Context) error {
132-
if len(ctx.Args()) != 2 {
132+
if ctx.Args().Len() != 2 {
133133
return errors.Errorf("wrong number of args")
134134
}
135135

136136
return lib.Chown(
137-
ctx.Args()[0],
138-
ctx.Args()[1],
137+
ctx.Args().Get(0),
138+
ctx.Args().Get(1),
139139
)
140140
}
141141

142142
func doCheckAAProfile(ctx *cli.Context) error {
143-
toCheck := ctx.Args()[0]
143+
toCheck := ctx.Args().Get(0)
144144
command := fmt.Sprintf("changeprofile %s", toCheck)
145145

146146
runtime.LockOSThread()
@@ -170,12 +170,12 @@ func doCheckAAProfile(ctx *cli.Context) error {
170170
}
171171

172172
func doAtomfsMount(ctx *cli.Context) error {
173-
if len(ctx.Args()) != 2 {
173+
if ctx.Args().Len() != 2 {
174174
return errors.Errorf("wrong number of args for mount")
175175
}
176176

177-
tag := ctx.Args()[0]
178-
mountpoint := ctx.Args()[1]
177+
tag := ctx.Args().Get(0)
178+
mountpoint := ctx.Args().Get(1)
179179

180180
wd, err := os.Getwd()
181181
if err != nil {
@@ -201,10 +201,10 @@ func doAtomfsMount(ctx *cli.Context) error {
201201
}
202202

203203
func doAtomfsUmount(ctx *cli.Context) error {
204-
if len(ctx.Args()) != 1 {
204+
if ctx.Args().Len() != 1 {
205205
return errors.Errorf("wrong number of args for umount")
206206
}
207207

208-
mountpoint := ctx.Args()[0]
208+
mountpoint := ctx.Args().Get(0)
209209
return atomfs.Umount(mountpoint)
210210
}

0 commit comments

Comments
 (0)