Skip to content

Hello Python App to GKE on Google Cloud #2

Hello Python App to GKE on Google Cloud

Hello Python App to GKE on Google Cloud #2

name: Hello Python App to GKE on Google Cloud
on:
# push:
# branches:
# - main
# paths:
# - "docker/app1-hello/python"
workflow_dispatch:
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install Dependencies
working-directory: docker/app1-hello/python
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Smoke Test
working-directory: docker/app1-hello/python
run: python -m py_compile main.py
docker-build-push:
runs-on: ubuntu-latest
needs: build-test
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Image
uses: docker/build-push-action@v6
with:
context: docker/app1-hello/python
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/hello-python:latest
deploy-gcp-gke:
runs-on: ubuntu-latest
needs: docker-build-push
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: 'google-github-actions/auth@v3'
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Setup gcloud CLI
uses: 'google-github-actions/setup-gcloud@v3'
- name: Install gke-cloud-auth-plugin
run: |
gcloud components install gke-gcloud-auth-plugin
- name: Configure kubectl for GKE
run: |
gcloud container clusters get-credentials ${{ secrets.GCP_CLUSTER_NAME }} \
--region ${{ secrets.GCP_REGION }}
- name: Verify connection
run: kubectl get nodes
- name: Deploy to GKE (Google Kubernetes Engine)
run: kubectl apply -f k8s/gcp/app1-hello