mirror of
https://github.com/wahyd4/links.git
synced 2026-08-09 05:06:16 +10:00
58 lines
1.5 KiB
YAML
58 lines
1.5 KiB
YAML
name: Build and Deploy to Kubernetes
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ] # Trigger the action on push to main branch
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
K8S_NAMESPACE: default # Replace with your Kubernetes namespace
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Log in to the Container registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
- name: Set up kubectl
|
|
uses: wahyd4/kubectl-helm-action@master
|
|
env:
|
|
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
|
|
|
|
- name: Deploy to Kubernetes
|
|
run: |
|
|
# Update the deployment.yaml with the new image tag
|
|
sed -i 's|image: .*|image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}|' k8s/deployment.yaml
|
|
|
|
# Apply Kubernetes manifests
|
|
kubectl apply -n apps -f k8s/deployment.yaml
|
|
env:
|
|
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
|