Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

devfile-init

Example Devfile v2 showing how to run an init container in an Eclipse Che / DevWorkspace workspace that writes to .bash_profile before the main dev container starts.

How it works

Devfile v2 doesn't have a native initContainer component type, but the preStart lifecycle event turns an apply command bound to a container component into an init container in the workspace pod. Init containers listed under preStart run in order, before any of the workspace's main containers start.

For the init container's changes to be visible in your shell, it needs to write to a location that's also mounted into the main dev container — so this example defines a shared volume component mounted at /home/user in both containers.

Components

  • home — a volume component shared between the init and dev containers.
  • tools — the main dev container (universal-developer-image), with home mounted at /home/user.
  • init-bash-profile — a minimal (ubi8-minimal) container that appends an alias and an env var export to /home/user/.bash_profile. Because it's only referenced via the preStart event (never a workspace command a user runs), it's realized as an init container rather than a long-running container.

Commands & events

commands:
  - id: init-bash-profile-cmd
    apply:
      component: init-bash-profile

events:
  preStart:
    - init-bash-profile-cmd

The apply command references the init-bash-profile component, and events.preStart lists it — this is what tells the DevWorkspace Operator to run it as an init container ahead of the workspace's regular containers.

Customizing

Edit the args in the init-bash-profile component to add whatever you need in .bash_profile (aliases, exports, sourcing other scripts, etc.). Multiple commands can be listed under preStart; they run as sequential init containers in the order given.

Caveats

  • apply commands used in preStart must reference container components, not plugins.
  • The init and main containers must mount the shared volume at the same path, or the shell won't see the file where it expects it.
  • postStart is a related but different event — it runs an exec command inside an already-running container rather than as a separate init container.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors