Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build user to test pipeline environments #1747

Merged
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
108 changes: 69 additions & 39 deletions pkg/build/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ const (
homeBuild = "/home/build"
)

var (
gid1000 = uint32(1000)
)

func defaultEnv(opts ...func(*apko_types.ImageConfiguration)) apko_types.ImageConfiguration {
env := apko_types.ImageConfiguration{
Accounts: types.ImageAccounts{
Groups: []types.Group{{GroupName: "build", GID: 1000, Members: []string{"build"}}},
Users: []apko_types.User{{UserName: "build", UID: 1000, GID: &gid1000}},
},
}

for _, opt := range opts {
opt(&env)
}

return env
}

func TestBuildWorkspaceConfig(t *testing.T) {
tmpDir := t.TempDir()
// realpath is used to get the real path of the temp dir
Expand Down Expand Up @@ -151,6 +170,7 @@ func TestConfigurationLoad(t *testing.T) {
Resources: &config.Resources{},
},
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{
{
Name: "hello",
Expand All @@ -161,27 +181,31 @@ func TestConfigurationLoad(t *testing.T) {
Subpackages: []config.Subpackage{{
Name: "cats",
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{{
Runs: "cats are angry",
}},
},
}, {
Name: "dogs",
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{{
Runs: "dogs are loyal",
}},
},
}, {
Name: "turtles",
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{{
Runs: "turtles are slow",
}},
},
}, {
Name: "donatello",
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{
{
Runs: "donatello's color is purple",
Expand All @@ -194,46 +218,54 @@ func TestConfigurationLoad(t *testing.T) {
},
}, {
Name: "leonardo",
Test: &config.Test{Pipeline: []config.Pipeline{
{
Runs: "leonardo's color is blue",
},
{
Uses: "go/build",
With: map[string]string{"packages": "blue"},
},
}},
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{
{
Runs: "leonardo's color is blue",
},
{
Uses: "go/build",
With: map[string]string{"packages": "blue"},
},
}},
}, {
Name: "michelangelo",
Test: &config.Test{Pipeline: []config.Pipeline{
{
Runs: "michelangelo's color is orange",
},
{
Uses: "go/build",
With: map[string]string{"packages": "orange"},
},
}},
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{
{
Runs: "michelangelo's color is orange",
},
{
Uses: "go/build",
With: map[string]string{"packages": "orange"},
},
}},
}, {
Name: "raphael",
Test: &config.Test{Pipeline: []config.Pipeline{
{
Runs: "raphael's color is red",
},
{
Uses: "go/build",
With: map[string]string{"packages": "red"},
},
}},
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{
{
Runs: "raphael's color is red",
},
{
Uses: "go/build",
With: map[string]string{"packages": "red"},
},
}},
}, {
Name: "simple",
Test: &config.Test{Pipeline: []config.Pipeline{
{
Runs: "simple-runs",
}, {
Uses: "simple-uses",
},
}},
Test: &config.Test{
Environment: defaultEnv(),
Pipeline: []config.Pipeline{
{
Runs: "simple-runs",
}, {
Uses: "simple-uses",
},
}},
}},
},
}, {
Expand All @@ -246,11 +278,9 @@ func TestConfigurationLoad(t *testing.T) {
Resources: &config.Resources{},
},
Test: &config.Test{
Environment: types.ImageConfiguration{
Contents: types.ImageContents{
Packages: []string{"busybox", "python-3"},
},
},
Environment: defaultEnv(func(env *apko_types.ImageConfiguration) {
env.Contents.Packages = []string{"busybox", "python-3"}
}),
Pipeline: []config.Pipeline{
{
Runs: "python3 ./py3-pandas-test.py\n",
Expand Down
18 changes: 18 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,15 @@ func ParseConfiguration(_ context.Context, configurationFilePath string, opts ..
Members: []string{"build"},
}
cfg.Environment.Accounts.Groups = append(cfg.Environment.Accounts.Groups, grp)
if cfg.Test != nil {
cfg.Test.Environment.Accounts.Groups = append(cfg.Test.Environment.Accounts.Groups, grp)
}
for _, sub := range cfg.Subpackages {
if sub.Test == nil || len(sub.Test.Pipeline) == 0 {
continue
}
sub.Test.Environment.Accounts.Groups = append(sub.Test.Environment.Accounts.Groups, grp)
}

gid1000 := uint32(1000)
usr := apko_types.User{
Expand All @@ -1366,6 +1375,15 @@ func ParseConfiguration(_ context.Context, configurationFilePath string, opts ..
GID: apko_types.GID(&gid1000),
}
cfg.Environment.Accounts.Users = append(cfg.Environment.Accounts.Users, usr)
if cfg.Test != nil {
cfg.Test.Environment.Accounts.Users = append(cfg.Test.Environment.Accounts.Users, usr)
}
for _, sub := range cfg.Subpackages {
if sub.Test == nil || len(sub.Test.Pipeline) == 0 {
continue
}
sub.Test.Environment.Accounts.Users = append(sub.Test.Environment.Accounts.Users, usr)
}

// Merge environment file if needed.
if envFile := options.envFilePath; envFile != "" {
Expand Down
Loading