Instead of creating multiple actions to build, tag, login, and push to Docker Repository, you can use one action to achieve all at once. Let's perform the following steps:
- 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 dockerpush.yml file under the .github/workflows directory with the following content. Make sure to change MyDockerRepo/repository so that it uses the name of the image you would like to push:
name: Build and Push to DockerHub
on: [push]
jobs:
build: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@master with: name: MyDockerRepo/repository username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }}
- Click on the Settings tab and go to the Secrets menu.
- Create a DOCKER_USERNAME secret with the value equals to the username you used to log in to your Docker Registry.
- Create DOCKER_PASSWORD secrets with a value equals to the password you used to log in to your Docker Registry. After both secrets have been created, you should be able to see them in the Secrets menu, as shown in the following screenshot:
Environmental variables stored as secrets will be encrypted and are only available for selected actions.