Add support for preserving container entrypoint cmd
Issue: Support preserving default ENTRYPOINT/CMD for c... (#392853 - closed)
What does this MR do and why?
Adds support for a new (boolean) custom attribute in the devfile: overrideCommand
overrideCommand defaults to true for the main component (having attribute gl/inject-editor: true) when not specified in the devfile.
overrideCommand defaults to false for all other components when not specified in the devfile.
This attribute helps to determine whether we should override the Entrypoint command of the specified containers with a keep alive op:
tail -f /dev/null
When overrideCommand is set to false:
- default Entrypoint cmd of the container is executed if the
command/argsproperties are not explicitly specified in the devfile - executes the specified command as the Entrypoint cmd if the
command/argsproperties are explicitly specified in the devfile
What it does?
- Adds a validation to check that the
command/argsproperties are only valid when specified withoverrideCommand: falsein the devfile - Replaces container Entrypoint command with
tail -f /dev/nullfor all containers specified in the devfile that don't explicitly disableoverrideCommand - Internal workspace containers that have the
gl-don't have their Entrypoint cmd replaced
References
- https://containers.dev/implementors/json_reference/
- https://devfile.io/docs/2.0.0/adding-container-component
Screenshots or screen recordings
This MR does not contain any UI changes
1. overrideCommand: false and default container entrypoint command
| Devfile | Workspace/ Pod Status |
|---|---|
overrideCommand disabled but command/args not specified
|
Stuck in Starting CrashLoopBackOff
|
- The
go-container-1executes and exits prematurely and the pod is stuck in theCrashLoopBackOffstate. This is becauseoverrideCommand: falseis provided without specifying command/args. - In this case the container's default entrypoint cmd/args are executed. The
alpinebased container does not keepalive and exits after execution.
2. overrideCommand: false with user specified entrypoint command & overrideCommand: true without any entrypoint command specified
| Devfile | Workspace/ Pod / Container Status | postStart executed |
|---|---|---|
![]() |
|
![]() |
- The
go-container-1executes and stays alive becauseoverrideCommand: falseis provided along with command/args:command: ['tail'] args: ['-f', '/dev/null'] - The
go-container-2explicitly setsoverrideCommand: true, in this case the container entrypoint cmd is by default replaced with thetail -f /dev/nullkeep alive command. - The
tooling-containerdoes not explicitly setoverrideCommandbut it's entrypoint cmd is also replaced because that is the default behavior when theoverrideCommandattribute is not explicitly set tofalse - As a result all the containers are marked ready, pod is in
Runningstate, workspace is started and postStart evenets are executed successfully.
How to set up and validate locally
- Setup workspaces locally following this guide
- Checkout this branch and add a devfile to any of your projects.
- Example devfile:
schemaVersion: 2.2.0
components:
- name: tooling-container
attributes:
gl/inject-editor: true
container:
image: "registry.gitlab.com/gitlab-org/remote-development/gitlab-remote-development-docs/ubuntu:22.04"
endpoints:
- name: http-3000
targetPort: 3000
exposure: internal
secure: false
- name: go-container-1
attributes:
overrideCommand: false
container:
image: "alpine:latest"
command: ['tail']
args: ['-f', '/dev/null']
- name: go-container-2
attributes:
overrideCommand: true
container:
image: "alpine:latest"
commands:
- id: go-container-command-1
exec:
component: go-container-1
commandLine: /bin/sh -c 'echo "GO CONTAINER COMMAND" > /projects/workspace-logs/go_container_test_1.log'
- id: go-container-command-2
exec:
component: go-container-2
commandLine: /bin/sh -c 'echo "GO CONTAINER COMMAND" > /projects/workspace-logs/go_container_test_2.log'
events:
postStart:
- go-container-command-1
- go-container-command-2
- Container
commandandargsattributes are only allowed whenoverrideCommandis set to false - Check that the correct validation errors are returned when these are provided without explicitly setting overrideCommand to false. - Then go to
http://gdk.test:3000/-/remote_development/workspacesand create a new workspace for that project. - Open the workspace, check that the postStart commands are executed correctly and the log files are created at
../workspace-logs/. - You may also check that in case when overrideCommand is set to false without specifying any command/args, that the default entrypoint command of the container is executed.
MR acceptance checklist
-
Add support for custom devfile attribute overrideCommand. This should function the same as thedevcontainerstandard"overrideCommand"attribute -
Add validation that command/argsif specified along withoverrideCommand: trueis not valid devfile schema. -
Update the fixture devfile that contains all of the possible devfile entries
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.






