Let's perform the following steps to automate the Docker image build directly from our GitHub repository:
- Sign in to your GitHub account.
- Select a repository where you have maintainer access. In our example, we are using the fork of the k8sdevopscookbook/python-flask-docker project.
- Click the Actionstab.
- From here, click on Add a new workflow.
- Create a dockerimage.yml file under the .github/workflows directory with the following content:
name: Docker Image CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
The workflow will create a new Docker image every time new code is pushed to the repository.