avisenna-landing-page/.github/workflows/build-and-deploy.yaml
2025-04-11 08:49:50 +00:00

57 lines
1.7 KiB
YAML

name: Build and Deploy to Kubernetes
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
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 }}"
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:
registry: ghcr.io
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 }}"
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
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
env:
KUBECONFIG: ~/.kube/config
# Step 6: Deploy the Docker image to Kubernetes
- name: Deploy to Kubernetes
run: |
IMAGE_NAME="ghcr.io/${{ github.repository }}"
TAG="${{ github.sha }}"
kubectl set image deployment/homepage homepage=$IMAGE_NAME:$TAG -n web
env:
KUBECONFIG: ~/.kube/config