From e7752b350c16edd8e875516650fdbacbfc1b9170 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 23 Feb 2023 01:29:03 +0100 Subject: [PATCH] build(gha): move named contexts section to dedicated page Signed-off-by: CrazyMax --- _data/toc.yaml | 2 + build/ci/github-actions/examples.md | 94 -------------------- build/ci/github-actions/named-contexts.md | 102 ++++++++++++++++++++++ 3 files changed, 104 insertions(+), 94 deletions(-) create mode 100644 build/ci/github-actions/named-contexts.md diff --git a/_data/toc.yaml b/_data/toc.yaml index 96fd66abf3..fb33bbb584 100644 --- a/_data/toc.yaml +++ b/_data/toc.yaml @@ -1627,6 +1627,8 @@ manuals: title: Local registry - path: /build/ci/github-actions/share-image-jobs/ title: Share built image between jobs + - path: /build/ci/github-actions/named-contexts/ + title: Named contexts - path: /build/ci/github-actions/examples/ title: Examples - sectiontitle: Bake diff --git a/build/ci/github-actions/examples.md b/build/ci/github-actions/examples.md index d6c64536e3..75adeb400c 100644 --- a/build/ci/github-actions/examples.md +++ b/build/ci/github-actions/examples.md @@ -7,101 +7,7 @@ keywords: ci, github actions, gha, examples This page showcases different examples of how you can customize and use the Docker GitHub Actions in your CI pipelines. -## Named contexts -You can define [additional build contexts](../../../engine/reference/commandline/buildx_build.md#build-context), -and access them in your Dockerfile with `FROM name` or `--from=name`. When -Dockerfile defines a stage with the same name it's overwritten. - -This can be useful with GitHub Actions to reuse results from other builds or pin -an image to a specific tag in your workflow. - -### Pin image to a tag - -Replace `alpine:latest` with a pinned one: - -```dockerfile -# syntax=docker/dockerfile:1 -FROM alpine -RUN echo "Hello World" -``` - -```yaml -name: ci - -on: - push: - branches: - - "main" - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build - uses: docker/build-push-action@v4 - with: - context: . - build-contexts: | - alpine=docker-image://alpine:3.16 - tags: myimage:latest -``` - -### Use image in subsequent steps - -By default, the [Docker Setup Buildx](https://github.com/marketplace/actions/docker-setup-buildx){:target="blank" rel="noopener" class=""} -action uses `docker-container` as a build driver, so built Docker images aren't -loaded automatically. - -With named contexts you can reuse the built image: - -```dockerfile -# syntax=docker/dockerfile:1 -FROM alpine -RUN echo "Hello World" -``` - -```yaml -name: ci - -on: - push: - branches: - - "main" - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build base image - uses: docker/build-push-action@v4 - with: - context: base - load: true - tags: my-base-image:latest - - - name: Build - uses: docker/build-push-action@v4 - with: - context: . - build-contexts: | - alpine=docker-image://my-base-image:latest - tags: myimage:latest -``` ## Copy images between registries diff --git a/build/ci/github-actions/named-contexts.md b/build/ci/github-actions/named-contexts.md new file mode 100644 index 0000000000..01d505d819 --- /dev/null +++ b/build/ci/github-actions/named-contexts.md @@ -0,0 +1,102 @@ +--- +title: Named contexts with GitHub Actions +keywords: ci, github actions, gha, buildkit, buildx, context +--- + +You can define [additional build contexts](../../../engine/reference/commandline/buildx_build.md#build-context), +and access them in your Dockerfile with `FROM name` or `--from=name`. When +Dockerfile defines a stage with the same name it's overwritten. + +This can be useful with GitHub Actions to reuse results from other builds or pin +an image to a specific tag in your workflow. + +## Pin image to a tag + +Replace `alpine:latest` with a pinned one: + +```dockerfile +# syntax=docker/dockerfile:1 +FROM alpine +RUN echo "Hello World" +``` + +{% raw %} +```yaml +name: ci + +on: + push: + branches: + - "main" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Build + uses: docker/build-push-action@v4 + with: + context: . + build-contexts: | + alpine=docker-image://alpine:3.16 + tags: myimage:latest +``` +{% endraw %} + +## Use image in subsequent steps + +By default, the [Docker Setup Buildx](https://github.com/marketplace/actions/docker-setup-buildx){:target="blank" rel="noopener" class=""} +action uses `docker-container` as a build driver, so built Docker images aren't +loaded automatically. + +With named contexts you can reuse the built image: + +```dockerfile +# syntax=docker/dockerfile:1 +FROM alpine +RUN echo "Hello World" +``` + +{% raw %} +```yaml +name: ci + +on: + push: + branches: + - "main" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Build base image + uses: docker/build-push-action@v4 + with: + context: base + load: true + tags: my-base-image:latest + - + name: Build + uses: docker/build-push-action@v4 + with: + context: . + build-contexts: | + alpine=docker-image://my-base-image:latest + tags: myimage:latest +``` +{% endraw %}