Skip to content

Commit

Permalink
Make the bundle user details global to the build package. Required if…
Browse files Browse the repository at this point in the history
… we allow subsituting build variables in parameters. If we choose not, we can revert this easily.
  • Loading branch information
Rich Baird authored and Rich Baird committed Jul 15, 2022
1 parent d7009a2 commit d66127b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ var (
// BUNDLE_DIR is the directory where the bundle is located in the CNAB execution environment.
BUNDLE_DIR = "/cnab/app"

// BUNDLE_UID is the user id assigned to the user executing the bundle
BUNDLE_UID = 65532

// BUNDLE_GID is the group assigned to the user executing the bundle
// Defaults to root
BUNDLE_GID = 0

// BUNDLE_USER is the username assigned to the user executing the bundle
BUNDLE_USER="nonroot"

// PORTER_MIXINS_TOKEN can control where mixin instructions will be placed in
// Dockerfile.
PORTER_MIXINS_TOKEN = "# PORTER_MIXINS"
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/dockerfile-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ func (g *DockerfileGenerator) buildMixinsSection(ctx context.Context) ([]string,
func (g *DockerfileGenerator) buildInitSection() []string {
return []string{
"ARG BUNDLE_DIR",
"ARG BUNDLE_UID=65532",
"ARG BUNDLE_USER=nonroot",
"ARG BUNDLE_GID=0",
fmt.Sprintf("ARG BUNDLE_UID=%d", BUNDLE_UID),
fmt.Sprintf("ARG BUNDLE_USER=%s", BUNDLE_USER),
fmt.Sprintf("ARG BUNDLE_GID=%d", BUNDLE_GID),
// Create a non-root user that is in the root group with the specified id and a home directory
"RUN useradd ${BUNDLE_USER} -m -u ${BUNDLE_UID} -g ${BUNDLE_GID} -o",
}
Expand Down

0 comments on commit d66127b

Please sign in to comment.