avisenna-landing-page/.github/workflows/build-and-deploy.yaml
2025-04-11 20:15:41 +00:00

56 lines
1.6 KiB
YAML

name: Build and Deploy
on:
push:
branches:
- main
- dev
- 'feat/**'
- 'test/**'
- 'fix/**'
- 'hotfix/**'
env:
VERSION: ${{ vars.VERSION || 'latest' }}
NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
run: |
IMAGE_NAME="ghcr.io/${{ github.repository }}:$VERSION"
docker build -t $IMAGE_NAME .
docker push $IMAGE_NAME
- name: Set up kubeconfig from secret
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > $HOME/.kube/config
shell: bash
- name: Detect container name
id: detect-container
run: |
CONTAINER=$(kubectl -n $NAMESPACE get deployment homepage -o=jsonpath='{.spec.template.spec.containers[0].name}')
echo "container=$CONTAINER" >> $GITHUB_OUTPUT
- name: Deploy to Kubernetes
run: |
IMAGE="ghcr.io/${{ github.repository }}:$VERSION"
kubectl set image deployment/homepage ${{ steps.detect-container.outputs.container }}=$IMAGE -n $NAMESPACE
env:
VERSION: ${{ vars.VERSION || 'latest' }}
NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }}