54 lines
1.5 KiB
YAML
54 lines
1.5 KiB
YAML
name: Build and Deploy to Kubernetes
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
env:
|
|
KUBECONFIG: ${HOME}/.kube/config
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Debug repository name
|
|
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"
|
|
shell: bash
|
|
|
|
- name: Set up Kubeconfig
|
|
run: |
|
|
mkdir -p ${HOME}/.kube
|
|
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ${HOME}/.kube/config
|
|
chmod 600 ${HOME}/.kube/config
|
|
export KUBECONFIG=${HOME}/.kube/config
|
|
kubectl version --client
|
|
kubectl cluster-info
|
|
cat ${HOME}/.kube/config
|
|
shell: bash
|
|
|
|
- name: Deploy to Kubernetes
|
|
run: |
|
|
export KUBECONFIG=${HOME}/.kube/config
|
|
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
|
kubectl set image deployment/homepage home=$IMAGE_NAME:v0.0.1 -n web
|
|
shell: bash
|