Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Bug/fix build caching #501

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
97 changes: 32 additions & 65 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on: # yamllint disable-line rule:truthy
branches:
- main
pull_request:
paths-ignore:
- .github/**
# paths-ignore:
# - .github/**

env:
#BUILD_CACHE: ${{ env.GITHUB_WORKSPACE }}/../imagecache # no env. contenxt at top level :/
Expand All @@ -25,41 +25,29 @@ jobs:
env:
# use per-run tag for build, but consistent tag for cache purposes
BUILD_TAG: ${{ github.job }}.${{ github.run_id }}
CACHE_TAG: buildcache
PRIOR_ART: latest_${{ env.IMAGE_ARTIFACT }}
outputs:
cache_tag: ${{ env.CACHE_TAG }}
cache_key: ${{ env.CACHE_KEY }}
tag: ${{ env.BUILD_TAG }}
steps:
- uses: actions/checkout@v3.0.0
- name: calculate cache key
env:
FILE_TO_HASH: pulp-core/Dockerfile
run: |
if [[ -f "$FILE_TO_HASH" && -r "$FILE_TO_HASH" ]]
then
# you can't use the env context as an arg for hashFiles, but it just does a sha256 :/
printf "CACHE_KEY=pulp.%s\n" $(sha256sum "$FILE_TO_HASH" | awk '$0=$1') >> $GITHUB_ENV
else
echo "Misisng '$FILE_TO_HASH'; this will probably fail later but setting default key anyway"
printf "CACHE_KEY=HoorayForDanny\n" >> $GITHUB_ENV
fi
- uses: actions/cache@v3.0.2
id: cache
with:
path: ${{ env.BUILD_CACHE }}
key: ${{ env.CACHE_KEY }}

- name: Import cached image
if: ${{ steps.cache.outputs.cache-hit }}
run: |
OUTFILE="$BUILD_CACHE/$CORE_CACHEFILE"
if [[ -f "$OUTFILE" && -r "$OUTFILE" ]]
then
printf "Importing $OUTFILE\n"
docker import "$OUTFILE"
fi
docker images
true
# - name: fetch images from latest release
# uses: dsaltares/fetch-gh-release-asset@master
# with:
# file: ${{ env.IMAGE_ARTIFACT }}
# token: ${{ secrets.GITHUB_TOKEN }}
# target: ${{ env.PRIOR_ART }}
# - name: Import latest release images
# run: |
# OUTFILE="$PRIOR_ART"
# if [[ -f "$OUTFILE" && -r "$OUTFILE" ]]
# then
# printf "Importing $OUTFILE\n"
# docker load --input "$OUTFILE"
# fi
# docker images
# true

- name: Build job-specific image
env:
DOCKER_BUILDKIT: 1
Expand All @@ -73,16 +61,6 @@ jobs:
do
printf "%s=%s\n" "$V" "${!V}"
done >> $GITHUB_ENV
- name: Export image to cache
# don't bother exporting, since the cache won't be updated if hit :/
#if: !${{ steps.cache.outputs.cache-hit }}
run: |
mkdir -p "$BUILD_CACHE"
cd "$BUILD_CACHE"
# retag with common tag for future builds
SPECIAL_IMAGE="$ORG/pulp-core:$CACHE_TAG"
docker tag "$ORG/pulp-core:$TAG" "$SPECIAL_IMAGE"
docker save --output="$CORE_CACHEFILE" "$SPECIAL_IMAGE"
- name: Export images for artifact
id: artifact_export
run: |
Expand All @@ -105,11 +83,6 @@ jobs:
uses: actions/checkout@v3.0.0
with:
fetch-depth: 0 # need all refs for tag generation
- uses: actions/cache@v3.0.2
with:
path: ${{ env.BUILD_CACHE }}
key: ${{ needs.build.outputs.cache_key }}

- name: Auto Increment Semver Action
uses: MCKanpolat/auto-semver-action@1.0.7
id: versioning
Expand Down Expand Up @@ -148,39 +121,33 @@ jobs:
- latest
steps:
- uses: actions/checkout@v3.0.0
- uses: actions/cache@v3.0.2
id: cache
with:
path: ${{ env.BUILD_CACHE }}
key: ${{ needs.build.outputs.cache_key }}
- name: Login to DockerHub
uses: docker/login-action@v1.14.1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Import cached image
if: ${{ steps.cache.outputs.cache-hit }}
- name: Download image artifact
uses: actions/download-artifact@v3
with:
name: images
path: ${{ env.IMAGE_ARTIFACT }}
- name: Import image artifact
run: |
if [[ -f "$CORE_CACHEFILE" && -r "$CORE_CACHEFILE" ]]
if [[ -f "$IMAGE_ARTIFACT" && -r "$IMAGE_ARTIFACT" ]]
then
docker import "$CORE_CACHEFILE"
docker load --input "$IMAGE_ARTIFACT"
else
printf "$CORE_CACHEFILE not found? Weird. \n"
ls -a "$( dirname "$CORE_CACHEFILE" )"
printf "$IMAGE_ARTIFACT not found? Weird. \n"
ls -a "$( dirname "$IMAGE_ARTIFACT" )"
fi
- name: Build (retag) images
env:
DOCKER_BUILDKIT: 1
ORG: kong
TAG: ${{ matrix.tag }}
CACHE_TAG: ${{ needs.build.cache_tag }}
CACHE_TAG: ${{ needs.build.tag }}
run: |
make images
# make these vars usable in later steps
for V in ORG TAG
do
printf "%s=%s\n" "$V" "${!V}"
done >> $GITHUB_ENV
- name: Publish images
run: |
make release