chore: update .dockerignore and Dockerfile for improved build context and permissions

This commit is contained in:
krau
2025-05-19 09:23:24 +08:00
parent 729e688748
commit a474fdf6ae
3 changed files with 25 additions and 11 deletions

View File

@@ -1,7 +1,11 @@
*.md
.git
.github
.github/
.gitignore
.vscode
.vscode/
downloads/
data/
cache/
docs
docker-compose.yml
config.example.toml
docker-compose.*

View File

@@ -2,12 +2,9 @@ FROM golang:alpine AS builder
WORKDIR /app
COPY go.* ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o saveany-bot .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X github.com/krau/SaveAny-Bot/common.Version=Docker" -o saveany-bot .
FROM alpine:latest
@@ -15,13 +12,13 @@ RUN addgroup -S saveany && adduser -S saveany -G saveany
WORKDIR /app
RUN mkdir -p /app/data /app/downloads /app/cache && \
chown -R saveany:saveany /app
COPY --from=builder /app/saveany-bot .
RUN mkdir -p /app/data /app/downloads /app/cache && \
chown -R saveany:saveany /app /app/downloads /app/cache /app/data
RUN chmod +x /app/saveany-bot
USER saveany
CMD ["./saveany-bot"]
ENTRYPOINT ["/app/saveany-bot"]

13
docker-compose.local.yml Normal file
View File

@@ -0,0 +1,13 @@
services:
saveany-bot:
build: .
container_name: saveany-bot
restart: unless-stopped
volumes:
- ./data:/app/data
- ./config.toml:/app/config.toml
- ./downloads:/app/downloads
- ./cache:/app/cache
# 使用 host 模式以便访问宿主机服务 (如代理)
# 如果你对 Docker 网络模式熟悉, 可以自行修改
network_mode: host