Skip to content

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?

  1. Adds a validation to check that the command/args properties are only valid when specified with overrideCommand: false in the devfile
  2. Replaces container Entrypoint command with tail -f /dev/null for all containers specified in the devfile that don't explicitly disable overrideCommand
  3. Internal workspace containers that have the gl- don't have their Entrypoint cmd replaced

References

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 Screenshot_2025-07-07_at_5.17.07_PM Stuck in Starting Screenshot_2025-07-07_at_5.17.21_PM CrashLoopBackOff Screenshot_2025-07-07_at_5.17.32_PM
  • The go-container-1 executes and exits prematurely and the pod is stuck in the CrashLoopBackOff state. This is because overrideCommand: 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.

2. overrideCommand: false with user specified entrypoint command & overrideCommand: true without any entrypoint command specified

Devfile Workspace/ Pod / Container Status postStart executed
Screenshot_2025-07-07_at_5.18.28_PM Screenshot_2025-07-07_at_5.19.53_PM Screenshot_2025-07-07_at_5.20.13_PM logs-outpu
  • The go-container-1 executes and stays alive because overrideCommand: false is provided along with command/args: command: ['tail'] args: ['-f', '/dev/null']
  • The go-container-2 explicitly sets overrideCommand: true, in this case the container entrypoint cmd is by default replaced with the tail -f /dev/null keep alive command.
  • The tooling-container does not explicitly set overrideCommand but it's entrypoint cmd is also replaced because that is the default behavior when the overrideCommand attribute is not explicitly set to false
  • 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 and args attributes are only allowed when overrideCommand 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 the devcontainer standard "overrideCommand" attribute
  • Add validation that command/args if specified along with overrideCommand: 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.

Edited by Daniyal Arshad

Merge request reports

Loading