fix git actions error using copilot advice

This commit is contained in:
Keyvan Ebrahimpour 2025-04-11 08:49:50 +00:00
parent f9fe3ff743
commit f9f5119be1

View file

@ -1,6 +1,5 @@
name: Build and Deploy to Kubernetes name: Build and Deploy to Kubernetes
# Uncomment to enable auto-deployment on push to main
on: on:
push: push:
branches: [ main ] branches: [ main ]
@ -13,12 +12,17 @@ jobs:
packages: write packages: write
steps: steps:
# Step 1: Checkout the repository code
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
# Step 2: Debug repository information (optional)
- name: Debug Repository Info - name: Debug Repository Info
run: echo "Repository: ${{ github.repository }}" run: |
echo "Repository: ${{ github.repository }}"
echo "Actor: ${{ github.actor }}"
# Step 3: Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry - name: Log in to GitHub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
@ -26,12 +30,15 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
# Step 4: Build and Push Docker Image with unique tag
- name: Build and Push Docker Image - name: Build and Push Docker Image
run: | run: |
IMAGE_NAME="ghcr.io/${{ github.repository }}" IMAGE_NAME="ghcr.io/${{ github.repository }}"
docker build -t "$IMAGE_NAME:latest" . TAG="${{ github.sha }}"
docker push "$IMAGE_NAME:latest" docker build -t "$IMAGE_NAME:$TAG" .
docker push "$IMAGE_NAME:$TAG"
# Step 5: Set up kubeconfig for Kubernetes access
- name: Set up kubeconfig - name: Set up kubeconfig
run: | run: |
mkdir -p ~/.kube mkdir -p ~/.kube
@ -40,9 +47,11 @@ jobs:
env: env:
KUBECONFIG: ~/.kube/config KUBECONFIG: ~/.kube/config
# Step 6: Deploy the Docker image to Kubernetes
- name: Deploy to Kubernetes - name: Deploy to Kubernetes
run: | run: |
IMAGE_NAME="ghcr.io/${{ github.repository }}" IMAGE_NAME="ghcr.io/${{ github.repository }}"
kubectl set image deployment/homepage homepage=$IMAGE_NAME:latest -n web TAG="${{ github.sha }}"
kubectl set image deployment/homepage homepage=$IMAGE_NAME:$TAG -n web
env: env:
KUBECONFIG: ~/.kube/config KUBECONFIG: ~/.kube/config