Home > Net >  How to set Dockerfile tag in GitHub Actions?
How to set Dockerfile tag in GitHub Actions?

Time:04-24

I'm using docker/build-push-action@v2 with an automated version bump action and the job runs fine until the build and push step where I get this error

/usr/bin/docker buildx build --build-arg NPM_TOKEN=*** --iidfile /tmp/docker-build-push-MO1ELt/iidfile --tag registry.digitalocean.com/xxx/xxx: --metadata-file /tmp/docker-build-push-MO1ELt/metadata-file --push ./xxx
error: invalid tag "registry.digitalocean.com/xxx/xxx:": invalid reference format
Error: buildx failed with: error: invalid tag "registry.digitalocean.com/xxx/xxx:": invalid reference format

Am I adding the tag correctly or is it something wrong with the version bump package?

My GitHub action file

name: deploy-auth

on:
  push:
    branches:
      - main
    paths:
      - 'xxx/**'

jobs: 
  build:
    runs-on: ubuntu-latest
    steps:
    
      - name: Checkout main
        uses: actions/checkout@v2
        
      - name: Automated Version Bump
        uses: 'phips28/gh-action-bump-version@master'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          default: fix
          tag-prefix: 'v'
        
          
      - name: Output Step
        env:
          NEW_TAG: ${{ steps.version-bump.outputs.newTag }}
        run: echo "new tag $NEW_TAG"
      
      - name: Install doctl
        uses: digitalocean/action-doctl@v2
        with:
          token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
          
      - name: Log in to DigitalOcean Container Registry with short-lived credentials
        run: doctl registry login --expiry-seconds 600
        
      - name: Build and push Docker image
        uses: docker/build-push-action@v2
        with: 
          context: ./xxx
          push: true
          tags: registry.digitalocean.com/xxx/xxx:${{ steps.version-bump.outputs.newTag }}
          build-args: |
            NPM_TOKEN=${{ secrets.NPM_TOKEN }}

CodePudding user response:

There's no version-bump step in that GHA. Which means ${{ steps.version-bump.outputs.newTag }} is empty. You can set an id field on the step to define it:

      - name: Automated Version Bump
        uses: 'phips28/gh-action-bump-version@master'
        id: version-bump
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          default: fix
          tag-prefix: 'v'
  • Related