openscopelabs's picture
feat(scan): right-click scan-mode alerting + per-camera pose
d6b1333
Raw History Blame Contribute Delete
4.97 kB
name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE: ghcr.io/${{ github.repository }}
DOCKER_NETWORK: cakra-network
CONTAINER: cakra-yolo
# CPU cap. cgroup v2 throttles peaks above this — keeps inference
# fast (~10 fps on 4 cores of an 8-core EPYC) without starving the
# NestJS API + ffmpeg encoders sharing the same VM.
CPUS: "4"
jobs:
build:
name: Build & push image
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.meta.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=sha,format=short,prefix=sha-
type=raw,value=latest,enable={{is_default_branch}}
# Dockerfile bakes the M YOLO-World weights + ONNX export at build
# time. Heavy build (~6-10 min cold); gha cache cuts that to
# ~2-3 min on code-only edits.
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
build-args: |
YOLO_BUILD_FAMILY=yolov8
YOLO_BUILD_SIZE=m
YOLO_EXPORT_IMGSZ=640
deploy:
name: Deploy to VM
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy container (docker run)
uses: appleboy/ssh-action@v1.2.0
env:
YOLO_ENV_FILE: ${{ secrets.YOLO_ENV_FILE }}
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
key: ${{ secrets.VM_SSH_KEY }}
port: ${{ secrets.VM_SSH_PORT || 22 }}
envs: YOLO_ENV_FILE
script: |
set -euo pipefail
NET="${{ env.DOCKER_NETWORK }}"
NAME="${{ env.CONTAINER }}"
CPUS="${{ env.CPUS }}"
IMAGE="${{ env.IMAGE }}:${{ needs.build.outputs.image_tag }}"
# cakra-network shared with the platform's API container so
# backend can reach this service via http://${NAME}:7860
# without exposing any public port.
sudo docker network inspect "$NET" >/dev/null 2>&1 \
|| sudo docker network create "$NET"
# Write .env (held in YOLO_ENV_FILE secret) — DATABASE_URL,
# CAKRA_PROFILE=vps, MODEL_PATH override etc. Stored at
# /opt/cakra/yolo/.env so it survives container recreate.
if [ -z "${YOLO_ENV_FILE:-}" ]; then
echo "✗ YOLO_ENV_FILE secret kosong"
exit 1
fi
sudo install -d -m 750 /opt/cakra/yolo
sudo install -d -m 770 /opt/cakra/yolo/alerts
umask 077
printf '%s' "$YOLO_ENV_FILE" | sudo tee /opt/cakra/yolo/.env > /dev/null
sudo chmod 600 /opt/cakra/yolo/.env
echo "${{ secrets.GITHUB_TOKEN }}" \
| sudo docker login ghcr.io -u "${{ github.actor }}" --password-stdin
sudo docker pull "$IMAGE"
sudo docker logout ghcr.io || true
# Replace running container atomically.
sudo docker rm -f "$NAME" >/dev/null 2>&1 || true
sudo docker run -d \
--name "$NAME" \
--restart unless-stopped \
--network "$NET" \
--cpus "$CPUS" \
--env-file /opt/cakra/yolo/.env \
--tmpfs /tmp/cakra-hls:size=512m,mode=755 \
-v /opt/cakra/yolo/alerts:/opt/cakra/yolo/alerts \
--log-opt max-size=10m --log-opt max-file=5 \
"$IMAGE"
# Healthcheck via container exec (no public port).
for i in $(seq 1 30); do
if sudo docker exec "$NAME" curl -fsS http://127.0.0.1:7860/health >/dev/null 2>&1; then
echo "✓ healthy after $((i*2))s"; exit 0
fi
sleep 2
done
echo "✗ tidak healthy dalam 60 detik"
sudo docker logs --tail=200 "$NAME"
exit 1
- name: Prune old images
if: success()
continue-on-error: true
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
key: ${{ secrets.VM_SSH_KEY }}
port: ${{ secrets.VM_SSH_PORT || 22 }}
script: |
sudo docker image prune -af --filter "until=168h" || true