I'm trying to use sonarsource/sonar-scanner-cli as a kubernetes container, so I do this in a yaml:
- name: "sonarqube-scan-{{ .Values.git.commitID }}"
  image: "{{ .Values.harbor.host }}/{{ .Values.harbor.cache }}/sonarsource/sonar-scanner-cli"
  env:
    # Sonarqube's URL
    - name: SONAR_HOST_URL
      valueFrom:
        secretKeyRef:
          name: sonarqube
          key: sonar-url
    # Auth token of sonarqube's bot
    - name: SONAR_LOGIN
      valueFrom:
        secretKeyRef:
          name: sonar-bot
          key: sonar-token
  volumeMounts:
    - mountPath: /usr/src
      name: initrepoNow, I want to do some pre-setup before the sonarsource/sonar-scanner-cl regular run and parse the docker container's run output for some other works. If this is a shell script, I do like:
$before.sh
$sonar-scanner-cl.sh | after.shI guess I can build a new docker image which is FROM sonarsource/sonar-scanner-cl, and put processes in before.sh and after.sh in its run script, but I don't know how to call the original sonarsource/sonar-scanner-cl run commands. What are the actual commands?
Or, alternatively, does kubernetes have a way to do this?
Here's how one can modify container commands without building another image.
docker pull sonarsource/sonar-scanner-clidocker inspect sonarsource/sonar-scanner-cliYou should get something like this:
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"sonar-scanner\"]" <- arguments
            ],
            "WorkingDir": "/usr/src",
            "Entrypoint": [ <- executable
                "/usr/bin/entrypoint.sh"
            ],
Entrypoint is what will be executed and CMD [...] (not Cmd) are the arguments for the executable. In a human-friendly format that equals to:
#      entrypoint          args
/usr/bin/entrypoint.sh sonar-scannerNow in this case we have a script that is being executed so there are two options.
docker run --rm --entrypoint="" sonarsource/sonar-scanner-cli /bin/cat /usr/bin/entrypoint.sh > entrypoint.shentrypoint.sh as you like, then put its contents into a configMap.0755)Note that this may not work with some images (ones with no shell inside).
- name: "sonarqube-scan-{{ .Values.git.commitID }}"
  image: "{{ .Values.harbor.host }}/{{ .Values.harbor.cache }}/sonarsource/sonar-scanner-cli"
  command: # this is entrypoint in k8s API
    - /bin/sh
    - -c
  args:  # this goes instead of CMD
    - "before.sh && /usr/bin/entrypoint.sh sonar-scanner && after.sh"
                 # | original command and args          |