54 lines
1.7 KiB
YAML
54 lines
1.7 KiB
YAML
name: Build and Deploy
|
|
run-name: ${{ github.actor }} is building and pushing 🚀
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
|
|
env:
|
|
REGISTRY: git.chopark.home
|
|
IMAGE: ${{ gitea.repository }}
|
|
DEPLOYMENT_NAME: ${{ gitea.repository##*/ }}-deployment # optional generic name
|
|
CONTAINER_NAME: ${DEPLOYMENT_NAME} # optional generic container name
|
|
NAMESPACE: catalog # optional namespace for the deployment
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Login to Gitea Registry
|
|
# We use single quotes around the secret to prevent shell interpretation
|
|
# and the VM IP to bypass the 'server' DNS issue.
|
|
run: |
|
|
echo '${{ secrets.REGISTRY_TOKEN }}' | \
|
|
docker login ${{ env.REGISTRY }} \
|
|
--username ${{ gitea.actor }} \
|
|
--password-stdin
|
|
|
|
- name: Build and Push Docker Image
|
|
run: |
|
|
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE }}:latest .
|
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE }}:latest
|
|
|
|
- name: List files in the repository
|
|
run: ls ${{ github.workspace }}
|
|
|
|
- run: echo "🍏 Build and Push status is ${{ job.status }}."
|
|
|
|
deploy-to-k8s:
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Set Kubeconfig
|
|
run: |
|
|
echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig.yaml
|
|
- name: Update Deployment Image
|
|
run: |
|
|
# export KUBECONFIG=kubeconfig.yaml
|
|
kubectl set image \
|
|
deployment/${{ env.DEPLOYMENT_NAME }} \
|
|
${{ env.CONTAINER_NAME }}=${{ env.REGISTRY }}/${{ env.IMAGE }}:latest \
|
|
-n ${{ env.NAMESPACE }} |