Skip to content

Commit

Permalink
Update default entrypoint script
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <[email protected]>
  • Loading branch information
dkwon17 committed Apr 19, 2024
1 parent 953df89 commit f99d0e3
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions pkg/library/home/persistentHome.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,36 @@ func addInitContainer(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec, initCon
}

func inferInitContainer(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) *v1alpha2.Container {
var firstUnflattenedComponent v1alpha2.Component
var nonImportedComponent v1alpha2.Component
for _, component := range dwTemplateSpec.Components {
if component.Container == nil {
continue
}

var err error
component.Attributes.Get(constants.MergedContributionsAttribute, &err)
if err == nil {
firstUnflattenedComponent = component
pluginSource := component.Attributes.GetString(constants.PluginSourceAttribute, nil)
if pluginSource == "" || pluginSource == "parent" {
// First, non-imported container component is selected
nonImportedComponent = component
break
}
}

if firstUnflattenedComponent.Name != "" {
image := firstUnflattenedComponent.Container.Image
command := []string{"/bin/sh", "-c", "/entrypoint.sh || true"}
createOutFile := "touch /home/user/.init-persistent-home"
runSetupScript := `([ -n "$HOME_SETUP_SCRIPT" ] && [ -f "$HOME_SETUP_SCRIPT" ] && echo "Running $HOME_SETUP_SCRIPT" && (source "$HOME_SETUP_SCRIPT" || true))`
runStow := `
(command -v stow > /dev/null && \
STOW_COMPLETE=/home/user/.stow_completed && \
[ ! -f $STOW_COMPLETE ] && \
echo "Running/ stow" && \
stow . -t /home/user/ -d /home/tooling/ --no-folding --adopt -v 2 > /tmp/stow.log 2>&1 && \
cp /home/tooling/.viminfo /home/user/.viminfo && \
cp /home/tooling/.bashrc /home/user/.bashrc && \
cp /home/tooling/.bash_profile /home/user/.bash_profile && \
touch $STOW_COMPLETE
)`
if nonImportedComponent.Name != "" {
image := nonImportedComponent.Container.Image
command := []string{"/bin/sh", "-c", "(" + createOutFile + " && " + runSetupScript + " || " + runStow + " || true) > /home/user/.init-persistent-home 2>&1"}

return &v1alpha2.Container{
Image: image,
Expand Down

0 comments on commit f99d0e3

Please sign in to comment.