Skip to content

Fully working basic example for automatically trigger a docker image build from github and pushing it to the registry

License

Notifications You must be signed in to change notification settings

sir-farfan/hello-docker-build-push-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Build and Push Action on Github

GitHub can double as a basic CI/CD system, automatically building your Docker images and sending them directly to the Docker Registry, the best part is that part is the job is already done, however, sometimes the documentation is not as easy to follow, so here I show you a basic example of how you can configure the Docker build and push action in your repository.

What you need:

Enabling the action

Github looks for actions enabled in in a repository in the workflows directory, here I created this docker.yml file:

on: [push, pull_request]

name: Docker

jobs:
  docker:
    name: Build and push to registry
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: sulfurf/hello-action
          tag_with_sha: true
          tag_with_ref: true

At line 1 I'm telling github to perform the current action every time there's a new commit in any branch or a pull request. The following lines are usual github action code, but at line 10 I'm requesting a checkout of the code to be performed, if you omit this step, the build/push action will fail with a very cryptic error.

Finally, at line 13 we can see the actual build and push configuration, you can find a description of the parameters in their project page.

About

Fully working basic example for automatically trigger a docker image build from github and pushing it to the registry

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published