# Canifa Note - Auto-Build Setup

This directory contains automated build configuration to rebrand Memos as **Canifa Note** and containerize it.

## 📦 What's Included

- **Dockerfile** - Multi-stage build with auto-rebranding support
- **auto-build.sh** - Local build script (pull code + build + push)
- **docker-compose.yml** - One-command local deployment
- **.github/workflows/build-canifa.yml** - Automated CI/CD on GitHub

## 🚀 Quick Start

### Option 1: Local Build (Manual)
```bash
cd /home/anhvh/app/outservice/memos
chmod +x auto-build.sh
./auto-build.sh latest
```

### Option 2: Docker Compose (Easiest)
```bash
cd /home/anhvh/app/outservice/memos
docker compose up --build -d
```
Access at: **http://localhost:5230**

### Option 3: Manual Docker Build
```bash
docker build \
  --build-arg APP_NAME=canifa-note \
  --build-arg APP_ICON=canifa \
  --build-arg BUILD_VERSION=v1.0 \
  -t canifa-note:latest .

docker run -p 5230:5230 -v canifa-data:/app/data canifa-note:latest
```

## 🔄 Auto-Rebranding Features

The build process automatically:
1. ✅ Pulls latest code from git
2. ✅ Replaces "Memos" → "Canifa Note" in Go/TS/JSON files
3. ✅ Renames Docker image to `canifa-note:latest`
4. ✅ Tags with version (git tag or timestamp)
5. ✅ Optionally pushes to Docker registry

## 📝 Customization

Set environment variables before building:

```bash
# Set custom app name and icon
export APP_NAME=my-app
export APP_ICON=my-icon
export REGISTRY=myregistry.azurecr.io

./auto-build.sh latest
```

### GitHub Actions Setup (CI/CD)

To enable automated builds on every push:

1. Add secrets to GitHub repo:
   - `DOCKER_REGISTRY` - e.g., `docker.io` or `myregistry.azurecr.io`
   - `DOCKER_USERNAME` - Registry username
   - `DOCKER_PASSWORD` - Registry token/password

2. Workflow runs automatically on:
   - Push to main/master/develop
   - Manual trigger via GitHub Actions UI
   - Pull requests

## 🛠️ Technical Details

### Dockerfile Architecture
- **Stage 1**: Go build environment - compiles binary with custom branding
- **Stage 2**: Alpine runtime - minimal image (~80-100MB)
- **BuildArgs**: APP_NAME, APP_ICON, BUILD_VERSION for flexibility

### File Replacements
The build process uses sed to replace:
- Go source files (*.go)
- TypeScript components (*.ts, *.tsx)
- Configuration files (*.json)

Pattern: Case-insensitive "memos" → Custom APP_NAME

### Health Check
Endpoint: `GET /api/v1/ping` (returns 200 if healthy)

## 📊 Image Info

```bash
# View built images
docker images | grep canifa-note

# Inspect image
docker inspect canifa-note:latest

# Check container logs
docker logs canifa-note
```

## 🔗 Related

- Original Memos: https://github.com/usememos/memos
- Docker Hub: https://hub.docker.com/r/your-org/canifa-note
- Deployment: See `docker-compose.yml` for volume/port config

## ⚠️ Notes

- First build takes longer (Go compilation)
- Subsequent builds use Docker cache (faster)
- Branding replacement uses regex - test with actual codebase
- Volume `canifa-data` persists note database
