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/db/db.go b/db/db.go index 1cd68a6..db16f30 100644 --- a/db/db.go +++ b/db/db.go @@ -11,7 +11,11 @@ var Conn *sql.DB func Init() { var err error +<<<<<<< HEAD Conn, err = sql.Open("sqlite", "./saas_bot.db") +======= + Conn, err = sql.Open("sqlite", "./data/bot.db") +>>>>>>> 63654c4c1b55ddcfeb4a5adf43d0a1778236c58d if err != nil { panic(err) }