缓存云原生 Buildpacks/Paketo.io pack CLI 构建在 GitHub 操作上(例如,使用 Spring Boot/Java/Maven buildpacks)?
Cache Cloud Native Buildpacks/Paketo.io pack CLI builds on GitHub Actions (e.g. with Spring Boot/Java/Maven buildpacks)?
我正在研究 a Spring Boot application,应该使用 Cloud Native Build Packs / Paketo.io 将其打包到 OCI 容器中。我使用 GitHub Actions 构建它,我的工作流程 build.yml
如下所示:
name: build
on: [push]
jobs:
build-with-paketo-push-2-dockerhub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Container Registry
run: echo $DOCKER_HUB_TOKEN | docker login -u jonashackt --password-stdin
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Install pack CLI via apt. See https://buildpacks.io/docs/tools/pack/#pack-cli
run: |
sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
sudo apt-get update
sudo apt-get install pack-cli
- name: Build app with pack CLI
run: pack build spring-boot-buildpack --path . --builder paketobuildpacks/builder:base
- name: Tag & publish to Docker Hub
run: |
docker tag spring-boot-buildpack jonashackt/spring-boot-buildpack:latest
docker push jonashackt/spring-boot-buildpack:latest
现在步骤 Build app with pack CLI
需要相对较长的时间,因为它总是下载 Paketo 构建器 Docker 映像,然后进行全新构建。这意味着下载 JDK 和每个 Maven 依赖项。有没有办法缓存基于 GitHub 操作的 Paketo 构建?
在 GitHub 操作上缓存 Docker 图像可能是一个选项 - . Another option would be to leverage the Docker official docker/build-push-action Action, which is able to cache the buildx-cache. But I didn't get the combination of pack CLI and buildx-caching to work (see this build for example)。
最后我偶然发现了 the general Cloud Native Buildpacks approach on how to cache in the docs:
Cache Images are a way to preserve build optimizing layers across
different host machines. These images can improve performance when
using pack in ephemeral environments such as CI/CD pipelines.
我发现这个概念非常好,因为它使用第二个缓存映像,它发布在您选择的容器注册表上 .并且此图像仅用于在附加 --cache-image
参数的每台计算机上构建的所有 Paketo pack CLI - 无论是本地桌面还是任何 CI/CD 平台(如 GitHub 操作)。
为了使用 --cache-image
参数,我们还必须使用 --publish
标志(因为缓存映像需要发布到您的容器注册表!)。这也意味着我们需要先登录容器注册表,然后才能 运行 我们的 pack CLI 命令。使用 Docker Hub 是这样的:
echo $DOCKER_HUB_TOKEN | docker login -u YourUserNameHere --password-stdin
此外,Paketo 构建器映像必须是 a trusted one. As the docs state:
By default, any builder suggested by pack builder suggest
is
considered trusted.
由于我使用的是推荐的生成器,因此我无需在此处执行任何操作。如果您想使用默认情况下不受信任的另一个构建器,请在最终 pack CLI 命令之前 you need to run a pack config trusted-builders add your/builder-to-trust:bionic
command。
这是 pack CLI 命令,如果您想构建 Spring 启动应用程序并使用 Docker Hub 作为容器注册表,它会启用缓存:
pack build index.docker.io/yourApplicationImageNameHere:latest \
--builder paketobuildpacks/builder:base \
--path . \
--cache-image index.docker.io/yourCacheImageNameHere:latest \
--publish
最后 GitHub 构建和发布示例的操作工作流 Spring 引导应用程序 https://github.com/jonashackt/spring-boot-buildpack 如下所示:
name: build
on: [push]
jobs:
build-with-paketo-push-2-dockerhub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Container Registry
run: echo $DOCKER_HUB_TOKEN | docker login -u jonashackt --password-stdin
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Install pack CLI via the official buildpack Action https://github.com/buildpacks/github-actions#setup-pack-cli-action
uses: buildpacks/github-actions/setup-pack@v4.1.0
- name: Build app with pack CLI using Buildpack Cache image (see https://buildpacks.io/docs/app-developer-guide/using-cache-image/) & publish to Docker Hub
run: |
pack build index.docker.io/jonashackt/spring-boot-buildpack:latest \
--builder paketobuildpacks/builder:base \
--path . \
--cache-image index.docker.io/jonashackt/spring-boot-buildpack-paketo-cache-image:latest \
--publish
请注意,使用 pack CLI 的 --publish
标志后,我们也不再需要额外的步骤 Tag & publish to Docker Hub
。因为这已经由 pack CLI 为我们完成了。
我正在研究 a Spring Boot application,应该使用 Cloud Native Build Packs / Paketo.io 将其打包到 OCI 容器中。我使用 GitHub Actions 构建它,我的工作流程 build.yml
如下所示:
name: build
on: [push]
jobs:
build-with-paketo-push-2-dockerhub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Container Registry
run: echo $DOCKER_HUB_TOKEN | docker login -u jonashackt --password-stdin
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Install pack CLI via apt. See https://buildpacks.io/docs/tools/pack/#pack-cli
run: |
sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
sudo apt-get update
sudo apt-get install pack-cli
- name: Build app with pack CLI
run: pack build spring-boot-buildpack --path . --builder paketobuildpacks/builder:base
- name: Tag & publish to Docker Hub
run: |
docker tag spring-boot-buildpack jonashackt/spring-boot-buildpack:latest
docker push jonashackt/spring-boot-buildpack:latest
现在步骤 Build app with pack CLI
需要相对较长的时间,因为它总是下载 Paketo 构建器 Docker 映像,然后进行全新构建。这意味着下载 JDK 和每个 Maven 依赖项。有没有办法缓存基于 GitHub 操作的 Paketo 构建?
在 GitHub 操作上缓存 Docker 图像可能是一个选项 -
最后我偶然发现了 the general Cloud Native Buildpacks approach on how to cache in the docs:
Cache Images are a way to preserve build optimizing layers across different host machines. These images can improve performance when using pack in ephemeral environments such as CI/CD pipelines.
我发现这个概念非常好,因为它使用第二个缓存映像,它发布在您选择的容器注册表上 .并且此图像仅用于在附加 --cache-image
参数的每台计算机上构建的所有 Paketo pack CLI - 无论是本地桌面还是任何 CI/CD 平台(如 GitHub 操作)。
为了使用 --cache-image
参数,我们还必须使用 --publish
标志(因为缓存映像需要发布到您的容器注册表!)。这也意味着我们需要先登录容器注册表,然后才能 运行 我们的 pack CLI 命令。使用 Docker Hub 是这样的:
echo $DOCKER_HUB_TOKEN | docker login -u YourUserNameHere --password-stdin
此外,Paketo 构建器映像必须是 a trusted one. As the docs state:
By default, any builder suggested by
pack builder suggest
is considered trusted.
由于我使用的是推荐的生成器,因此我无需在此处执行任何操作。如果您想使用默认情况下不受信任的另一个构建器,请在最终 pack CLI 命令之前 you need to run a pack config trusted-builders add your/builder-to-trust:bionic
command。
这是 pack CLI 命令,如果您想构建 Spring 启动应用程序并使用 Docker Hub 作为容器注册表,它会启用缓存:
pack build index.docker.io/yourApplicationImageNameHere:latest \
--builder paketobuildpacks/builder:base \
--path . \
--cache-image index.docker.io/yourCacheImageNameHere:latest \
--publish
最后 GitHub 构建和发布示例的操作工作流 Spring 引导应用程序 https://github.com/jonashackt/spring-boot-buildpack 如下所示:
name: build
on: [push]
jobs:
build-with-paketo-push-2-dockerhub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Container Registry
run: echo $DOCKER_HUB_TOKEN | docker login -u jonashackt --password-stdin
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Install pack CLI via the official buildpack Action https://github.com/buildpacks/github-actions#setup-pack-cli-action
uses: buildpacks/github-actions/setup-pack@v4.1.0
- name: Build app with pack CLI using Buildpack Cache image (see https://buildpacks.io/docs/app-developer-guide/using-cache-image/) & publish to Docker Hub
run: |
pack build index.docker.io/jonashackt/spring-boot-buildpack:latest \
--builder paketobuildpacks/builder:base \
--path . \
--cache-image index.docker.io/jonashackt/spring-boot-buildpack-paketo-cache-image:latest \
--publish
请注意,使用 pack CLI 的 --publish
标志后,我们也不再需要额外的步骤 Tag & publish to Docker Hub
。因为这已经由 pack CLI 为我们完成了。