Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to provide command-line arguments to runner service containers #2139

Open
mrparkers opened this issue Sep 19, 2022 · 7 comments
Open
Labels
enhancement New feature or request Runner Feature Feature scope to the runner

Comments

@mrparkers
Copy link

Describe the enhancement
I would like to be able to provide command-line arguments to a service container.

Code Snippet
docker-compose currently handles this with the command directive:

version: "3"
services:
  keycloak:
    image: quay.io/keycloak/keycloak:19.0.2
    command: start-dev --features=preview
    environment:
    - KEYCLOAK_ADMIN=keycloak
    - KEYCLOAK_ADMIN_PASSWORD=password
    - KC_LOG_LEVEL=INFO
    - KC_DB=dev-mem
    ports:
    - 8080:8080

The API for actions could look like this:

jobs:
  test:
    services:
      keycloak:
        image: quay.io/keycloak/keycloak:19.0.2
        ports:
          - 8080:8080
        env:
          KC_DB: dev-mem
          KC_LOG_LEVEL: INFO
          KEYCLOAK_ADMIN: keycloak
          KEYCLOAK_ADMIN_PASSWORD: password
        command: start-dev --features=preview

Additional information
If you're working with a docker image that only specifies a script as the ENTRYPOINT, then there is no feasible way to use this image as a service container within GitHub Actions if you need to specify additional arguments. Here's a list of everything I tried:

  • I tried using options to set the --entrypoint flag when starting the container, but that doesn't work when trying to set arguments for the entrypoint script.
  • I tried putting a script into my repository that would run the command with the arguments I want, that I could then mount to the service container as a volume. This doesn't work because the volume mount would happen before my repository code is cloned down within the workflow.

Right now, the only possible workaround is for me to build and push my own container that uses my desired container as a base, and overrides the ENTRYPOINT to specify the arguments I want. This is not a good long-term solution, as my test suite runs on three different versions of this software, so I need to maintain three different containers that have this fix.

@mrparkers mrparkers added the enhancement New feature or request label Sep 19, 2022
@nikola-jokic
Copy link
Contributor

Hey @mrparkers,

If you are using self-hosted runners, you can leverage runner-container-hooks. With this, you can customize the way docker commands are invoked. For more information, you can find the docs here. ☺️

@mrparkers
Copy link
Author

Hi @nikola-jokic, thanks for your suggestion. Unfortunately, I am not using self-hosted runners for this project, so this solution will not work for me. Do you have any potential workarounds for this using GitHub's hosted runners?

@nikola-jokic nikola-jokic added the Runner Feature Feature scope to the runner label Oct 5, 2022
@nikola-jokic
Copy link
Contributor

Hey @mrparkers,

Unfortunately, I don't for now 😞 ... Some arguments are added by default, and I don't see an easy workaround. There is an ongoing work related to passing arguments to the ProcessInvoker, and I will keep this issue in mind for that

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2023

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 15 days.

@nickstanish
Copy link

I ran into this issue as well. It would be nice if we could modify this in the service definition, though there are some other workarounds I've found:

  1. Update the upstream Dockerfile to support changing entrypoint/command behavior with environment variables
  2. Create a downstream Dockerfile that uses the upstream one as a base image, and then modifies the entrypoint/command. This requires building the image first so that it can be used in other jobs. Though it wouldn't change often so it could be a separate build and maybe even publish to github package registry if you need it to be private
  3. Call docker/compose inside of the job steps manually instead of using services:, which would look something like below:
      - name: Start docker service on port 3000
        id: docker_service
        env:
          DOCKER_IMAGE: ${{ steps.docker_build.outputs.imageid }}
        run: |
          {
            echo "ENVVAR1=foo";
            echo "ENVVAR2=bar";
            echo "PORT=3000";
          } >> .env
          CONTAINER_ID=$(docker run --rm --network host --detach --env-file=.env "$DOCKER_IMAGE")
          echo "$CONTAINER_ID"
          docker ps
          echo "docker_container_id=$CONTAINER_ID" >> "$GITHUB_OUTPUT"
      - name: Verify health check
        # Or could check docker status to see if container healthy
        run: curl --fail -sS --retry 5 --retry-delay 5 --retry-connrefused http://127.0.0.1:3000
        # Add steps that depend on service here
      - name: Print docker container logs
        if: ${{always() && steps.docker_service.outputs.docker_container_id}}
        run: docker logs --timestamps ${{steps.docker_service.outputs.docker_container_id}}
      - name: Cleanup docker container
        if: ${{always() && steps.docker_service.outputs.docker_container_id}}
        run: docker stop ${{steps.docker_service.outputs.docker_container_id}}

@albilaga
Copy link

albilaga commented Feb 4, 2024

Is there still any other way to do this except building docker compose on the host itself for now?

@bpkroth
Copy link

bpkroth commented May 10, 2024

Also interested in this. For instance, to add extensions to a postgres service container.

bpkroth added a commit to cmu-db/benchbase that referenced this issue May 13, 2024
… CI pipeline (#510)

For testing support in #300 

Note, do to lack of support for adjusting CMD args in service container
launching (actions/runner#2139), we basically
have to manage starting the container via `docker compose` ourselves.

Luckily there are scripts for that already, and this way the CI
environment should match the local dev experience as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Runner Feature Feature scope to the runner
Projects
None yet
Development

No branches or pull requests

6 participants
@nickstanish @albilaga @mrparkers @bpkroth @nikola-jokic and others