-
Notifications
You must be signed in to change notification settings - Fork 2k
添加docker配置 #1290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
guohuiyuan
wants to merge
12
commits into
FloatTech:master
Choose a base branch
from
guohuiyuan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
添加docker配置 #1290
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b1cad21
feat (docker):添加 Dockerfile 和 docker-compose 以实现容器化
guohuiyuan ae2795a
fix(banner): 改进标签检索逻辑以处理缺失的标签
guohuiyuan f20d622
fix(docker): 更新 docker-compose 中的镜像名称,并添加 Docker 登录的调试步骤
guohuiyuan 5432e7f
fix(docker): 更正调试步骤中 Docker Hub 用户名的秘密变量名称
guohuiyuan 9325783
fix(docker): 更新 Docker 镜像路径以使用固定的仓库名称
guohuiyuan b924181
fix(docker): 移除 Docker 登录凭据的调试步骤
guohuiyuan 0021fd9
fix(docker): 为 Docker 构建添加 cache-from 选项,以优化镜像构建
guohuiyuan 72186f3
fix(docker): 在 Docker 元数据提取中为最新版本添加原始标签
guohuiyuan 9dfbdd2
feat(docker): 添加 Docker 使用说明,并在.dockerignore 中包含 config.json
guohuiyuan b0b7480
fix(docker): 添加一个命令,使用指定的配置文件来运行机器人
guohuiyuan dc11914
Merge branch 'master' of github.com:guohuiyuan/ZeroBot-Plugin
guohuiyuan f12f463
feat(docker): 使用卷挂载和环境变量更新 Docker 运行指令
guohuiyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| .git | ||
| .github | ||
| .gitlab-ci.yml | ||
| .dockerignore | ||
| # VCS | ||
| .git | ||
| .github | ||
| .gitlab-ci.yml | ||
|
|
||
| # Docker / misc | ||
| .dockerignore | ||
| .DS_Store | ||
| .env | ||
| .env.local | ||
|
|
||
| # Editors/IDEs | ||
| .vscode | ||
| .idea | ||
| *.swp | ||
| *.swo | ||
|
|
||
| # Node / build artifacts | ||
| node_modules | ||
|
|
||
| # Common binary / build outputs | ||
| bin/ | ||
| dist/ | ||
| _build/ | ||
| *.exe | ||
| *.exe~ | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
| *.out | ||
| *.test | ||
|
|
||
| # Logs, caches, temporary files | ||
| *.log | ||
| *.tmp | ||
| *.prof | ||
| coverage.out | ||
| *.coverprofile | ||
| .cache | ||
| tmp/ | ||
| temp/ | ||
|
|
||
| # Go test / tooling | ||
| Godeps/ | ||
| *.test | ||
|
|
||
| # Generated files and large data | ||
| **/gen/ | ||
| data/ | ||
| downloads | ||
| docs/ | ||
|
|
||
| # Keep module files and Dockerfile in context | ||
| !go.mod | ||
| !go.sum | ||
| !Dockerfile | ||
| config.json | ||
| .env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Copy this file to .env and fill values before using docker-compose | ||
| # Docker Hub account to push images (required for CI pushes) | ||
| DOCKERHUB_USERNAME=yourhubuser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| name: Build And Push Docker Image | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| # Sequence of patterns matched against refs/tags | ||
| tags: | ||
| - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| packages: write | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Set time zone | ||
| uses: szenius/set-timezone@v1.0 | ||
| with: | ||
| timezoneLinux: "Asia/Shanghai" | ||
| timezoneMacos: "Asia/Shanghai" | ||
| timezoneWindows: "China Standard Time" | ||
|
|
||
| # # 如果有 dockerhub 账户,可以在github的secrets中配置下面两个,然后取消下面注释的这几行,并在meta步骤的images增加一行 ${{ github.repository }} | ||
| # - name: Login to DockerHub | ||
| # uses: docker/login-action@v1 | ||
| # with: | ||
| # username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| # password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
|
||
| - name: Login to DockerHub | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
|
||
| - name: Extract metadata (tags, labels) for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v4 | ||
| with: | ||
| images: | | ||
| docker.io/${{ secrets.DOCKERHUB_USERNAME }}/zerobot-plugin | ||
| tags: | | ||
| type=schedule,pattern=nightly | ||
| type=edge | ||
| type=ref,event=branch | ||
| type=ref,event=pr | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
| type=semver,pattern={{major}} | ||
| type=raw,value=latest | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v2 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
|
|
||
| - name: Build and push | ||
| id: docker_build | ||
| uses: docker/build-push-action@v4 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,6 @@ zerobot | |
| ZeroBot-Plugin* | ||
| *.syso | ||
| /.direnv | ||
| /result | ||
| /result | ||
| config.json | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Build stage | ||
| FROM golang:1.25 AS builder | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy go mod files | ||
| COPY go.mod go.sum ./ | ||
|
|
||
| # Download dependencies | ||
| RUN go mod download | ||
|
|
||
| # Copy source code | ||
| COPY . . | ||
|
|
||
| # Run code generators (generate banner and other generated files) | ||
| RUN go generate main.go | ||
|
|
||
| # Build the application | ||
| RUN CGO_ENABLED=0 GOOS=linux go build -o zerobot-plugin . | ||
|
|
||
| # Runtime stage | ||
| FROM alpine:latest | ||
|
|
||
| # [新增] 替换为阿里云镜像源,解决 TLS 连接错误和速度慢的问题 | ||
| RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories | ||
|
|
||
| # Install ca-certificates for HTTPS requests | ||
| RUN apk --no-cache add ca-certificates | ||
|
|
||
| # Create a non-root user | ||
| RUN adduser -D -s /bin/sh appuser | ||
|
|
||
| # Set working directory | ||
| WORKDIR /home/appuser/ | ||
|
|
||
| # Copy the binary from builder stage | ||
| COPY --from=builder /app/zerobot-plugin . | ||
|
|
||
| # Create data directory and set ownership | ||
| RUN mkdir -p /home/appuser/data \ | ||
| && chown -R appuser:appuser /home/appuser/ | ||
|
|
||
| # Declare data as a mountable volume | ||
| VOLUME ["/home/appuser/data"] | ||
|
|
||
| # Switch to non-root user | ||
| USER appuser | ||
|
|
||
| RUN /home/appuser/zerobot-plugin -s /home/appuser/config.json || true | ||
|
|
||
| # Run the bot by default (absolute path) | ||
| CMD ["/home/appuser/zerobot-plugin"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| services: | ||
| zerobot-plugin: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| image: ${DOCKERHUB_USERNAME}/zerobot-plugin:latest | ||
| container_name: zerobot-plugin | ||
| restart: unless-stopped | ||
| working_dir: /home/appuser | ||
| environment: | ||
| - TZ=Asia/Shanghai | ||
| volumes: | ||
| - ./data:/home/appuser/data | ||
| - ./config.json:/home/appuser/config.json | ||
| command: ["/home/appuser/zerobot-plugin", "-c", "/home/appuser/config.json"] | ||
| user: "1000:1000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,9 +42,34 @@ func main() { | |
| if err != nil { | ||
| panic(err) | ||
| } | ||
| s := strings.Split(vartag.String(), "\n") | ||
| // parse tags safely; if no tags available, fallback to commit hash or default | ||
| tagsOut := strings.TrimSpace(vartag.String()) | ||
| var tag string | ||
| if tagsOut == "" { | ||
| // no tags; try commit short hash | ||
| rev := exec.Command("git", "rev-parse", "--short", "HEAD") | ||
| var revOut bytes.Buffer | ||
| rev.Stdout = &revOut | ||
| if rev.Run() == nil { | ||
| tag = strings.TrimSpace(revOut.String()) | ||
| } else { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个和下面的else冗余了,直接在最后判断一次 |
||
| tag = "v0.0.0" | ||
| } | ||
| } else { | ||
| parts := strings.Split(tagsOut, "\n") | ||
| // last non-empty line is the newest tag | ||
| for i := len(parts) - 1; i >= 0; i-- { | ||
| if parts[i] != "" { | ||
| tag = parts[i] | ||
| break | ||
| } | ||
| } | ||
| if tag == "" { | ||
| tag = "v0.0.0" | ||
| } | ||
| } | ||
| now := time.Now() | ||
| _, err = fmt.Fprintf(f, banner, s[len(s)-2], now.Year(), now.Format(timeformat)) | ||
| _, err = fmt.Fprintf(f, banner, tag, now.Year(), now.Format(timeformat)) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个secret是你的?