I have following repo structure.
├── .cosmos
│ └── .config
├── .github
│ └── workflows
│ ├── plan.yml
│ └── update.yml
├── .gitignore
├── README.md
├── assets
│ ├── 1.png
│ ├── 2.png
│ └── 3.png
└── us-west-2
├── applications
│ └── test.json
└── cluster-config.json
And following GH Action yaml file.
plan.yml
name: Cosmos Plan
on:
pull_request:
paths:
- "**/applications/*.json"
- "**/cluster-config.json"
jobs:
find:
name: Find edited clusters
runs-on: ubuntu-latest
outputs:
new: ${{ steps.find.outputs.new }}
modified: ${{ steps.find.outputs.modified }}
anyNew: ${{ steps.find.outputs.anyNew }}
anyModified: ${{ steps.find.outputs.anyModified }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout cosmos-find action
uses: actions/checkout@v2
with:
repository: this/cosmos-find
ref: refs/tags/v3
path: ./.github/actions/cosmos-find
token: ${{ secrets.COSMOS_PAT }}
- name: Cosmos find
id: find
uses: ./.github/actions/cosmos-find
create:
needs: find
if: ${{ needs.find.outputs.anyNew == 'true' }}
name: Create ${{ matrix.cluster }} cluster (plan)
runs-on: ubuntu-latest
container:
image: ghcr.io/this/cosmos:v2.3.0-prerelease
credentials:
username: ${{ github.actor }}
password: ${{ secrets.COSMOS_PAT }}
volumes:
- ${{ github.workspace }}/.cosmos/.config:/github/home/.cosmos/.config
strategy:
fail-fast: false
matrix: ${{fromJson(needs.find.outputs.new)}}
steps:
- name: Check cosmos config file
run: |
ls -al /github/home/.cosmos/.config
cat /github/home/.cosmos/.config
I want to mount .cosmos/.config file from my current repository to the container that I am running the action on.
According to this Github Workflow Syntax https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainervolumes , I should be able to do that.
I have specified volumes with following code block in my github action yml file.
container:
image: ghcr.io/this/cosmos:v2.3.0-prerelease
credentials:
username: ${{ github.actor }}
password: ${{ secrets.COSMOS_PAT }}
volumes:
- ${{ github.workspace }}/.cosmos/.config:/github/home/.cosmos/.config
I can see that during the Initialize Containers phase, GH Action is able to mount the file successfully. ( below logs )
/usr/bin/docker create --name
ee297063e4994cb488db28bfeadb1b8e_ghcriothiscosmosv230prerelease_487bad
--label 8a33c1 --workdir /__w/virtualization-ci/virtualization-ci --network github_network_492eeddeb3ec4aca8594cb85567cea02 -e "HOME=/github/home" -e GITHUB_ACTIONS=true -e CI=true -v
"/var/run/docker.sock":"/var/run/docker.sock" **-v
"/home/runner/work/virtualization-ci/virtualization-ci/.cosmos/.config":"/github/home/.cosmos/.config"**
-v "/home/runner/work":"/__w" -v "/home/runner/runners/2.278.0/externals":"/__e":ro -v
"/home/runner/work/_temp":"/__w/_temp" -v
"/home/runner/work/_actions":"/__w/_actions" -v
"/opt/hostedtoolcache":"/__t" -v
"/home/runner/work/_temp/_github_home":"/github/home" -v
"/home/runner/work/_temp/_github_workflow":"/github/workflow"
--entrypoint "tail" ghcr.io/this/cosmos:v2.3.0-prerelease "-f" "/dev/null"
But when I try to list and cat that file through GH Step Check cosmos config file, its telling me that its a directory. ( Error and Failure )
Run ls -al /github/home/.cosmos/.config
ls -al /github/home/.cosmos/.config
cat /github/home/.cosmos/.config
shell: sh -e {0}
cat: /github/home/.cosmos/.config: Is a directory
total 8
drwxr-xr-x 2 root root 4096 May 21 16:50 .
drwxr-xr-x 3 root root 4096 May 21 16:50 ..
Error: Process completed with exit code 1.
I have tried to mount the file on my local docker container by giving the full path and it does so without any issues.
Thanks.
You should be able to do this pretty easily with the cache action. Just cache that file in one job and load that cache in the following job as in the example here
name: Caching Primes
on: push
jobs: build: runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v3
with:
path: prime-numbers
key: ${{ runner.os }}-primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: /generate-primes.sh -d prime-numbers
- name: Use Prime Numbers
run: /primes.sh -d prime-numbers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With