簡體   English   中英

如何從 GitHub 操作緩存 docker 圖像

[英]How to cache a docker image from a GitHub Action

我有一個場景,我在 GitHub 工作流上使用 maven 和 docker 構建應用程序。

然后在構建應用程序(帶有 docker 映像)時,應用程序的集成測試失敗。

在重新運行 GitHub 工作流之前,我經常需要更改現有的集成測試而不更改應用程序本身。 這會導致使用 java 和 docker 構建(並在本地測試)操作。

構建過程已經完成,並且 docker 圖像上傳到 GitHub 包。 如何檢查此應用程序是否已有 docker 映像?

我可以使用 actions/cache@v2 ( https://github.com/actions/cache ) 嗎? 如何? Docker 在它可以緩存的語言中沒有提到......

為此,我建議使用Docker 的 Build Push 操作 通過build-push-action ,您可以使用內聯緩存、注冊表緩存或實驗性緩存后端 API 來緩存您的容器鏡像:

內聯緩存

name: Build and push
uses: docker/build-push-action@v2
with:
    context: .
    push: true
    tags: user/app:latest
    cache-from: type=registry,ref=user/app:latest
    cache-to: type=inline

請參閱Buildkit 文檔

注冊表緩存

name: Build and push
uses: docker/build-push-action@v2
with:
    context: .
    push: true
    tags: user/app:latest
    cache-from: type=registry,ref=user/app:buildcache
    cache-to: type=registry,ref=user/app:buildcache,mode=max

請參閱Buildkit 文檔

緩存后端 API

name: Build and push
uses: docker/build-push-action@v2
with:
    context: .
    push: true
    tags: user/app:latest
    cache-from: type=gha
    cache-to: type=gha,mode=max

請參閱Buildkit 文檔

我個人更喜歡使用緩存后端 API,因為它易於設置,並且可以大大縮短整體 CI 管道運行時間。

您不需要使用緩存操作,因為上述工作流程本質上實現了它並為我們抽象了工作流程。

這是一個例子: https://github.com/moja-global/FLINT.Reporting/blob/d7504909f8f101054e503a2993f4f70ca92c2577/.github/workflows/docker.yml#L54

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM