-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add daily docker cache workflow to master (#3681)
This PR makes the following changes: - Adds a new workflow action that runs once a day `Monday - Friday` at 5am to build a fresh docker cache - This will allow all child branches to have access to this cache
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Daily Docker Cache | ||
|
||
on: | ||
schedule: | ||
- cron: '0 12 * * 1-5' # Monday - Friday at 5am Arizona Time | ||
|
||
jobs: | ||
cache-docker-images: | ||
runs-on: ubuntu-latest | ||
|
||
# # final check to make sure it runs only on master branch | ||
if: github.ref == 'refs/heads/master' | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18.19.1 | ||
cache: 'yarn' | ||
|
||
# we login to docker to avoid docker pull limit rates | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Check docker.hub limit start of job | ||
env: | ||
USER: ${{ secrets.DOCKER_USERNAME }} | ||
PASS: ${{ secrets.DOCKER_PASSWORD }} | ||
run: yarn docker:limit | ||
|
||
- name: Install and build packages | ||
run: yarn setup | ||
env: | ||
YARN_SETUP_ARGS: "--prod=false --silent" | ||
|
||
- name: Create Docker Image List | ||
run: | | ||
yarn docker:listImages | ||
cat ./images/image-list.txt | ||
- name: Restore Docker image cache | ||
id: docker-cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/docker_cache | ||
key: docker-images-${{ hashFiles('./images/image-list.txt') }} | ||
lookup-only: true | ||
|
||
- name: Clear old docker cache | ||
if: ${{steps.docker-cache.outputs.cache-hit == 'true'}} | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
REPO: ${{ github.repository }} | ||
BRANCH: refs/heads/master | ||
run: | | ||
gh extension install actions/gh-actions-cache | ||
echo "Fetching list of cache key" | ||
cacheKeysForPR=$(gh actions-cache list --key "docker-images-" -R $REPO -B $BRANCH -L 100 | cut -f 1 ) | ||
## Setting this to not fail the workflow while deleting cache keys. | ||
set +e | ||
echo "Deleting caches..." | ||
for cacheKey in $cacheKeysForPR | ||
do | ||
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm | ||
done | ||
echo "Done" | ||
- name: Pull and save Docker images | ||
run: yarn docker:saveImages | ||
|
||
- name: Update Docker image cache | ||
uses: actions/cache/save@v4 | ||
with: | ||
path: /tmp/docker_cache | ||
key: docker-images-${{ hashFiles('./images/image-list.txt') }} | ||
|
||
- name: Check docker.hub limit end of job | ||
env: | ||
USER: ${{ secrets.DOCKER_USERNAME }} | ||
PASS: ${{ secrets.DOCKER_PASSWORD }} | ||
run: npm run docker:limit |