From 1f8529badc121464c5f79276409424d54ec6c99c Mon Sep 17 00:00:00 2001 From: XingfenD Date: Thu, 27 Aug 2026 15:32:47 +0800 Subject: [PATCH 1/2] feat: add Docker deployment support Add Dockerfile, docker-compose.yml, .dockerignore, .env.example, Makefile docker targets, and README/CHANGELOG docs. --- .dockerignore | 10 ++++++++++ .env.example | 3 +++ Dockerfile | 19 +++++++++++++++++++ Makefile | 11 ++++++++++- docker-compose.yml | 15 +++++++++++++++ docs/CHANGELOG.md | 13 +++++++++++++ docs/README.md | 27 +++++++++++++++++++++++++++ 7 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2b7b8d9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git +.gitignore +*.md +docs +tests +workspace +yDropbox +docker-compose.yml +.env +.env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..03d7957 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +# 访问令牌(必填)。请将下方示例替换为高强度随机字符串。 +# Access token (required). Replace the example below with a strong random string. +YDROPBOX_TOKEN=change-me-to-a-strong-random-token diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8b586f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.25-alpine AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/yDropbox ./cmd/ydropbox + +FROM alpine:3.20 +RUN adduser -D -u 10001 -s /sbin/nologin ydropbox \ + && apk add --no-cache ca-certificates tzdata +WORKDIR /app +COPY --from=build /out/yDropbox /app/yDropbox +USER ydropbox +VOLUME /app/workspace +EXPOSE 8999 +ENTRYPOINT ["/app/yDropbox"] +CMD ["--addr", "0.0.0.0:8999", "--workspace", "/app/workspace"] diff --git a/Makefile b/Makefile index e5a96c2..a738339 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BINARY := yDropbox PKG := ./cmd/ydropbox -.PHONY: build test run clean vet +.PHONY: build test run clean vet docker docker-up docker-down build: CGO_ENABLED=0 go build -o $(BINARY) $(PKG) @@ -17,3 +17,12 @@ vet: clean: rm -f $(BINARY) + +docker: + docker build -t ydropbox . + +docker-up: + docker compose up -d --build + +docker-down: + docker compose down diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0e60bba --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +services: + ydropbox: + build: . + image: yoresee/yDropbox:latest + container_name: ydropbox + restart: unless-stopped + ports: + - "8999:8999" + environment: + YDROPBOX_TOKEN: ${YDROPBOX_TOKEN:?set YDROPBOX_TOKEN in .env} + volumes: + - ydropbox-data:/app/workspace + +volumes: + ydropbox-data: diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 541ba7e..683e86f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,19 @@ All notable changes to this template should be documented in this file. The format loosely follows Keep a Changelog and can be adapted to the team's habits. 本文档参考了 Keep a Changelog 的思路,也可以根据团队习惯调整。 +## [0.1.0] - 2026-08-27 + +### Added / 新增 + +- Added Docker deployment support: `Dockerfile`, `.dockerignore`, `docker-compose.yml` and `.env.example`. +- 新增 Docker 部署支持:`Dockerfile`、`.dockerignore`、`docker-compose.yml` 与 `.env.example`。 + +- Added `make docker` / `make docker-up` / `make docker-down` convenience targets to the Makefile. +- 在 Makefile 中新增 `make docker` / `make docker-up` / `make docker-down` 便捷命令。 + +- Documented Docker deployment in `docs/README.md`. +- 在 `docs/README.md` 中补充了 Docker 部署说明。 + ## [0.0.1] - 2026-04-28 ### Added / 新增 diff --git a/docs/README.md b/docs/README.md index 6c4387d..302400c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,6 +49,33 @@ make vet # 静态检查 (go vet ./...) make clean # 删除二进制文件 ``` +## Docker 部署 + +项目提供了 `Dockerfile` 与 `docker-compose.yml`,将编译产物打包为单一镜像(前端资源已通过 `go:embed` 内嵌,SQLite 为纯 Go 实现,镜像无外部依赖)。 + +### 使用 Docker Compose(推荐) + +```bash +cp .env.example .env +# 编辑 .env,设置 YDROPBOX_TOKEN 为一个高强度随机字符串 +docker compose up -d --build +``` + +服务启动后监听 `8999` 端口,文件与数据库持久化在名为 `ydropbox-data` 的卷中。 + +### 仅使用 Docker + +```bash +docker build -t ydropbox . +docker run -d --name ydropbox \ + -p 8999:8999 \ + -e YDROPBOX_TOKEN=YOUR_SECRET_TOKEN \ + -v "$(pwd)/workspace:/app/workspace" \ + ydropbox +``` + +> 注意:必须通过 `-e YDROPBOX_TOKEN=...` 或 `--token` 提供访问令牌,否则服务启动会失败(与本地运行一致)。 + ## 配置 | 参数 / 环境变量 | 说明 | 默认值 | From 3171866344303e221ecb7253133646355528c663 Mon Sep 17 00:00:00 2001 From: XingfenD Date: Thu, 27 Aug 2026 15:32:57 +0800 Subject: [PATCH 2/2] chore: gitignore local .env file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1965240..23fe6a2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ Thumbs.db # Superpowers workspace .superpowers/ + +# local env with secrets +.env