Skip to content

Commit

Permalink
GitHub actions: restore and load images if specified for test
Browse files Browse the repository at this point in the history
In case when we want to run test suite against newly build EVE from PR
we don't want to store it dockerhub, because it just takes up the space
and bandwitdth of dockerhub.
This patch introduces option to cache docker images and load them for testing

Signed-off-by: Pavel Abramov <[email protected]>
  • Loading branch information
uncleDecart committed Dec 6, 2023
1 parent 9611e40 commit f2b1535
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ inputs:
type: bool
eve_image:
type: string
eve_image_cache_key:
type: string

runs:
using: 'composite'
Expand Down Expand Up @@ -53,6 +55,22 @@ runs:
./eden config set default --key=eve.cpu --value=2
shell: bash
working-directory: "./eden"
- name: Restore cache if specified
if: |
inputs.eve_image_cache_key != "" &&
inputs.eve_image != ""
uses: action/cache/restore@v3
with:
path: inputs.eve_image
key: inputs.eve_image_cache_key
- name: c
- name: Load containers to docker if specified
if: |
inputs.eve_image_cache_key != "" &&
inputs.eve_image != ""
run: |
docker load -q -i ${{ inputs.eve_image }}
shell: bash
- name: Setup eve version
run: |
image=${{ inputs.eve_image }}
Expand Down
16 changes: 15 additions & 1 deletion docs/github-actions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Github Actions

Eden is a part of testing infrastructure of EVE and it's integrated in EVE CI/CD pipelines. EVE uses [test.yml](https://github.com/lf-edge/eden/blob/master/.github/workflows/test.yml) reusable workflow to run eden tests against specific EVE version in PR.
Eden reusable workflows are running using [BuildJet](https://buildjet.com/for-github-actions) runners provided by LF-EDGE. They provide both Arm and x86_64 architectures.

## About runners

Check failure on line 5 in docs/github-actions.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## About runners"]
Eden reusable workflow (`test.yml`) is running using [BuildJet](https://buildjet.com/for-github-actions) runners provided by LF-EDGE. They provide both Arm and x86_64 architectures.
Currently we are provided with 4vCPU/16GBs of RAM and 8vCPU/32GBs of RAM runners. Maximum CPUs running in parallel is 64 for x86_64, that means with 4vCPUs we can have 16 jobs running in parallel.
In case one wants to run eden workflows locally in their own fork, `runner` and `repo` input variables for reusable workflow should be specified.

## Using GitHub Cache to run `test.yml` with custom EVE build

Check failure on line 10 in docs/github-actions.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Using GitHub Cache to run `test.yml` with custom EVE build"]
Sometimes you want to run tests in your CI/CD with EVE version, which is not published on Dockerhub,
for instance, when you have pull request to master. Eden [will](https://github.com/lf-edge/eden/blob/ed507793968a2005212d589d6c3d88824783a9a7/pkg/utils/container.go#L175-L178) prefer local image over pulling from Dockerhub. That means if you load image before running tests it will work with local image. For workflow `test.yml` you can use `eve_image_cache_key` parameter

### Why GitHub Cache and `eve_image_cache_key` parameter?

Check failure on line 14 in docs/github-actions.md

View workflow job for this annotation

GitHub Actions / yetus

markdownlint:MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Why GitHub Cache and `eve_image_cache_key` parameter?"]
In order to pass objects between jobs you need to either use cache or artifacts. Artifacts are published and stored for 90 days, cache is not published and GitHub deletes previous entries if total amount of cache is more than 10GBs. Artifacts also rebuild each time.

Unfortunately, you can't add additional steps before invoking reusable workflow, otherwise we could have just do `docker load` before invoking tests workflow.

In order to restore cache from test workflow, you need key to restore this cache from and what files exactly you want to restore. There are [wildcards](https://github.com/actions/toolkit/tree/main/packages/glob) to restore all the files from cache, but you will need to access this file afterwards, so that's why `eve_image_cache` parameter is needed.

**Important note:** Image you store in GitHub Cache should be the same specified in `eve_image`.

0 comments on commit f2b1535

Please sign in to comment.