4. GitHub Actions
Warning
To securely access the Docker Hub repository, you need to create two secrets in your GitHub
account: DOCKER_HUB_USERNAME
and DOCKER_HUB_ACCESS_TOKEN
respectively. Read more here.
Solution 4.1 Dockerize Application with GitHub Actions
To Dockerize your application using GitHub Actions follow these steps:
Open the
docker-build.yaml
file under thesolution/
directory.Edit this file to meet your needs (correct app name, version, etc.).
Save changes you have made.
On GitHub, open your fork of the workshop repository.
Put
docker-build.yaml
to the.github/workflows
directory to execute.
The docker-build.yaml
for Python Flask application should look like this:
# This is a basic workflow to help you get started with Actions
name: Docker Build and Push
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
-
name: Check Out Repo
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/python-helloworld:latest
Watch the solution video lesson.