Optimized Docker Image with Multi-Stage Build
### Summary
This PR significantly reduces the Docker image size from **2.7GB to ~250MB** (over 90% reduction) by implementing a multi-stage build approach and removing unnecessary build dependencies from the final image.
### Changes Made
#### 1. **Multi-Stage Build Architecture**
- **Builder Stage**: Contains all build tools (Go, Node.js, Task, Goose, SQLC, golangci-lint)
- **Runtime Stage**: Uses `debian:trixie-slim` with only essential runtime dependencies
#### 2. **Dependency Optimization**
**Removed from final image:**
- Go compiler and toolchain
- Node.js and npm
- Task runner (except Goose for migrations)
- SQLC and golangci-lint
- Wget, unzip, git, and other build tools
**Retained in final image:**
- PostgreSQL clients (13-18) for backup operations
- Goose binary for database migrations
- Application binaries (`app` and `change-password`)
- Static files
#### 3. **Security Improvements**
- Created non-root user `pgbackweb` for application execution
- Removed build tools that could be exploited
- Minimal attack surface with only required packages
#### 4. **Migration Handling**
- Migration files are copied to the final image for runtime use
#### 5. **Build Process**
- All compilation happens in the builder stage
- Only compiled binaries and runtime dependencies are copied to final image
### Benefits
- **10x smaller image** (2.7GB → ~250MB)
- **Faster deployments** and reduced storage costs
- **Improved security** with fewer packages and non-root user
- **Same functionality** with optimized resource usage
合并状态:未合并 1 条评论