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

actions: mount shared cache in run tasks #241

Open
robwhitby opened this issue Mar 12, 2024 · 4 comments
Open

actions: mount shared cache in run tasks #241

robwhitby opened this issue Mar 12, 2024 · 4 comments
Labels
area: release enhancement New feature or request

Comments

@robwhitby
Copy link
Contributor

slack thread

it would be great to be able to access the halfpipe shared/team cache in actions run tasks

the cache NFS volume it is already mounted on the runner at /mnt/halfpipe/shared-cache

ideally in a run task the team's sub-directory would be mounted in the container like:

docker run -v `/mnt/halfpipe/shared-cache/<team>:/var/halfpipe/shared-cache ...

this is not possible currently because the github step syntax does not allow configuring volume options.

@robwhitby robwhitby added enhancement New feature or request area: release labels Mar 12, 2024
@robwhitby
Copy link
Contributor Author

halfpipe task

- type: run
  name: hello
  script: \echo hello
  docker:
    image: alpine
  vars:
   MY_VAR: myvar

current workflow output

- name: hello
  uses: docker://alpine
  with:
    args: -c "cd run-task; \echo MY_VAR=$MY_VAR"
    entrypoint: /bin/sh
  env:
    MY_VAR: myvar

option of rendering the docker command ourselves:

- name: hello
  run: |
    docker run \
      --workdir /github/workspace/run-task \
      --rm \
      -e "ARTIFACTORY_PASSWORD" \
      -e "ARTIFACTORY_URL" \
      -e "ARTIFACTORY_USERNAME" \
      -e "BUILD_VERSION" \
      -e "GIT_REVISION" \
      -e "RUNNING_IN_CI" \
      -e "VAULT_ROLE_ID" \
      -e "VAULT_SECRET_ID" \
      -e "INPUT_ARGS" \
      -e "INPUT_ENTRYPOINT" \
      -e "HOME" \
      -e "GITHUB_JOB" \
      -e "GITHUB_REF" \
      -e "GITHUB_SHA" \
      -e "GITHUB_REPOSITORY" \
      -e "GITHUB_REPOSITORY_OWNER" \
      -e "GITHUB_REPOSITORY_OWNER_ID" \
      -e "GITHUB_RUN_ID" \
      -e "GITHUB_RUN_NUMBER" \
      -e "GITHUB_RETENTION_DAYS" \
      -e "GITHUB_RUN_ATTEMPT" \
      -e "GITHUB_REPOSITORY_ID" \
      -e "GITHUB_ACTOR_ID" \
      -e "GITHUB_ACTOR" \
      -e "GITHUB_TRIGGERING_ACTOR" \
      -e "GITHUB_WORKFLOW" \
      -e "GITHUB_HEAD_REF" \
      -e "GITHUB_BASE_REF" \
      -e "GITHUB_EVENT_NAME" \
      -e "GITHUB_SERVER_URL" \
      -e "GITHUB_API_URL" \
      -e "GITHUB_GRAPHQL_URL" \
      -e "GITHUB_REF_NAME" \
      -e "GITHUB_REF_PROTECTED" \
      -e "GITHUB_REF_TYPE" \
      -e "GITHUB_WORKFLOW_REF" \
      -e "GITHUB_WORKFLOW_SHA" \
      -e "GITHUB_WORKSPACE" \
      -e "GITHUB_EVENT_PATH" \
      -e "GITHUB_PATH" \
      -e "GITHUB_ENV" \
      -e "GITHUB_STEP_SUMMARY" \
      -e "GITHUB_STATE" \
      -e "GITHUB_OUTPUT" \
      -e "GITHUB_ACTION" \
      -e "GITHUB_ACTION_REPOSITORY" \
      -e "GITHUB_ACTION_REF" \
      -e "RUNNER_OS" \
      -e "RUNNER_ARCH" \
      -e "RUNNER_NAME" \
      -e "RUNNER_ENVIRONMENT" \
      -e "RUNNER_TOOL_CACHE" \
      -e "RUNNER_TEMP" \
      -e "RUNNER_WORKSPACE" \
      -e "ACTIONS_RUNTIME_URL" \
      -e "ACTIONS_RUNTIME_TOKEN" \
      -e "ACTIONS_CACHE_URL" \
      -e "ACTIONS_RESULTS_URL" \
      -e GITHUB_ACTIONS=true \
      -e CI=true \
      -e MY_VAR \
      --entrypoint "/bin/sh" \
      -v "/mnt/halfpipe/shared-cache/my-team":"/var/halfpipe/shared-cache" \
      -v "/var/run/docker.sock":"/var/run/docker.sock" \
      -v "/home/runner/_work/_temp/_github_home":"/github/home" \
      -v "/home/runner/_work/_temp/_github_workflow":"/github/workflow" \
      -v "/home/runner/_work/_temp/_runner_file_commands":"/github/file_commands" \
      -v "/home/runner/_work/ee-test-actions/ee-test-actions":"/github/workspace" \
      alpine \
      -c "\echo MY_VAR=$MY_VAR"
  env:
    MY_VAR: myvar

@robwhitby
Copy link
Contributor Author

robwhitby commented Mar 12, 2024

not very keen on this option, feels very brittle if github change anything e.g. directory structure or env vars

@robwhitby
Copy link
Contributor Author

there is also this approach but hard to tell how official it really is :)
https://github.com/actions/runner-container-hooks

@dhs3000
Copy link
Contributor

dhs3000 commented Mar 26, 2024

@robwhitby Are there environment variables for those /home/runner/_work/_temp/* directories that maybe could be used instead of hardcoding?

Could the following add all github-provided environment variables?

# shell pseudo code:
CMD=$(cat <<EOF
docker run \
  --workdir /github/workspace/run-task \
  --rm \
  -e "ARTIFACTORY_PASSWORD" \
  -e "ARTIFACTORY_URL" \
  -e "ARTIFACTORY_USERNAME" \
  -e "BUILD_VERSION" \
  -e "GIT_REVISION" \
  -e "RUNNING_IN_CI" \
  -e "VAULT_ROLE_ID" \
  -e "VAULT_SECRET_ID" \
  -e GITHUB_ACTIONS=true \
  -e CI=true \  
  -e "INPUT_ARGS" \
  -e "INPUT_ENTRYPOINT" \
  -e "HOME" \
  $(env | grep "GITHUB_") \
  $(env | grep "RUNNER_") \
  $(env | grep "ACTIONS_") \
  -e MY_VAR \
  --entrypoint "/bin/sh" \
  -v "/mnt/halfpipe/shared-cache/my-team":"/var/halfpipe/shared-cache" \
  -v "/var/run/docker.sock":"/var/run/docker.sock" \
  -v "/home/runner/_work/_temp/_github_home":"/github/home" \
  -v "/home/runner/_work/_temp/_github_workflow":"/github/workflow" \
  -v "/home/runner/_work/_temp/_runner_file_commands":"/github/file_commands" \
  -v "/home/runner/_work/ee-test-actions/ee-test-actions":"/github/workspace" \
  alpine \
  -c "\echo MY_VAR=$MY_VAR"
EOF
)
eval "$CMD"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: release enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants