Files
links/.github/workflows/build-and-deploy.yml
T
junvandGitHub 22d33f4e93 Upgrade GitHub Actions to latest versions
Updated GitHub Actions to use newer versions of actions for checkout, setup-uv, login, metadata, and build-push.
2026-03-27 11:46:47 +11:00

86 lines
2.1 KiB
YAML

name: Build and Deploy to Kubernetes
on:
push:
branches: [ main ]
pull_request:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
K8S_NAMESPACE: apps
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies (including dev)
run: uv sync --dev
- name: Run tests
env:
DJANGO_SETTINGS_MODULE: core.settings
FILE_UPLOADS_FOLDER: /tmp/test-uploads
run: uv run pytest tests/ -v --tb=short
build-and-deploy:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push main application image
- name: Build and push Docker image
uses: docker/build-push-action@v6
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