Build and push release Docker image

The following is a quick recipe to build and push a release Docker image.


name: docker-release
on:
  push:
    tags:        
      - v*
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout sources
      uses: actions/checkout@v1
    - name: Login to Docker Hub
      uses: azure/docker-login@v1
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
    - name: Build image
      run: |
        TAG=${GITHUB_REF}
        INDEX=${TAG%v*}
        VERSION=${TAG:${#INDEX}}
        docker build -t myusername/myimagename:$VERSION .
        docker push myusername/myimagename:$VERSION
        

Add the DOCKER_USERNAME and DOCKER_PASSWORD as secrets to your GitHub account. Adjust the myusername/myimagename in both the build and the push command.

Posted July 2nd, 2021

Up