Cleaned up and unified GitHub Actions deploy workflow
This commit is contained in:
parent
d0cdfbfa55
commit
f9fe3ff743
1 changed files with 48 additions and 0 deletions
48
.github/workflows/build-and-deploy.yaml
vendored
Normal file
48
.github/workflows/build-and-deploy.yaml
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
name: Build and Deploy to Kubernetes
|
||||
|
||||
# Uncomment to enable auto-deployment on push to main
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Debug Repository Info
|
||||
run: echo "Repository: ${{ github.repository }}"
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
run: |
|
||||
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
||||
docker build -t "$IMAGE_NAME:latest" .
|
||||
docker push "$IMAGE_NAME:latest"
|
||||
|
||||
- name: Set up kubeconfig
|
||||
run: |
|
||||
mkdir -p ~/.kube
|
||||
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
|
||||
chmod 600 ~/.kube/config
|
||||
env:
|
||||
KUBECONFIG: ~/.kube/config
|
||||
|
||||
- name: Deploy to Kubernetes
|
||||
run: |
|
||||
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
||||
kubectl set image deployment/homepage homepage=$IMAGE_NAME:latest -n web
|
||||
env:
|
||||
KUBECONFIG: ~/.kube/config
|
||||
Loading…
Reference in a new issue