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/args
properties are not explicitly specified in the devfile - executes the specified command as the Entrypoint cmd if the
command/args
properties are explicitly specified in the devfile
What it does?
- Adds a validation to check that the
command/args
properties are only valid when specified withoverrideCommand: false
in the devfile - Replaces container Entrypoint command with
tail -f /dev/null
for 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
overrideCommand: false
and default container entrypoint command
1. Devfile | Workspace/ Pod Status |
---|---|
overrideCommand disabled but command/args not specified ![]() |
Stuck in Starting ![]() CrashLoopBackOff ![]() |
- The
go-container-1
executes and exits prematurely and the pod is stuck in theCrashLoopBackOff
state. This is becauseoverrideCommand: false
is provided without specifying command/args. - In this case the container's default entrypoint cmd/args are executed. The
alpine
based container does not keepalive and exits after execution.
overrideCommand: false
with user specified entrypoint command & overrideCommand: true
without any entrypoint command specified
2. Devfile | Workspace/ Pod / Container Status | postStart executed |
---|---|---|
![]() |
![]() ![]() |
![]() |
- The
go-container-1
executes and stays alive becauseoverrideCommand: false
is provided along with command/args:command: ['tail'] args: ['-f', '/dev/null']
- The
go-container-2
explicitly setsoverrideCommand: true
, in this case the container entrypoint cmd is by default replaced with thetail -f /dev/null
keep alive command. - The
tooling-container
does not explicitly setoverrideCommand
but it's entrypoint cmd is also replaced because that is the default behavior when theoverrideCommand
attribute is not explicitly set tofalse
- As a result all the containers are marked ready, pod is in
Running
state, 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
command
andargs
attributes are only allowed whenoverrideCommand
is 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/workspaces
and 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 thedevcontainer
standard"overrideCommand"
attribute -
Add validation that command/args
if specified along withoverrideCommand: true
is 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.