fix git actions error using copilot advice
This commit is contained in:
parent
f9fe3ff743
commit
f9f5119be1
1 changed files with 14 additions and 5 deletions
19
.github/workflows/build-and-deploy.yaml
vendored
19
.github/workflows/build-and-deploy.yaml
vendored
|
|
@ -1,6 +1,5 @@
|
|||
name: Build and Deploy to Kubernetes
|
||||
|
||||
# Uncomment to enable auto-deployment on push to main
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
|
@ -13,12 +12,17 @@ jobs:
|
|||
packages: write
|
||||
|
||||
steps:
|
||||
# Step 1: Checkout the repository code
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Step 2: Debug repository information (optional)
|
||||
- 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
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
|
|
@ -26,12 +30,15 @@ jobs:
|
|||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Step 4: Build and Push Docker Image with unique tag
|
||||
- name: Build and Push Docker Image
|
||||
run: |
|
||||
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
||||
docker build -t "$IMAGE_NAME:latest" .
|
||||
docker push "$IMAGE_NAME:latest"
|
||||
TAG="${{ github.sha }}"
|
||||
docker build -t "$IMAGE_NAME:$TAG" .
|
||||
docker push "$IMAGE_NAME:$TAG"
|
||||
|
||||
# Step 5: Set up kubeconfig for Kubernetes access
|
||||
- name: Set up kubeconfig
|
||||
run: |
|
||||
mkdir -p ~/.kube
|
||||
|
|
@ -40,9 +47,11 @@ jobs:
|
|||
env:
|
||||
KUBECONFIG: ~/.kube/config
|
||||
|
||||
# Step 6: Deploy the Docker image to Kubernetes
|
||||
- name: Deploy to Kubernetes
|
||||
run: |
|
||||
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:
|
||||
KUBECONFIG: ~/.kube/config
|
||||
|
|
|
|||
Loading…
Reference in a new issue