Build a Docker Image and Publish It to GCP GCR & Artifact Registry using Github Actions
YouTube Tutorial
Create GitHub Repository
Create Flask App
Create Docker Image for Flask App
Create Service Account in GCP
Create GitHub Actions Docker Build and Push Workflow
Use GitHub Actions to Push Docker to Artifact Registry
Increment Git Tag for Each Commit and Use It for Docker Image
Go to GitHub
Create empty repository lesson-087
, keep it public
Clone repository
Create app.py
Create requirements.txt
Optionally, create .gitignore
Create Docker Image for Flask App
Create Dockerfile
Build docker image
docker build -t lesson-087:latest .
docker run -p 5000:5000 lesson-087:latest
curl localhost:5000/hello
Create Service Account in GCP
Create github-actions
service account
Create and download key for service account
Add Storage Admin
role to the service account, project wide permissions (fix later)
Create GitHub Actions Docker Build and Push Workflow
Create .github/workflows/gcp.yml
Create GitHub secret SERVICE_ACCOUNT_KEY
Commit and push
git add .
git commit -m ' init commit'
git push origin main
Check docker image in GCR
Fix permissions, remove wide project permissions and add to GS bucket
Create empty commit to test CI
git commit --allow-empty -m " Trigger CI"
git push origin main
Use GitHub Actions to Push Docker to Artifact Registry
Create images
Artifact Registry repository
Add github-actions
service account to images
repo with Artifact Registry Writer
role
Add gcloud auth configure-docker us-west2-docker.pkg.dev --quiet
to Configure Docker Client
step
Add Push Docker Image to Artifact Registry
step
Commit and push
git add .
git commit -m ' add step to push docker to artifact registry'
git push origin main
Increment Git Tag for Each Commit and Use It for Docker Image
Create scripts/git_update.sh
Add Automatic Tagging of Releases
step
Update GIT_TAG
variable to ${{ steps.increment-git-tag.outputs.git-tag }}
Commit and test
git add .
git commit -m ' add step to increment git tag'
git push origin main
Check GitHub Tag, GCR and Artifact registry
Delete github-actions
service account
Delete lesson-087
GCR repository
Delete artifacts.devopsbyexample-325402.appspot.com
GS bucket
Delete images
artifact repository