Skip to content

Warning annotation appears in Github Actions when post-build tries to clean up the builder #156

Closed
@bamarch

Description

Behaviour

Steps to reproduce this issue

  1. Use buildx
  2. Warning appears in Github Actions when post-build tries to clean up the builder

Expected behaviour

If the error code is ignored and it's expected the builder won't be there sometimes, suppress the error so this warning annotation isn't present in each build

Actual behaviour

Each build shows a warning generated by the post step - perhaps it is something I'm doing or there is a way to easily suppress it?

image

image

Unfortunately these annotations are quite visible, and I'm often finding myself fielding questions about why they're present

Configuration

# composite action
name: 'Build'
description: 'pr.yml or ci.yml job: build'
inputs:
  src-code-path:
    description: 'Path to dir containing dotnet source code, relative to the github workspace root.'
    required: false
    default: './src'
  infra-repo-path:
    description: 'Path to checked-out infrastructure repo code, relative to the github workspace root.'
    required: false
    default: './infra-repo'
  publish:
    description: 'Publish built images to ACR if this is set to true'
    required: false
    default: 'false'
  acr-host:
    description: 'The ACR host for publishing images to'
    required: false
    default: ''
  acr-user:
    description: 'The ACR user for publishing images as'
    required: false
    default: ''
  acr-password:
    description: 'The ACR user password'
    required: false
    default: ''
  image-version:
    description: 'Version to tag the deployed docker image with when publishing e.g. github.sha, or 1.2.3'
    required: true
runs:
  using: "composite"
  steps:
    - name: Set Env
      shell: bash
      run: |
        {
          echo "SCRIPTS_DIR=${{ github.workspace }}/${{ inputs.infra-repo-path }}/.github/scripts"
          echo "SRC_DIR=${{ github.workspace }}/${{ inputs.src-code-path }}"
        } >> "$GITHUB_ENV"

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

    - name: Build Docker Images (testing)
      shell: bash
      if: ${{ inputs.publish != 'true' }}
      working-directory: ${{ env.SRC_DIR }}
      # cached for maximum speed
      run: |
        docker buildx bake \
          -f docker-compose.yml \
          --builder ${{ steps.buildx.outputs.name }} \
          --set *.cache-from="type=gha,scope=${{ github.workflow }}" \
          --set *.cache-to="type=gha,scope=${{ github.workflow }},mode=max"

    - name: Build Docker Images (to publish)
      if: ${{ inputs.publish == 'true' }}
      shell: bash
      working-directory: ${{ env.SRC_DIR }}
      env:
        DOCKER_REGISTRY: ${{ inputs.acr-host }}/
        IMAGE_VERSION: ":${{ inputs.image-version }}"
        BUILD_ARG_HOMEPAGE_OVERRIDE: "${{ env.BUILD_ARG_HOMEPAGE_OVERRIDE }}"
      # no cache for security so when we publish we pull in security updates for the base
      run: |
        docker buildx bake \
          -f docker-compose.yml \
          --builder ${{ steps.buildx.outputs.name }} \
          --load \
          --no-cache

    - uses: azure/docker-login@v1
      if: ${{ inputs.publish == 'true' }}
      with:
        login-server: ${{ inputs.acr-host }}
        username: ${{ inputs.acr-user }}
        password: ${{ inputs.acr-password }}

    - name: Push Docker Images (image version)
      if: ${{ inputs.publish == 'true' }}
      shell: bash
      working-directory: ${{ env.SRC_DIR }}
      env:
        DOCKER_REGISTRY: ${{ inputs.acr-host }}/
        IMAGE_VERSION: ":${{ inputs.image-version }}"
      run: docker compose -f docker-compose.yml push

    - name: Tag Images (branch name)
      if: ${{ inputs.publish == 'true' && github.ref_name == 'main' }}
      shell: bash
      run: |
        for source_image_name in $(docker images --format "{{.Repository}}" | grep "${{ inputs.acr-host }}"); do
          echo "Tagging $source_image_name"
          source_image="${source_image_name}:${{ inputs.image-version }}"

          dest_image_branchname="${source_image_name}:main"
          echo "Tagging $source_image -> $dest_image_branchname"
          docker tag "$source_image" "$dest_image_branchname"
        done

    - name: Push Docker Images (branch name)
      if: ${{ inputs.publish == 'true' && github.ref_name == 'main' }}
      shell: bash
      working-directory: ${{ env.SRC_DIR }}
      env:
        DOCKER_REGISTRY: ${{ inputs.acr-host }}/
        IMAGE_VERSION: ":main"
      run: docker compose -f docker-compose.yml push
      
# using the action
jobs:

  build-and-publish:
    name: "Docker Build and Publish"
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./src
    steps:
    - uses: actions/checkout@v2

    - name: Checkout Infrastructure repo
      uses: actions/checkout@v2
      with:
        fetch-depth: 0
        repository: BondOrigination/infrastructure
        path: infra-repo
        ssh-key: ${{ secrets.DEPLOY_KEY_INFRASTRUCTURE_READ_ONLY }}

    - name: Use PR Build action and publish
      uses: ./infra-repo/.github/actions/build
      with:
        publish: true
        image-version: ${{ github.sha }}
        acr-host: ${{ secrets.ACR_HOST__PRE }}
        acr-user: ${{ secrets.ACR_USERNAME__PRE }}
        acr-password: ${{ secrets.ACR_PASSWORD__PRE }}      

Logs

full logs: docker_buildx_logs.txt

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions