Skip to content

Commit

Permalink
fix: allow devfile env vars to reference $PROJECT_SOURCE & $PROJECT_ROOT
Browse files Browse the repository at this point in the history
Environment variables defined in a kubernetes container can only
reference other environment variables that are declared earlier in the
list of container environment variables.

This change ensures that the $PROJECT_SOURCE and $PROJECT_ROOT
devfile environment variables are the first environment variables
defined in all workspace pod containers so that devfile environment
variables can reference $PROJECT_SOURCE and $PROJECT_ROOT.

Fix #1274

Signed-off-by: Andrew Obuchowicz <[email protected]>
  • Loading branch information
AObuchow committed Jun 28, 2024
1 parent 1360f21 commit ae31bc4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/library/container/mountSources.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ func handleMountSources(k8sContainer *corev1.Container, devfileContainer *dw.Con
return err
}

k8sContainer.Env = append(k8sContainer.Env, corev1.EnvVar{
Name: devfileConstants.ProjectsRootEnvVar,
Value: sourceMapping,
}, corev1.EnvVar{
Name: devfileConstants.ProjectsSourceEnvVar,
Value: path.Join(sourceMapping, projectsSourcePath),
})
// The $PROJECT_ROOT and $PROJECT_SOURCE environment variables must be the first
// environment variables defined in the container so that other environment variables can reference them.
k8sContainer.Env = append([]corev1.EnvVar{
{
Name: devfileConstants.ProjectsRootEnvVar,
Value: sourceMapping,
},
{
Name: devfileConstants.ProjectsSourceEnvVar,
Value: path.Join(sourceMapping, projectsSourcePath),
}}, k8sContainer.Env...)

return nil
}
Expand Down

0 comments on commit ae31bc4

Please sign in to comment.