Files
buzz/.github/workflows/build.yml
T
dmgnr 41b24bd7c2
Build and Push Image / build-backend (push) Successful in 31s
Build and Push Image / build-frontend (push) Successful in 1m57s
Build and Push Image / push (push) Successful in 39s
fix(ci): update k3s api server
2026-08-30 14:11:11 +07:00

127 lines
5.0 KiB
YAML
Executable File

name: Build and Push Image
on:
workflow_dispatch:
push:
branches:
- main
- dev
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install kubectl
run: |
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -sLO "https://dl.k8s.io/release/v1.35.0/bin/linux/${ARCH}/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl
- name: Configure kubectl
run: |
kubectl config set-cluster buzz --server=https://astrxl-la3.neko-piranha.ts.net:6443 --insecure-skip-tls-verify=true
kubectl config set-credentials ci-deployer --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context buzz --cluster=buzz --user=ci-deployer --namespace=buzz
kubectl config use-context buzz
- name: Generate .env from K8s secret
run: |
kubectl get secret buzz-env -n buzz \
-o go-template='{{range $k,$v := .data}}{{$k}}={{$v|base64decode}}{{"\n"}}{{end}}' > .env
ls -l .env
- run: |
TAG=${{ gitea.sha }}
docker build \
-t registry.neko-piranha.ts.net/${{ gitea.repository }}:frontend \
-t registry.neko-piranha.ts.net/${{ gitea.repository }}:frontend-$TAG \
.
docker build --target migration \
-t registry.neko-piranha.ts.net/${{ gitea.repository }}:migration \
.
build-backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install kubectl
run: |
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -sLO "https://dl.k8s.io/release/v1.35.0/bin/linux/${ARCH}/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl
- name: Configure kubectl
run: |
kubectl config set-cluster buzz --server=https://astrxl-la3.neko-piranha.ts.net:6443 --insecure-skip-tls-verify=true
kubectl config set-credentials ci-deployer --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context buzz --cluster=buzz --user=ci-deployer --namespace=buzz
kubectl config use-context buzz
- name: Generate .env from K8s secret
run: |
kubectl get secret buzz-env -n buzz \
-o go-template='{{range $k,$v := .data}}{{$k}}={{$v|base64decode}}{{"\n"}}{{end}}' > .env
ls -l .env
- run: |
TAG=${{ gitea.sha }}
docker build \
-f backend.dockerfile \
-t registry.neko-piranha.ts.net/${{ gitea.repository }}:backend \
-t registry.neko-piranha.ts.net/${{ gitea.repository }}:backend-$TAG \
.
push:
needs: [build-frontend, build-backend]
runs-on: ubuntu-latest
steps:
- run: |
TAG=${{ gitea.sha }}
docker push registry.neko-piranha.ts.net/${{ gitea.repository }}:backend &
docker push registry.neko-piranha.ts.net/${{ gitea.repository }}:backend-$TAG &
docker push registry.neko-piranha.ts.net/${{ gitea.repository }}:frontend &
docker push registry.neko-piranha.ts.net/${{ gitea.repository }}:frontend-$TAG &
docker push registry.neko-piranha.ts.net/${{ gitea.repository }}:migration &
wait
- name: Install kubectl
run: |
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -sLO "https://dl.k8s.io/release/v1.35.0/bin/linux/${ARCH}/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl
- name: Configure kubectl
run: |
kubectl config set-cluster buzz --server=https://astrxl-la3.neko-piranha.ts.net:6443 --insecure-skip-tls-verify=true
kubectl config set-credentials ci-deployer --token=${{ secrets.KUBE_TOKEN }}
kubectl config set-context buzz --cluster=buzz --user=ci-deployer --namespace=buzz
kubectl config use-context buzz
- name: Deploy to k3s
run: |
TAG=${{ gitea.sha }}
# DB migration
kubectl delete job db-migrate -n buzz --ignore-not-found
kubectl create job db-migrate \
--image=registry.neko-piranha.ts.net/${{ gitea.repository }}:migration \
-n buzz \
--dry-run=client -o json \
-- bun dr push | \
jq '.spec.template.spec.containers[0].envFrom = [{"secretRef": {"name": "buzz-env"}}] | .spec.template.spec.containers[0].imagePullPolicy = "Always"' | \
kubectl apply -f -
# Roll app & backend
kubectl set image deployment/app app=registry.neko-piranha.ts.net/${{ gitea.repository }}:frontend-$TAG -n buzz
kubectl set image deployment/backend backend=registry.neko-piranha.ts.net/${{ gitea.repository }}:backend-$TAG -n buzz
kubectl rollout status deployment/app -n buzz --timeout=180s &
kubectl rollout status deployment/backend -n buzz --timeout=180s &
kubectl wait --for=condition=complete job/db-migrate -n buzz --timeout=600s &
wait