1
0
mirror of https://github.com/openshift/source-to-image.git synced 2026-02-05 12:44:54 +01:00

Add support for assemble-user label

Add support for assemble-user label

Add support for assemble-user label

Add support for assemble-user label

Add support for assemble-user label

Add support for assemble-user label
This commit is contained in:
Ricardo Pchevuzinske Katz
2017-08-15 22:28:09 -03:00
committed by Ricardo Pchevuzinske Katz
parent aea5c8fa96
commit 48d9ae3ce9
4 changed files with 36 additions and 0 deletions

View File

@@ -76,6 +76,13 @@ and placing them into the appropriate directories inside the image. The workflow
1. Build any application artifacts.
1. Install the artifacts into locations appropriate for running.
In the case you need to assemble the Image using a different user than the runtime user defined
in ``USER`` directive of Dockerfile, you can achive this by the following ways:
1. use the `--assemble-user` in cmd line
1. use the label `io.openshift.s2i.assemble-user`
#### Example `assemble` script:
**NOTE**: All the examples are written in [Bash](http://www.gnu.org/software/bash/)

View File

@@ -23,10 +23,20 @@ func GetStrategy(client docker.Client, config *api.Config) (build.Builder, api.B
func Strategy(client docker.Client, config *api.Config, overrides build.Overrides) (build.Builder, api.BuildInfo, error) {
var builder build.Builder
var buildInfo api.BuildInfo
var err error
fs := fs.NewFileSystem()
startTime := time.Now()
if config.AssembleUser, err = docker.GetAssembleUser(client, config); err != nil {
buildInfo.FailureReason = utilstatus.NewFailureReason(
utilstatus.ReasonPullBuilderImageFailed,
utilstatus.ReasonMessagePullBuilderImageFailed,
)
return nil, buildInfo, err
}
image, err := docker.GetBuilderImage(client, config)
buildInfo.Stages = api.RecordStageAndStepInfo(buildInfo.Stages, api.StagePullImages, api.StepPullBuilderImage, startTime, time.Now())
if err != nil {

View File

@@ -50,6 +50,9 @@ const (
// The previous name of this label was 'io.s2i.scripts-url'. This is now
// deprecated.
ScriptsURLLabel = api.DefaultNamespace + "scripts-url"
// AssembleUserLabel is the User that will be used in the assemble process
AssembleUserLabel = api.DefaultNamespace + "assemble-user"
// DestinationLabel is the name of the Docker image LABEL that tells S2I where
// to place the artifacts (scripts, sources) in the builder image.
// The previous name of this label was 'io.s2i.destination'. This is now

View File

@@ -363,3 +363,19 @@ func GetDefaultDockerConfig() *api.DockerConfig {
return cfg
}
// GetAssembleUser finds an assemble user on the given image.
// This functions receives the config to check if the AssembleUser was defined in command line
// If the cmd is blank, it tries to fetch the value from the Builder Image defined Label (assemble-user)
// Otherwise it follows the common flow, using the USER defined in Dockerfile
func GetAssembleUser(client Client, config *api.Config) (string, error) {
if len(config.AssembleUser) > 0 {
return config.AssembleUser, nil
}
d := New(client, config.PullAuthentication)
imageData, err := d.GetLabels(config.BuilderImage)
if err != nil {
return "", err
}
return imageData[AssembleUserLabel], nil
}