Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
code-explore-lab
cloud-drive
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
dev
Breadcrumbs
cloud-drive
/
Dockerfile
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
48 lines (37 loc) · 1.92 KB
dev
Breadcrumbs
cloud-drive
/
Dockerfile
Copy path
Top
File metadata and controls
Code
Blame
48 lines (37 loc) · 1.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 通用构建文件:用 SERVICE_DIR 指定要构建的服务目录。
# 例:docker build --build-arg SERVICE_DIR=./service/user/api -t cloud-drive/user-api .
#
# 说明:这里刻意不写 `# syntax=docker/dockerfile:1`。
# 那行会让 BuildKit 去 Docker Hub 拉一份前端镜像,在受限网络下会直接失败
# (典型报错:frontend grpc server closed unexpectedly)。
# 本文件只用到内置前端已支持的特性(多阶段构建 + 缓存挂载)。
FROM golang:1.27-alpine AS builder
WORKDIR /src
# 构建阶段可指定 module proxy。默认用国内镜像,proxy.golang.org 在部分网络下不可达。
ARG GOPROXY=https://goproxy.cn,direct
ENV GOPROXY=${GOPROXY}
# 先只拷贝依赖清单,命中构建缓存。
#
# 两个 cache mount 是构建速度的关键:
# - /go/pkg/mod 下载过的模块,跨构建复用(go.mod 不变时不用重新下载)
# - /root/.cache/go-build Go 编译缓存,未改动包的 .a 文件直接复用
# 没有它们时每次构建都在全新容器里从零编译全部依赖,7 个服务并行要 20 分钟以上;
# 有了之后只有首次(缓存为空)是冷的,后续重建基本是秒级。
# cache mount 的内容不写进镜像层,所以下面 go build 的那一步也要挂同样的目录。
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
COPY . .
ARG SERVICE_DIR=./service/user/api
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/app ${SERVICE_DIR}
FROM alpine:3.20
# tzdata:MySQL DSN 里的 loc=Asia/Shanghai 需要时区数据,否则连接会报 unknown time zone。
RUN apk add --no-cache ca-certificates tzdata \
&& addgroup -g 10001 app \
&& adduser -D -u 10001 -G app app
WORKDIR /app
COPY --from=builder /out/app /app/app
USER 10001:10001
ENTRYPOINT ["/app/app"]
You can’t perform that action at this time.