build(gha): fix named context with container builder

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-02-23 02:18:12 +01:00
parent 0d6444f67b
commit 3c9cda5e3e
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
1 changed files with 65 additions and 1 deletions

View File

@ -83,11 +83,14 @@ jobs:
- -
name: Set up Docker Buildx name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
with:
driver: docker
- -
name: Build base image name: Build base image
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: base context: ./base
file: ./base/Dockerfile
load: true load: true
tags: my-base-image:latest tags: my-base-image:latest
- -
@ -100,3 +103,64 @@ jobs:
tags: myimage:latest tags: myimage:latest
``` ```
{% endraw %} {% endraw %}
## Using with a container builder
As shown in the previous section we are not using the default
[`docker-container` driver](../../drivers/docker-container.md) for building with
named contexts. That's because this driver can't load an image from the Docker
store as it's isolated. To solve this problem you can use a [local registry](local-registry.md)
to push your base image in your workflow:
```dockerfile
# syntax=docker/dockerfile:1
FROM alpine
RUN echo "Hello World"
```
```yaml
name: ci
on:
push:
branches:
- "main"
jobs:
docker:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
# network=host driver-opt needed to push to local registry
driver-opts: network=host
-
name: Build base image
uses: docker/build-push-action@v4
with:
context: ./base
file: ./base/Dockerfile
tags: localhost:5000/my-base-image:latest
push: true
-
name: Build
uses: docker/build-push-action@v4
with:
context: .
build-contexts: |
alpine=docker-image://localhost:5000/my-base-image:latest
tags: myimage:latest
```