Search code examples
dockergithubgithub-actions

Create Docker Image From Github and Publish to Hub


My github repository link is https://github.com/ferdasonmez/oyente. I forked a github site and made sme changes on some lib versions. Now I want to push it to Docker. I already created a repository under my docker account. ferdaozdemir/oyente

Using the below yml file, I am trying to create the image but nothing happens. I already created the secrets for Docker under Github settings. This can easily be recreated by forking the repository and entering your own secrets.

name: Build Docker Container Image
on: push
jobs:
  build-container:
    name: Build container
    runs-on: ubuntu-latest
    steps:
      - name: Push to Docker Hub
        uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USER_NAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: ferdaozdemir/oyente
          tags: latest

Solution

  • You may be missing steps. I have some repos with a similar setup (i.e. Dockerfile in the top-level directory) but I also run steps to

    • checkout
    • build (where I now use buildx)
    • log into the Docker Hub
    • build and push
    • and also report and commit a timestamp (to force cache changes)

    I include one of these below (source is here. It may not be the most minimal setup but it had been working for me quite reliably, including via scheduled (i.e cron) actions. I am skipping the last two items here (see here for the complete file):

    name: docker
    on:
      push:
      schedule:
      - cron: "22 2 * * 1"
        
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
        - name: Checkout
          uses: actions/checkout@v2
    
        #- name: Set up QEMU
        #  uses: docker/setup-qemu-action@v1
    
        - name: Buildx
          uses: docker/setup-buildx-action@v1
    
        - name: Login
          uses: docker/login-action@v1
          with:
            username: ${{ secrets.DOCKER_USERNAME }}
            password: ${{ secrets.DOCKER_PASSWORD }}
            
        - name: Build and push
          uses: docker/build-push-action@v2
          with:
            context: .
            push: true
            tags: rocker/drd:latest