Last active
          June 12, 2020 07:58 
        
      - 
      
- 
        Save luthermonson/0ca80d83f4452fc1a341e84b9e6ca09d to your computer and use it in GitHub Desktop. 
    Github Action to Build a Docker Image and push it to Github Packages
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Have a ./Dockerfile in your projecft and put in .github/workflows/build-and-push.yml | |
| name: Build Docker Image and Push to Github Packages | |
| on: | |
| push: | |
| tags: | |
| - '*' | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v1 | |
| - name: Build and Push Image to Github Packages | |
| env: | |
| DOCKER_USERNAME: ${{ github.actor }} | |
| DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
| REPOSITORY: ${{ github.repository }} | |
| REF: ${{ github.ref }} | |
| REGISTRY: docker.pkg.github.com | |
| IMAGE_NAME: app | |
| run: | | |
| TAG=${REF##*/} | |
| echo "$DOCKER_PASSWORD" | docker login docker.pkg.github.com -u "$DOCKER_USERNAME" --password-stdin | |
| docker build -t $REGISTRY/$REPOSITORY/$IMAGE_NAME:$TAG . | |
| docker push $REGISTRY/$REPOSITORY/$IMAGE_NAME:$TAG | |
| echo "::set-output name=image::$REGISTRY/$REPOSITORY/$IMAGE_NAME:$TAG" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment