dockerfile + db relocation

This commit is contained in:
2026-03-02 00:17:32 -03:00
parent 9ff021879f
commit 63654c4c1b
6 changed files with 77 additions and 2 deletions

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
.vscode
.git
data/
bot.db

33
Dockerfile Normal file
View File

@@ -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"]

View File

@@ -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"
```

BIN
bot.db

Binary file not shown.

View File

@@ -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)
}

2
go.mod
View File

@@ -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