github-ci icon indicating copy to clipboard operation
github-ci copied to clipboard

Cannot push to Github Container Registry

Open geeanlooca opened this issue 2 years ago • 7 comments

Hi, I'm trying to build a Singularity and push it to Github Container Registry using one of the Github Actions workflow provided in this repo as a template.

I run a modified version of the "Docker" workflow, where I skip the step that checks whether the Singularity recipe has been changed in order to build the image at every push. Here is the content of the .yaml file for this workflow.

name: Singularity Build (docker)
on: 
  push:

    # Edit the branches here if you want to change deploy behavior
    branches:
      - main
      - master

  # Do the builds on all pull requests (to test them)
  # pull_request: []

jobs:
  build-test-containers:
    runs-on: ubuntu-latest
    strategy:
      # Keep going on other deployments if anything bloops
      fail-fast: false
      matrix:
        singularity_version:
        - '3.8.1'
        recipe: ["Singularity"]


    container:
      image: quay.io/singularity/singularity:v${{ matrix.singularity_version }}
      options: --privileged

    name: Check ${{ matrix.recipe }}
    steps:

      - name: Check out code for the container builds
        uses: actions/checkout@v2

      - name: Continue if Singularity Recipe Exists
        run: |
          if [[ -f "${{ matrix.recipe }}" ]]; then
            echo "keepgoing=true" >> $GITHUB_ENV
          fi        
      - name: Build Container
        if: ${{ env.keepgoing == 'true' }}
        env:
          recipe: ${{ matrix.recipe }}
        run: |
         ls 
         if [ -f "${{ matrix.recipe }}" ]; then
            sudo -E singularity build container.sif ${{ matrix.recipe }}
            tag=$(echo "${recipe/Singularity\./}")
            if [ "$tag" == "Singularity" ]; then
                tag=latest
            fi
            # Build the container and name by tag
            echo "Tag is $tag."
            echo "tag=$tag" >> $GITHUB_ENV
         else
           echo "${{ matrix.recipe }} is not found."
           echo "Present working directory: $PWD"
           ls
         fi
      - name: Login and Deploy Container
        if: (github.event_name != 'pull_request')
        env:
          keepgoing: ${{ env.keepgoing }}
        run: |         
            if [[ "${keepgoing}" == "true" ]]; then
                echo ${{ secrets.GITHUB_TOKEN }} | singularity remote login -u ${{ secrets.GHCR_USERNAME }} --password-stdin oras://ghcr.io
                singularity push container.sif oras://ghcr.io/${GITHUB_REPOSITORY}:${tag}
            fi

The container is built without error but it fails on the Login and Deploy Container step with a 404 error:

Password (or token when username is empty): 
INFO:    Token stored in /root/.singularity/remote.yaml
FATAL:   Unable to push image to oci registry: unable to push: unexpected status: 404 Not Found
Error: Process completed with exit code 255.

One of the failed runs

Am I doing something wrong? Thanks, Gianluca

geeanlooca avatar Mar 28 '22 13:03 geeanlooca

It says the username is empty - Is GHCR_USERNAME set in your secrets? You could probably just use github.actor instead.

vsoch avatar Mar 28 '22 13:03 vsoch

Note that full instructions (including setting this) are in the README https://github.com/singularityhub/github-ci#1-enable-packages

vsoch avatar Mar 28 '22 13:03 vsoch

Thanks for the quick reply.

I indeed forgot to set the username secret, but I tried again using either secrets.GHCR_USERNAME or github.actor and got the same result. Got the same error trying to push a local image on my pc and explicitly writing the username in the command 🤦‍♂️

geeanlooca avatar Mar 28 '22 14:03 geeanlooca

Note that I can correctly push a Docker image using a different workflow.

geeanlooca avatar Mar 28 '22 14:03 geeanlooca

I think if you are getting this error trying to push a local image, you might want to debug that first. E.g., there are many settings for packages and typically you need to make sure they are enabled and your user account has permission to push to a specific repository where they are enabled.

vsoch avatar Mar 28 '22 18:03 vsoch

Thanks again for the assistance! Do you mind if I leave this issue open so I can come back and write a solution in case I am able to solve the problem?

geeanlooca avatar Mar 29 '22 09:03 geeanlooca

Yes please do! I hope you figure it out and can add some notes here - I definitely faced similar issues when I was first using packages and it's been too long for me to remember the details beyond needing to set up permissions.

vsoch avatar Mar 29 '22 09:03 vsoch