From 62432939ab4e35158d22c1f51c341ceda2c8b402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiri=20Dan=C4=9Bk?= Date: Fri, 31 May 2024 10:27:03 +0200 Subject: [PATCH] squash-me, implement read-only cache for pull requests; undo hardcoded params in Makefile --- .github/workflows/build-notebooks-TEMPLATE.yaml | 9 +++++++-- Makefile | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-notebooks-TEMPLATE.yaml b/.github/workflows/build-notebooks-TEMPLATE.yaml index cd0997fb0..e826d79b5 100644 --- a/.github/workflows/build-notebooks-TEMPLATE.yaml +++ b/.github/workflows/build-notebooks-TEMPLATE.yaml @@ -19,7 +19,12 @@ name: Build & Publish Notebook Servers (TEMPLATE) jobs: build: runs-on: ubuntu-latest + env: + # GitHub image registry used for storing $(CONTAINER_ENGINE)'s cache + CACHE: "ghcr.io/${{ github.repository }}/workbench-images/build-cache" + steps: + - uses: actions/checkout@v4 - name: Login to GitHub Container Registry @@ -67,7 +72,7 @@ jobs: env: IMAGE_TAG: "${{ github.ref_name }}_${{ github.sha }}" IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images" - CACHE: "ghcr.io/${{ github.repository }}/workbench-images/build-cache" + CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}" # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request - name: "pull_request: make ${{ inputs.target }}" @@ -76,7 +81,7 @@ jobs: env: IMAGE_TAG: "${{ github.head_ref }}_${{ github.sha }}" IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images/pr${{ fromJson(inputs.github).event.number }}" - CACHE: "ghcr.io/${{ github.repository }}/workbench-images/build-cache" + CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }}" - run: df -h if: "${{ !cancelled() }}" diff --git a/Makefile b/Makefile index 98d63ad4f..878d50176 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ IMAGE_REGISTRY ?= quay.io/opendatahub/workbench-images RELEASE ?= 2024a +# additional user-specified caching parameters for $(CONTAINER_ENGINE) build +CONTAINER_BUILD_CACHE_ARGS ?= --no-cache # OS dependant: Generate date, select appropriate cmd to locate container engine ifeq ($(OS), Windows_NT) @@ -41,7 +43,7 @@ define build_image $(eval BUILD_ARGS := --build-arg BASE_IMAGE=$(BASE_IMAGE_NAME)), $(eval BUILD_ARGS :=) ) - $(CONTAINER_ENGINE) build --cache-from $(CACHE) --cache-to $(CACHE) -t $(IMAGE_NAME) $(BUILD_ARGS) $(2) + $(CONTAINER_ENGINE) build $(CONTAINER_BUILD_CACHE_ARGS) -t $(IMAGE_NAME) $(BUILD_ARGS) $(2) endef # Push function for the notebok image: