Remove blank lines after code block markers

This commit is contained in:
yeasy
2026-03-21 22:36:09 -07:00
parent 312f8fea42
commit 9ac19d79ee
132 changed files with 0 additions and 1517 deletions

View File

@@ -21,7 +21,6 @@
使用 Docker 多阶段构建可以有效减小镜像体积
```dockerfile
## Build stage
FROM golang:1.23 AS builder
@@ -36,7 +35,6 @@ WORKDIR /app
COPY --from=builder /app/main .
CMD ["./main"]
```
#### 2. GitLab CI 配置
GitLab CI`.gitlab-ci.yml`配置如下
@@ -76,7 +74,6 @@ deploy_staging:
only:
- develop
```
### 21.1.3 最佳实践
1. **不可变基础设施**一旦镜像构建完成在各个环境DevStagingProd中都应该使用同一个镜像 tag通常是 commit hash而不是重新构建

View File

@@ -30,7 +30,6 @@ jobs:
push: false
tags: local/test:ci
```
该示例会在 GitHub Actions 中构建当前仓库的 Docker 镜像不推送到 registry
## 21.2.2 最佳实践
@@ -47,7 +46,6 @@ jobs:
with:
args: go version
```
## 21.2.3 参考资料
* [Actions Docs](https://docs.github.com/en/actions)

View File

@@ -26,7 +26,6 @@ git init
git remote add origin git@github.com:username/drone-demo.git
```
这里以一个简单的 `Go` 程序为例该程序输出 `Hello World!`
编写 `app.go` 文件
@@ -40,7 +39,6 @@ func main() {
fmt.Printf("Hello World!\n")
}
```
编写 `.drone.yml` 文件
```yaml
@@ -65,7 +63,6 @@ trigger:
branch:
- master
```
现在目录结构如下
```bash
@@ -73,7 +70,6 @@ trigger:
├── .drone.yml
└── app.go
```
## 21.3.3 推送项目源代码到 GitHub
```bash
@@ -83,7 +79,6 @@ git commit -m "test drone ci"
git push origin master
```
## 21.3.4 查看项目构建过程及结果
打开我们部署好的 `Drone` 网站或者 Drone Cloud即可看到构建结果

View File

@@ -30,7 +30,6 @@ VS Code 的 [Dev Containers](https://code.visualstudio.com/docs/devcontainers/co
"postCreateCommand": "go version"
}
```
然后在 VS Code 命令面板选择
* `Dev Containers: Reopen in Container`
@@ -40,7 +39,6 @@ VS Code 会拉取镜像并启动容器,随后你就可以在容器内运行:
```bash
go test ./...
```
## 21.6.3 结合 Docker Compose可选
如果项目同时依赖数据库/缓存例如 Postgres/Redis可以使用 `dockerComposeFile`
@@ -58,5 +56,4 @@ go test ./...
"workspaceFolder": "/work"
}
```
注意`service` 需要对应 compose 里的服务名

View File

@@ -44,11 +44,9 @@ func main() {
}
}
```
**多阶段 Dockerfile**
```dockerfile
# Stage 1: 构建阶段
FROM golang:1.20-alpine AS builder
@@ -88,11 +86,9 @@ EXPOSE 8080
# 使用绝对路径作为 ENTRYPOINT
ENTRYPOINT ["/app"]
```
**构建和测试**
```bash
# 构建镜像
docker build -t go-app:latest .
@@ -113,7 +109,6 @@ docker exec go-demo ls -la /
# 镜像大小通常 < 10MB相比 golang:1.20-alpine 的 ~1GB
docker history go-app:latest
```
**go.mod go.sum 示例**
```text
@@ -125,7 +120,6 @@ require (
// 如果需要依赖
)
```
#### 带依赖的 Go 应用
**应用代码使用 Gin 框架**
@@ -156,7 +150,6 @@ func main() {
log.Fatal(router.Run(":8080"))
}
```
**优化的 Dockerfile**
```dockerfile
@@ -189,7 +182,6 @@ EXPOSE 8080
CMD ["./app"]
```
### 21.7.2 Rust 应用的最小化镜像构建
Rust 因其性能和安全性在系统级应用中备受青睐
@@ -226,7 +218,6 @@ async fn hello() -> HttpResponse {
}))
}
```
**Cargo.toml**
```toml
@@ -245,11 +236,9 @@ tokio = { version = "1.35", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
```
**多阶段构建 Dockerfile**
```dockerfile
# Stage 1: 编译
FROM rust:1.75-alpine AS builder
@@ -274,7 +263,6 @@ EXPOSE 8080
CMD ["/app"]
```
**构建和验证**
```bash
@@ -285,7 +273,6 @@ curl http://localhost:8080/health | jq .
# Rust 应用通常比 Go 更小5-20MB取决于依赖
docker images rust-app
```
### 21.7.3 数据库容器化最佳实践
#### PostgreSQL 生产部署
@@ -312,7 +299,6 @@ HEALTHCHECK --interval=10s --timeout=5s --start-period=40s --retries=3 \
EXPOSE 5432
```
**初始化脚本init-db.sql**
```sql
@@ -348,7 +334,6 @@ GRANT USAGE ON SCHEMA public TO appuser;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO appuser;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO appuser;
```
**健康检查脚本health-check.sh**
```bash
@@ -362,7 +347,6 @@ PGPASSWORD=$POSTGRES_PASSWORD pg_isready \
exit $?
```
**Docker Compose 配置**
```yaml
@@ -419,7 +403,6 @@ networks:
backend:
driver: bridge
```
**性能优化配置**
```yaml
@@ -472,7 +455,6 @@ services:
volumes:
postgres_data:
```
#### MySQL/MariaDB 部署
```dockerfile
@@ -489,7 +471,6 @@ EXPOSE 3306
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD mariadb-admin ping -h localhost || exit 1
```
**自定义 my.cnf**
```ini
@@ -514,7 +495,6 @@ server_id = 1
log_bin = mysql-bin
binlog_format = ROW
```
#### Redis 缓存部署
```dockerfile
@@ -531,11 +511,9 @@ EXPOSE 6379
HEALTHCHECK --interval=5s --timeout=3s --retries=5 \
CMD redis-cli ping || exit 1
```
**redis.conf 配置**
```text
# 绑定地址
bind 0.0.0.0
@@ -567,7 +545,6 @@ client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
```
### 21.7.4 微服务架构的 Docker Compose 编排
**三层微服务架构示例**
@@ -704,7 +681,6 @@ networks:
backend-network:
driver: bridge
```
**nginx.conf 配置**
```nginx
@@ -760,7 +736,6 @@ server {
}
}
```
### 21.7.5 使用 VS Code Dev Containers
Dev Containers 让整个开发环境容器化提升团队一致性
@@ -823,7 +798,6 @@ Dev Containers 让整个开发环境容器化,提升团队一致性。
"remoteUser": "vscode"
}
```
**.devcontainer/Dockerfile**
```dockerfile
@@ -843,11 +817,9 @@ ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /workspace
```
**Docker Compose 用于 Dev Containers**
```yaml
# .devcontainer/docker-compose.yml
version: '3.9'