diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6ba89fb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.vscode +.git +data/ +bot.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ccf7771 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM golang:1.25-alpine AS builder + +# Ensure CGO is off for a static binary +ENV CGO_ENABLED=0 +# Ensure Go modules are strictly enforced +ENV GO111MODULE=on + +WORKDIR /app + +# Copy only the dependency files first +COPY go.mod go.sum ./ +RUN go mod download + +# Copy the entire project structure +COPY . . + +# Build from the current directory (.) so it finds the module root +RUN go build -o /app/bot . + +FROM alpine:latest + +RUN apk --no-cache add ca-certificates +RUN mkdir /data + +WORKDIR /root/ + +COPY --from=builder /app/bot . +COPY --from=builder /app/templates ./templates +COPY .env . + +ENV DB_PATH=/data/bot.db + +CMD ["./bot"] \ No newline at end of file diff --git a/README.md b/README.md index e9b0a7a..d843755 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,40 @@ # whatsapp-bot +## 🐳 Docker Deployment (Server) + +Build and run the central inventory server: + +```bash +# Build the image +docker build -t go-bot:latest . + +# Run the container (Map port 9090 and persist the database/cache) +docker run -d \ + --name whatsapp-bot \ + -p 9090:9090 \ + -e OPENROUTER_API_KEY=your_key \ + -e WHATSAPP_PHONE_ID=your_id \ + -e WHATSAPP_TOKEN=your_token \ + -v $(pwd)/whatsapp-bot/data:/root/data:Z \ + --restart unless-stopped \ + go-bot:latest +``` + +Or use this stack: +```yml +services: + bot: + image: go-bot:latest + container_name: whatsapp-bot + restart: unless-stopped + environment: + - OPENROUTER_API_KEY=your_api_key_here + - WHATSAPP_PHONE_ID=your_phone_id_here + - WHATSAPP_TOKEN=your_token_here + volumes: + # Map host data folder to the app's data path + # The :Z is required for SELinux (Fedora/RHEL) + - YOUR_PATH/whatsapp-bot/data:/root/data:Z + ports: + - "8080:9090" +``` diff --git a/bot.db b/bot.db deleted file mode 100644 index 514ac89..0000000 Binary files a/bot.db and /dev/null differ diff --git a/db/db.go b/db/db.go index 42ffff1..e40214f 100644 --- a/db/db.go +++ b/db/db.go @@ -10,7 +10,7 @@ var Conn *sql.DB func Init() { var err error - Conn, err = sql.Open("sqlite", "./bot.db") + Conn, err = sql.Open("sqlite", "./data/bot.db") if err != nil { panic(err) } diff --git a/go.mod b/go.mod index d20bad1..2ed9a8e 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.25.0 require ( github.com/gin-gonic/gin v1.12.0 + github.com/joho/godotenv v1.5.1 modernc.org/sqlite v1.46.1 ) @@ -21,7 +22,6 @@ require ( github.com/goccy/go-json v0.10.5 // indirect github.com/goccy/go-yaml v1.19.2 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/joho/godotenv v1.5.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect