mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-10 00:49:30 +00:00
Use a better structure
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# DevOps 工作流完整示例
|
||||
## DevOps 工作流完整示例
|
||||
|
||||
本章将演示一个基于 Docker, Kubernetes 和 Jenkins/GitLab CI 的完整 DevOps 工作流。
|
||||
|
||||
## 工作流概览
|
||||
### 工作流概览
|
||||
|
||||
1. **Code**: 开发人员提交代码到 GitLab。
|
||||
2. **Build**: GitLab CI 触发构建任务。
|
||||
@@ -12,25 +12,25 @@
|
||||
6. **Verify**: 人工或自动化验证。
|
||||
7. **Release (Production)**: 审批后自动部署到生产环境。
|
||||
|
||||
## 关键配置示例
|
||||
### 关键配置示例
|
||||
|
||||
### 1. Dockerfile (多阶段构建)
|
||||
#### 1. Dockerfile (多阶段构建)
|
||||
|
||||
```dockerfile
|
||||
# Build stage
|
||||
## Build stage
|
||||
FROM golang:1.18 AS builder
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN go build -o main .
|
||||
|
||||
# Final stage
|
||||
## Final stage
|
||||
FROM alpine:latest
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/main .
|
||||
CMD ["./main"]
|
||||
```
|
||||
|
||||
### 2. GitLab CI (.gitlab-ci.yml)
|
||||
#### 2. GitLab CI (.gitlab-ci.yml)
|
||||
|
||||
```yaml
|
||||
stages:
|
||||
@@ -67,7 +67,7 @@ deploy_staging:
|
||||
- develop
|
||||
```
|
||||
|
||||
## 最佳实践
|
||||
### 最佳实践
|
||||
|
||||
1. **不可变基础设施**: 一旦镜像构建完成,在各个环境(Dev, Staging, Prod)中都应该使用同一个镜像 tag (通常是 commit hash),而不是重新构建。
|
||||
2. **配置分离**: 使用 ConfigMap 和 Secret 管理环境特定的配置,不要打包进镜像。
|
||||
|
||||
Reference in New Issue
Block a user