Commit 0b97326
authored
refactor: Consolidate to single universal Dockerfile with BUILD_ENV argument (#569)
* refactor: Consolidate Dockerfiles into unified multi-target approach
This PR simplifies Docker configuration by replacing two separate
Dockerfiles with a single unified Dockerfile using build targets.
## Changes
### Files Added:
- `Dockerfile.unified` - New unified Dockerfile with 'development' and 'production' targets
### Files Modified:
- `docker-compose.yaml` - Updated to use unified Dockerfile with explicit targets
- `.dockerignore` - Keep ignoring Dockerfile.dev specifically
- `.github/workflows/docker-validate.yml` - Updated to lint unified Dockerfile
- `README.md` - Updated Docker documentation to reflect unified approach
### Files To Remove (in next commit):
- `Dockerfile` (old production-only)
- `Dockerfile.dev` (old development-only)
## Benefits
1. **Single Source of Truth**: One Dockerfile to maintain instead of two
2. **Shared Base Layers**: Common stages (base, deps, deps-dev) are reused
3. **Better Caching**: BuildKit can optimize shared layers between targets
4. **Simpler Maintenance**: Changes to Node/pnpm versions in one place
5. **Consistent Behavior**: Same base configuration for dev and prod
## How It Works
The unified Dockerfile has 5 stages:
- `base`: Common setup (Node.js, pnpm installation)
- `deps`: Production dependencies only
- `deps-dev`: All dependencies (including devDependencies)
- `development` (TARGET): Dev server with hot-reload
- `builder`: Builds Next.js static export
- `production` (TARGET): Nginx serving static export
Docker Compose automatically selects the correct target:
- `dev` service → `development` target
- `prod` service → `production` target
## Migration Path
Existing users can continue using docker-compose without changes.
Direct docker build commands need to specify `-f Dockerfile.unified` and `--target`.
Once validated, we'll remove the old Dockerfiles in a follow-up commit.
* refactor: Consolidate to single universal Dockerfile with BUILD_ENV argument
- Removed Dockerfile.unified and Dockerfile.dev
- Created single Dockerfile that switches between dev/prod via BUILD_ENV
- Simplified docker-compose.yaml to use BUILD_ENV instead of targets
- Updated health checks to use curl for both environments
- Updated .dockerignore to remove specific Dockerfile references
- Updated docker validation workflow to lint new Dockerfile
- Updated README documentation with simpler build commands
- Architecture: One Dockerfile, two modes, controlled by single argument
* fix: Resolve hadolint issues in Dockerfile
- Add --no-install-recommends to apt-get install (DL3015)
- Escape $uri variables in nginx config (SC2016)
- Use JSON notation for CMD (DL3025)
- Improves security and follows Docker best practices
* chore: Add hadolint config to ignore version pinning warnings
DL3008 and SC2016 are ignored because:
- Pinning apt package versions creates maintenance burden
- System packages are upgraded for security (apt-get upgrade)
- Echo statements for nginx config are properly escaped
- These checks are too strict for our use case1 parent 830c5b9 commit 0b97326
File tree
7 files changed
+138
-206
lines changed- .github/workflows
7 files changed
+138
-206
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | 53 | | |
56 | 54 | | |
57 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | 43 | | |
50 | 44 | | |
51 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
5 | 3 | | |
6 | | - | |
7 | 4 | | |
8 | 5 | | |
9 | | - | |
| 6 | + | |
10 | 7 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 8 | + | |
16 | 9 | | |
| 10 | + | |
17 | 11 | | |
18 | 12 | | |
19 | | - | |
| 13 | + | |
20 | 14 | | |
21 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
22 | 21 | | |
23 | | - | |
24 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
42 | 39 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 40 | + | |
57 | 41 | | |
58 | 42 | | |
59 | | - | |
60 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
61 | 82 | | |
| 83 | + | |
62 | 84 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 85 | + | |
79 | 86 | | |
80 | 87 | | |
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 93 | + | |
| 94 | + | |
153 | 95 | | |
154 | | - | |
155 | | - | |
156 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
157 | 103 | | |
158 | | - | |
159 | | - | |
| 104 | + | |
| 105 | + | |
This file was deleted.
0 commit comments