mirror of
https://github.com/wahyd4/links.git
synced 2026-08-09 05:06:16 +10:00
59 lines
1.6 KiB
YAML
59 lines
1.6 KiB
YAML
name: Build and Deploy to Kubernetes
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
K8S_NAMESPACE: apps
|
|
|
|
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 }}
|
|
|
|
# Build and push main application image
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: |-
|
|
${{ steps.meta.outputs.tags }}
|
|
ghcr.io/wahyd4/links:1.0.${{ github.run_number }}
|
|
labels: |-
|
|
${{ steps.meta.outputs.labels }}
|
|
|
|
- name: Deploy to Kubernetes
|
|
uses: wahyd4/kubectl-helm-action@master
|
|
env:
|
|
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
|
|
with:
|
|
args: |-
|
|
# Update both deployments with new image tags
|
|
sed -i 's|image: .*|image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:1.0.${{ github.run_number }}|' k8s/manifest.yaml
|
|
# Apply Kubernetes manifests
|
|
kubectl --insecure-skip-tls-verify apply -n ${{ env.K8S_NAMESPACE }} -f k8s/manifest.yaml
|