Skip to content

Commit

Permalink
Define build user string in one place
Browse files Browse the repository at this point in the history
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
  • Loading branch information
egibs committed Feb 7, 2025
1 parent 1d50cef commit 18f9128
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
11 changes: 5 additions & 6 deletions pkg/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var requireErrInvalidConfiguration require.ErrorAssertionFunc = func(t require.T
// TestConfiguration_Load is the main set of tests for loading a configuration
// file. When in doubt, add your test here.
func TestConfiguration_Load(t *testing.T) {
gid1000 := uint32(1000)
tests := []struct {
name string
skipConfigCleanStep bool
Expand Down Expand Up @@ -209,8 +208,8 @@ func TestConfiguration_Load(t *testing.T) {
"GOPATH": "/var/cache/melange/go",
},
Accounts: apko_types.ImageAccounts{
Users: []apko_types.User{{UserName: "build", UID: 1000, GID: apko_types.GID(&gid1000)}},
Groups: []apko_types.Group{{GroupName: "build", GID: 1000, Members: []string{"build"}}},
Users: []apko_types.User{{UserName: buildUser, UID: 1000, GID: apko_types.GID(&gid1000)}},
Groups: []apko_types.Group{{GroupName: buildUser, GID: 1000, Members: []string{buildUser}}},
},
},
Subpackages: []config.Subpackage{},
Expand Down Expand Up @@ -285,14 +284,14 @@ package:
}
gid1000 := uint32(1000)
expected.Environment.Accounts.Users = []apko_types.User{{
UserName: "build",
UserName: buildUser,
UID: 1000,
GID: apko_types.GID(&gid1000),
}}
expected.Environment.Accounts.Groups = []apko_types.Group{{
GroupName: "build",
GroupName: buildUser,
GID: 1000,
Members: []string{"build"},
Members: []string{buildUser},
}}
expected.Environment.Environment = map[string]string{
"HOME": "/home/build",
Expand Down
8 changes: 4 additions & 4 deletions pkg/build/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ const (
homeBuild = "/home/build"
)

var (
gid1000 = uint32(1000)
)
const buildUser = "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"}}},
Groups: []types.Group{{GroupName: "build", GID: 1000, Members: []string{buildUser}}},
Users: []apko_types.User{{UserName: "build", UID: 1000, GID: apko_types.GID(&gid1000)}},
},
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import (
"chainguard.dev/melange/pkg/util"
)

const purlTypeAPK = "apk"
const (
buildUser = "build"
purlTypeAPK = "apk"
)

type Trigger struct {
// Optional: The script to run
Expand Down Expand Up @@ -1361,12 +1364,12 @@ func ParseConfiguration(_ context.Context, configurationFilePath string, opts ..

// TODO: validate that subpackage ranges have been consumed and applied
usr := apko_types.User{
UserName: "build",
UserName: buildUser,
UID: 1000,
}

grp := apko_types.Group{
GroupName: "build",
GroupName: buildUser,
GID: 1000,
Members: []string{usr.UserName},
}
Expand Down

0 comments on commit 18f9128

Please sign in to comment.