docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.31k stars 552 forks source link

Tarball output throws `ResourceExhausted` error #1047

Closed robertsLando closed 8 months ago

robertsLando commented 8 months ago

Contributing guidelines

I've found a bug, and:

Description

I have set outputs to: outputs: type=tar,dest=./out.tar

The exports throws:

#18 exporting to client tarball
#18 sending tarball
#18 sending tarball 2.3s done
#18 ERROR: failed to write file header root/.cshrc: rpc error: code = ResourceExhausted desc = grpc: received message larger than max (16307097 vs. 4194304)

https://github.com/yao-pkg/pkg-fetch/actions/runs/7744165698/job/21117282351#step:4:1149

Expected behaviour

The export to end successfully

Actual behaviour

Throws error

Repository URL

https://github.com/yao-pkg/pkg-fetch

Workflow run URL

https://github.com/yao-pkg/pkg-fetch/actions/runs/7744165698/job/21117282351#step:4:1149

YAML workflow

name: Build Node binaries for Linux

on:
  workflow_dispatch:
  workflow_call:

jobs:
  linux-x64:
    runs-on: ubuntu-20.04

    strategy:
      fail-fast: false
      matrix:
        target-node: [14, 16, 18, 20]

    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build
        uses: docker/build-push-action@v5
        with:
          build-args: |
            PKG_FETCH_OPTION_n=node${{ matrix.target-node }}
          context: .
          file: ./Dockerfile.linux
          platforms: linux/amd64
          outputs: type=tar,dest=../out.tar

      - name: Extract binaries from Docker image
        run: |
          tar xvf ../out.tar root/pkg-fetch/dist

      - name: Check if binary is compiled
        id: check_file
        run: |
          (test -f root/pkg-fetch/dist/*.sha256sum && echo "EXISTS=true" >> $GITHUB_OUTPUT) || echo "EXISTS=false" >> $GITHUB_OUTPUT

      - uses: actions/upload-artifact@v4
        if: steps.check_file.outputs.EXISTS == 'true'
        with:
          name: node${{ matrix.target-node }}-linux-x64
          path: root/pkg-fetch/dist/*

  linux-arm64:
    runs-on: ubuntu-20.04

    strategy:
      fail-fast: false
      matrix:
        target-node: [14, 16, 18, 20]

    steps:
      - uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build
        uses: docker/build-push-action@v5
        with:
          build-args: |
            TARGET_TOOLCHAIN_ARCH=aarch64
            PKG_FETCH_OPTION_a=arm64
            PKG_FETCH_OPTION_n=node${{ matrix.target-node }}
          context: .
          file: ./Dockerfile.linuxcross
          platforms: linux/amd64
          outputs: type=tar,dest=../out.tar

      - name: Extract binaries from Docker image
        run: |
          tar xvf ../out.tar root/pkg-fetch/dist

      - name: Check if binary is compiled
        id: check_file
        run: |
          (test -f root/pkg-fetch/dist/*.sha256sum && echo "EXISTS=true" >> $GITHUB_OUTPUT) || echo "EXISTS=false" >> $GITHUB_OUTPUT

      - uses: actions/upload-artifact@v4
        if: steps.check_file.outputs.EXISTS == 'true'
        with:
          name: node${{ matrix.target-node }}-linux-arm64
          path: root/pkg-fetch/dist/*

Workflow logs

No response

BuildKit logs

No response

Additional info

No response

crazy-max commented 8 months ago

Why would you want to load the image and extract the tarball where you could just output files from your build using the local exporter: https://docs.docker.com/build/exporters/local-tar/?

You would not need the Extract binaries from Docker image step or archive/load the whole image.

Just add an extra scratch stage in https://github.com/yao-pkg/pkg-fetch/blob/main/Dockerfile.linuxcross like:

FROM ubuntu:bionic AS build
...
ARG PKG_FETCH_OPTION_n

RUN yarn start --arch $PKG_FETCH_OPTION_a --node-range $PKG_FETCH_OPTION_n --output dist

FROM scratch
COPY --from=build /root/pkg-fetch /

Then in the workflow:

      - name: Build
        uses: docker/build-push-action@v5
        with:
          build-args: |
            TARGET_TOOLCHAIN_ARCH=aarch64
            PKG_FETCH_OPTION_a=arm64
            PKG_FETCH_OPTION_n=node${{ matrix.target-node }}
          context: .
          file: ./Dockerfile.linuxcross
          platforms: linux/amd64
          outputs: root/pkg-fetch
robertsLando commented 8 months ago

Reason is that I never thought about your clever solution yet :) I'm tring to use the docker cp command now but I will give that a try. Anyway I dunno why previous code used to work for long time and now stopped working with that error

crazy-max commented 8 months ago

Anyway I dunno why previous code used to work for long time and now stopped working with that error

Best guess is not enough disk space on the runner

robertsLando commented 8 months ago

Ok so thanks again for the suggestion, it's much cleaner then the others I thought :) Can close this