Skip to content

ci: 自动构建后端 Docker 镜像并发布到 GHCR (#106)#190

Merged
AmintaCCCP merged 5 commits into
mainfrom
feat/docker-ghcr-publish
Jun 2, 2026
Merged

ci: 自动构建后端 Docker 镜像并发布到 GHCR (#106)#190
AmintaCCCP merged 5 commits into
mainfrom
feat/docker-ghcr-publish

Conversation

@AmintaCCCP

@AmintaCCCP AmintaCCCP commented Jun 2, 2026

Copy link
Copy Markdown
Owner

概述

解决 #106 — 自动构建后端 Docker 镜像并发布到 GitHub Container Registry (ghcr.io),用户无需本地构建即可直接拉取使用。

变更内容

新增 .github/workflows/docker-publish.yml

  • Push 到 main 分支 → 自动构建并推送 latest 标签
  • Push v* 标签 → 自动生成语义化版本标签 (v1.2.3, 1.2.3, 1.2, 1)
  • 所有构建 → 附带 sha-<commit> 标签便于追溯
  • 使用 GITHUB_TOKEN 认证,无需配置额外 Secrets
  • Docker Buildx + GHA 缓存加速后续构建

更新 docker-compose.yml

  • Backend 服务默认从 ghcr.io/amintacccp/github-stars-manager-server:latest 拉取
  • 保留注释中的本地构建选项

更新文档

  • DOCKER.md — 新增 Quick Start 章节
  • README.md / README_zh.md — 添加 ghcr.io 拉取命令

使用方式

docker-compose up -d

合并后首次运行前,需要在 repo → Settings → Packages 中将镜像可见性设为 Public,否则用户需先 docker login ghcr.io

Summary by CodeRabbit

  • New Features

    • Pre-built backend container images published to the registry for quicker, simpler deployments.
  • Documentation

    • Quick Start and deployment docs updated with pulling/pinning image tags, backend-only run examples (optional secrets), full-stack compose workflow, and README updates in English and Chinese.
  • Chores

    • CI workflow added to automate building and publishing backend container images.

Closes #106

- Add .github/workflows/docker-publish.yml to auto-build and push
  backend Docker image to ghcr.io on main push and version tags
- Update docker-compose.yml to pull from ghcr.io by default
- Update DOCKER.md with Quick Start section for pre-built images
- Update README.md and README_zh.md with ghcr.io pull instructions
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a6601f6-4048-4f9d-af04-5c5584c2ca34

📥 Commits

Reviewing files that changed from the base of the PR and between 66526f6 and 5559e4d.

📒 Files selected for processing (3)
  • .github/workflows/docker-publish.yml
  • README.md
  • README_zh.md
✅ Files skipped from review due to trivial changes (1)
  • README_zh.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • README.md
  • .github/workflows/docker-publish.yml

📝 Walkthrough

Walkthrough

Adds a GitHub Actions workflow that builds and pushes the server Docker image to GHCR, switches docker-compose to reference the pre-built GHCR backend image, and updates DOCKER.md and README (EN/ZH) with pull, run, .env, and stopping guidance for using pre-built images.

Changes

Docker Image Publishing and Documentation

Layer / File(s) Summary
GitHub Actions workflow for GHCR publishing
.github/workflows/docker-publish.yml
New workflow publishes Docker images to GHCR (ghcr.io/amintacccp/github-stars-manager-server) on pushes to main, version tags v*, and manual dispatch; includes automated semver/latest/SHA tagging, Buildx build+push, and GitHub Actions cache.
Docker Compose image reference
docker-compose.yml
Backend service now references ghcr.io/amintacccp/github-stars-manager-server:${BACKEND_IMAGE_TAG:-latest} with commented instructions to revert to local build: ./server.
DOCKER.md quick start, examples, and stop flows
DOCKER.md
Reworks docs into a GHCR-focused Quick Start: compose pull/start, GHCR auth note, available tags and BACKEND_IMAGE_TAG pinning, backend docker run examples (volume, API_SECRET, ENCRYPTION_KEY), env table, local-build guidance, and updated stop instructions.
Documentation updates (EN & ZH)
README.md, README_zh.md
README and README_zh updated to use GHCR pre-built backend image, change quick start to docker-compose up -d, add .env examples (API_SECRET, ENCRYPTION_KEY, BACKEND_IMAGE_TAG), and add backend-only docker run examples.
sequenceDiagram
  participant GitHubActions
  participant DockerBuildx
  participant GHCR
  participant User
  GitHubActions->>DockerBuildx: build ./server using buildx
  DockerBuildx->>GHCR: push image + tags (semver / latest / sha)
  User->>GHCR: docker pull ghcr.io/amintacccp/github-stars-manager-server:latest
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped to the CI with a tiny cheer,
built the image swift and pushed it clear,
tags snug in place, compose now takes flight,
pull, run, and rest — the backend’s prebuilt right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding automated Docker image building and publishing to GHCR via GitHub Actions CI workflow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/docker-ghcr-publish

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
docker-compose.yml (1)

13-15: ⚡ Quick win

Avoid hard-coding mutable latest for backend image.

Using :latest in compose makes deployments non-reproducible and can cause surprise upgrades. Prefer a pinned version/digest with an env override.

Suggested change
-    image: ghcr.io/amintacccp/github-stars-manager-server:latest
+    image: ghcr.io/amintacccp/github-stars-manager-server:${BACKEND_IMAGE_TAG:-v0.6.2}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker-compose.yml` around lines 13 - 15, The docker-compose image is
hard-coded to ghcr.io/amintacccp/github-stars-manager-server:latest; change it
to use a pinned tag or digest and support an environment override (e.g., replace
the literal value with an env var like
${BACKEND_IMAGE:-ghcr.io/amintacccp/github-stars-manager-server:vX} or a digest)
and document adding BACKEND_IMAGE to .env so deployments are reproducible and
not using mutable :latest.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/docker-publish.yml:
- Line 22: Update the checkout step and other `uses:` entries to pin to audited
commit SHAs instead of tags and disable credential persistence: replace
`actions/checkout@v6` with its specific commit SHA for the release you rely on
and add `persist-credentials: false` to that checkout step; do the same SHA
pinning for any other `uses:` actions in the workflow to harden supply-chain
integrity and avoid leaving Git credentials in the runner.

In `@DOCKER.md`:
- Around line 10-28: Add a short prerequisite note to the "Quick Start (Using
Pre-built Images from GHCR)" section explaining that if the GHCR package is
private users must authenticate before pulling images; update the text around
the docker pull/docker-compose up commands to mention running "docker login
ghcr.io" (or equivalent GHCR auth) when images are not public and ensure the
README variants stay consistent with this note so users know to authenticate
before attempting to pull.

---

Nitpick comments:
In `@docker-compose.yml`:
- Around line 13-15: The docker-compose image is hard-coded to
ghcr.io/amintacccp/github-stars-manager-server:latest; change it to use a pinned
tag or digest and support an environment override (e.g., replace the literal
value with an env var like
${BACKEND_IMAGE:-ghcr.io/amintacccp/github-stars-manager-server:vX} or a digest)
and document adding BACKEND_IMAGE to .env so deployments are reproducible and
not using mutable :latest.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d4a9617-55cf-412e-b7db-2defb335e912

📥 Commits

Reviewing files that changed from the base of the PR and between 63f3fd3 and 9bd6183.

📒 Files selected for processing (5)
  • .github/workflows/docker-publish.yml
  • DOCKER.md
  • README.md
  • README_zh.md
  • docker-compose.yml

Comment thread .github/workflows/docker-publish.yml Outdated
Comment thread DOCKER.md
- DOCKER.md: add standalone backend docker run section with env var table
- README.md: add backend-only docker run examples
- README_zh.md: sync Chinese docs
- docker-compose.yml: use env var override for image tag instead of hard-coded :latest
- docker-publish.yml: add persist-credentials: false to checkout step
- DOCKER.md: add GHCR authentication note and BACKEND_IMAGE_TAG docs
- README.md/README_zh.md: add .env example with BACKEND_IMAGE_TAG

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
DOCKER.md (1)

10-19: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add GHCR auth prerequisite in Quick Start to prevent pull failures.

Line 10-19 should include a short prerequisite note: if the package is not public, users must run docker login ghcr.io before docker-compose up -d/docker pull; otherwise first-run onboarding can fail unexpectedly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@DOCKER.md` around lines 10 - 19, Add a short prerequisite sentence to the
"Quick Start (Using Pre-built Images from GHCR)" section indicating that if the
GHCR package is private, users must authenticate with `docker login ghcr.io`
before running `docker-compose up -d` or `docker pull`; place this note directly
above the existing docker-compose commands in the Quick Start block so users see
it before attempting to pull images.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@DOCKER.md`:
- Around line 10-19: Add a short prerequisite sentence to the "Quick Start
(Using Pre-built Images from GHCR)" section indicating that if the GHCR package
is private, users must authenticate with `docker login ghcr.io` before running
`docker-compose up -d` or `docker pull`; place this note directly above the
existing docker-compose commands in the Quick Start block so users see it before
attempting to pull images.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 39b23476-4345-491d-885f-9c5bfe1fb4c8

📥 Commits

Reviewing files that changed from the base of the PR and between 9bd6183 and 2baab47.

📒 Files selected for processing (3)
  • DOCKER.md
  • README.md
  • README_zh.md
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • README_zh.md

- Document both edit-in-place and override file approaches
- Add warning not to commit override file to git
- docker-publish.yml: pin all 5 actions to commit SHAs with version comments
- README.md: add GHCR auth note for private packages
- README_zh.md: add GHCR auth note for private packages

Addresses CodeRabbit review: supply-chain hardening and doc consistency
@AmintaCCCP AmintaCCCP merged commit bfe511e into main Jun 2, 2026
5 checks passed
@AmintaCCCP AmintaCCCP deleted the feat/docker-ghcr-publish branch June 3, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant