baker-cli 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2025 IQ GmbH
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,457 @@
1
+ Metadata-Version: 2.4
2
+ Name: baker-cli
3
+ Version: 0.1.3
4
+ Summary: Super simple Docker Build Dependency Pipeline
5
+ Author-email: Team IQ <service@get-iq.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/iq-company/baker-cli
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: PyYAML>=6.0
12
+ Requires-Dist: typer>=0.12.0
13
+ Requires-Dist: Jinja2>=3.1
14
+ Dynamic: license-file
15
+
16
+ # baker-cli
17
+
18
+ A small, pragmatic Python CLI that controls your Docker build cascades **uniformly locally and in CI**:
19
+
20
+ * **Targets & Bundles** are defined in **YAML**
21
+ * **Tags** are created by **checksum** (self / self+deps) *or* by **expressions** (ENV, files, Git-SHA, ...)
22
+ * **Build only when necessary**: Existence check locally or in registry
23
+ * Optionally generates a **`docker-bake.hcl`** and builds via **`docker buildx bake`**
24
+ * **Build-Args** are definable, get interpolated and **flow into the hash**
25
+ * Configuration values can be **overridden via CLI** (`--set key=value`)
26
+
27
+ ---
28
+
29
+ ## Contents
30
+
31
+ * [Quickstart](#quickstart)
32
+ * [Prerequisites](#prerequisites)
33
+ * [Repository Layout](#repository-layout)
34
+ * [Configuration (`build-settings.yml`)](#configuration-build-settingsyml)
35
+
36
+ * [Targets](#targets)
37
+ * [Bundles](#bundles)
38
+ * [Interpolation & Expressions](#interpolation--expressions)
39
+ * [Tag Expressions (Functions)](#tag-expressions-functions)
40
+ * [Build-Args & Hashing](#build-args--hashing)
41
+ * [CLI](#cli)
42
+
43
+ * [`plan`](#plan)
44
+ * [`gen-hcl`](#gen-hcl)
45
+ * [`build`](#build)
46
+ * [Global Overrides (`--set`)](#global-overrides---set)
47
+ * [Existence Check & Push Strategy](#existence-check--push-strategy)
48
+ * [GitHub Actions Example](#github-actions-example)
49
+ * [Tips & Best Practices](#tips--best-practices)
50
+ * [Troubleshooting](#troubleshooting)
51
+ * [Security Notes](#security-notes)
52
+
53
+ ---
54
+
55
+ ## Quickstart
56
+
57
+ ### 1) Installation (pip/pipx)
58
+
59
+ ```bash
60
+ # Mit pip
61
+ pip install baker-cli
62
+
63
+ # Oder mit pipx (empfohlen für globale CLIs)
64
+ pipx install baker-cli
65
+
66
+ # Projekt initialisieren (aktuelles Verzeichnis oder Zielordner)
67
+ baker init
68
+ # oder
69
+ baker init ./mein-projekt
70
+ ```
71
+
72
+ ### 2) Entwicklung (lokal, .venv)
73
+
74
+ ```bash
75
+ # Virtuelle Umgebung anlegen
76
+ python -m venv .venv
77
+ source .venv/bin/activate
78
+
79
+ # Projekt lokal installieren (editable)
80
+ pip install -U pip
81
+ pip install -e .
82
+
83
+ # Projekt initialisieren (falls noch nicht vorhanden)
84
+ baker init
85
+
86
+ # Optional: CI-Workflow generieren
87
+ baker ci --settings build-settings.yml
88
+
89
+ # Beispiel: Plan & Build
90
+ baker plan --settings build-settings.yml --check local --targets base
91
+ baker build --settings build-settings.yml --check remote --push --targets base
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Prerequisites
97
+
98
+ * **Python 3.11+**
99
+ * **Docker** (with `buildx` plugin)
100
+
101
+ ---
102
+
103
+ ## Repository Layout
104
+
105
+ ```
106
+ demo/ # Project name
107
+ ├── build-settings.yml # Build configuration
108
+ ├── sqlite/ # Sample Stage "sqlite"
109
+ │ └── Dockerfile # Related Dockerfile
110
+ └── ui/ # Sample Stage "ui"
111
+ └── Dockerfile # Related Dockerfile
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Configuration (`build-settings.yml`)
117
+
118
+ ### Targets
119
+
120
+ ```yaml
121
+ targets:
122
+ cascade-base:
123
+ dockerfile: Dockerfile.sqlite
124
+ context: .
125
+ tags:
126
+ - "cascade-base:{{ checksum_self }}"
127
+ build-args:
128
+ CONDUCTOR_VERSION: "3.16.0"
129
+ JAVA_VERSION: "17"
130
+
131
+ cascade-ui:
132
+ dockerfile: ui/Dockerfile
133
+ context: .
134
+ tags:
135
+ - "cascade-ui:{{ checksum_self }}"
136
+ depends_on:
137
+ - cascade-base
138
+ build-args:
139
+ BASE_IMAGE: "cascade-base:{{ checksum_self }}"
140
+ ```
141
+
142
+ ### Bundles
143
+
144
+ ```yaml
145
+ bundles:
146
+ all:
147
+ targets:
148
+ - cascade-base
149
+ - cascade-ui
150
+
151
+ sqlite:
152
+ targets:
153
+ - cascade-base
154
+ ```
155
+
156
+ ### Interpolation & Expressions
157
+
158
+ ```yaml
159
+ targets:
160
+ my-target:
161
+ tags:
162
+ - "my-app:{{ env.BUILD_VERSION }}"
163
+ - "my-app:{{ git.short_sha }}"
164
+ - "my-app:{{ file_hash('package.json') }}"
165
+ build-args:
166
+ VERSION: "{{ env.BUILD_VERSION }}"
167
+ COMMIT_SHA: "{{ git.full_sha }}"
168
+ ```
169
+
170
+ ### Tag Expressions (Functions)
171
+
172
+ * `{{ checksum_self }}` - Hash of Dockerfile + context
173
+ * `{{ checksum_deps }}` - Hash of dependencies
174
+ * `{{ env.VAR_NAME }}` - Environment variable
175
+ * `{{ git.short_sha }}` - Short Git commit hash
176
+ * `{{ git.full_sha }}` - Full Git commit hash
177
+ * `{{ file_hash('path/to/file') }}` - Hash of specific file
178
+ * `{{ timestamp }}` - Current timestamp
179
+
180
+ ### Build-Args & Hashing
181
+
182
+ Build-args are interpolated and included in the hash calculation:
183
+
184
+ ```yaml
185
+ targets:
186
+ my-target:
187
+ build-args:
188
+ VERSION: "{{ env.BUILD_VERSION }}"
189
+ FEATURE_FLAG: "{{ env.ENABLE_FEATURE }}"
190
+ # These args flow into the checksum calculation
191
+ ```
192
+
193
+ ---
194
+
195
+ ## CLI
196
+
197
+ ### `plan`
198
+
199
+ Show what would be built:
200
+
201
+ ```bash
202
+ # Show plan for specific targets
203
+ python baker.py plan --targets cascade-base
204
+
205
+ # Show plan with existence check
206
+ python baker.py plan --check local --targets cascade-base
207
+
208
+ # Show plan for bundles
209
+ python baker.py plan --targets all
210
+ ```
211
+
212
+ ### `gen-hcl`
213
+
214
+ Generate `docker-bake.hcl` file:
215
+
216
+ ```bash
217
+ # Generate HCL file
218
+ python baker.py gen-hcl --targets cascade-base
219
+
220
+ # Generate for all targets
221
+ python baker.py gen-hcl --targets all
222
+ ```
223
+
224
+ ### `build`
225
+
226
+ Build Docker images:
227
+
228
+ ```bash
229
+ # Build locally
230
+ python baker.py build --check local --push=off --targets cascade-base
231
+
232
+ # Build and push
233
+ python baker.py build --check registry --push=on --targets cascade-base
234
+
235
+ # Build with specific registry
236
+ python baker.py build --registry my-registry.com --push=on --targets cascade-base
237
+ ```
238
+
239
+ ### Global Overrides (`--set`)
240
+
241
+ Override configuration values:
242
+
243
+ ```bash
244
+ # Override build args
245
+ python baker.py build --set CONDUCTOR_VERSION=3.17.0 --targets cascade-base
246
+
247
+ # Override multiple values
248
+ python baker.py build --set CONDUCTOR_VERSION=3.17.0 --set JAVA_VERSION=21 --targets cascade-base
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Existence Check & Push Strategy
254
+
255
+ ### Local Check
256
+ ```bash
257
+ python baker.py build --check local --push=off --targets cascade-base
258
+ ```
259
+ * Checks if image exists locally
260
+ * Skips build if found
261
+
262
+ ### Registry Check
263
+ ```bash
264
+ python baker.py build --check registry --push=on --targets cascade-base
265
+ ```
266
+ * Checks if image exists in registry
267
+ * Skips build if found
268
+ * Pushes after successful build
269
+
270
+ ### No Check
271
+ ```bash
272
+ python baker.py build --check=off --push=on --targets cascade-base
273
+ ```
274
+ * Always builds
275
+ * Pushes after successful build
276
+
277
+ ---
278
+
279
+ ## GitHub Actions Example
280
+
281
+ ```yaml
282
+ name: Build and Push
283
+
284
+ on:
285
+ push:
286
+ branches: [main]
287
+ pull_request:
288
+ branches: [main]
289
+
290
+ jobs:
291
+ build:
292
+ runs-on: ubuntu-latest
293
+ steps:
294
+ - uses: actions/checkout@v3
295
+
296
+ - name: Set up Python
297
+ uses: actions/setup-python@v4
298
+ with:
299
+ python-version: '3.9'
300
+
301
+ - name: Install dependencies
302
+ run: pip install pyyaml
303
+
304
+ - name: Build images
305
+ run: |
306
+ python baker.py build \
307
+ --check registry \
308
+ --push=on \
309
+ --targets all \
310
+ --set BUILD_VERSION=${{ github.sha }}
311
+ ```
312
+
313
+ ---
314
+
315
+ ## Tips & Best Practices
316
+
317
+ ### 1. Use Checksums for Reproducible Builds
318
+ ```yaml
319
+ targets:
320
+ my-target:
321
+ tags:
322
+ - "my-app:{{ checksum_self }}"
323
+ ```
324
+
325
+ ### 2. Leverage Dependencies
326
+ ```yaml
327
+ targets:
328
+ base:
329
+ dockerfile: Dockerfile.base
330
+
331
+ app:
332
+ dockerfile: Dockerfile.app
333
+ depends_on:
334
+ - base
335
+ build-args:
336
+ BASE_IMAGE: "base:{{ checksum_self }}"
337
+ ```
338
+
339
+ ### 3. Use Environment Variables for Dynamic Values
340
+ ```yaml
341
+ targets:
342
+ my-target:
343
+ build-args:
344
+ VERSION: "{{ env.BUILD_VERSION }}"
345
+ COMMIT_SHA: "{{ git.short_sha }}"
346
+ ```
347
+
348
+ ### 4. Group Related Targets in Bundles
349
+ ```yaml
350
+ bundles:
351
+ production:
352
+ targets:
353
+ - base
354
+ - app
355
+ - worker
356
+
357
+ development:
358
+ targets:
359
+ - base
360
+ - dev-tools
361
+ ```
362
+
363
+ ---
364
+
365
+ ## Troubleshooting
366
+
367
+ ### Common Issues
368
+
369
+ #### 1. Docker Buildx Not Available
370
+ ```bash
371
+ # Enable buildx
372
+ docker buildx create --use
373
+ ```
374
+
375
+ #### 2. Registry Authentication
376
+ ```bash
377
+ # Login to registry
378
+ docker login my-registry.com
379
+ ```
380
+
381
+ #### 3. Build Context Issues
382
+ ```yaml
383
+ # Ensure context includes all necessary files
384
+ targets:
385
+ my-target:
386
+ context: . # Use project root
387
+ dockerfile: path/to/Dockerfile
388
+ ```
389
+
390
+ #### 4. Tag Collisions
391
+ ```yaml
392
+ # Use unique tags
393
+ targets:
394
+ my-target:
395
+ tags:
396
+ - "my-app:{{ checksum_self }}"
397
+ - "my-app:latest" # Only if appropriate
398
+ ```
399
+
400
+ ---
401
+
402
+ ## Security Notes
403
+
404
+ ### 1. Build-Args Security
405
+ * Build-args are visible in image history
406
+ * Don't pass secrets via build-args
407
+ * Use multi-stage builds for sensitive data
408
+
409
+ ### 2. Registry Security
410
+ * Use authenticated registries
411
+ * Scan images for vulnerabilities
412
+ * Use specific tags, avoid `latest`
413
+
414
+ ### 3. Context Security
415
+ * Use `.dockerignore` to exclude sensitive files
416
+ * Minimize build context size
417
+ * Review Dockerfile for security best practices
418
+
419
+ ---
420
+
421
+ ## Advanced Usage
422
+
423
+ ### Custom Tag Functions
424
+ ```yaml
425
+ targets:
426
+ my-target:
427
+ tags:
428
+ - "my-app:{{ env.BUILD_VERSION }}-{{ git.short_sha }}"
429
+ - "my-app:{{ file_hash('package.json') }}"
430
+ ```
431
+
432
+ ### Conditional Builds
433
+ ```yaml
434
+ targets:
435
+ my-target:
436
+ dockerfile: Dockerfile
437
+ tags:
438
+ - "my-app:{{ checksum_self }}"
439
+ # Only build if specific conditions are met
440
+ build-args:
441
+ BUILD_TYPE: "{{ env.BUILD_TYPE }}"
442
+ ```
443
+
444
+ ### Multi-Architecture Builds
445
+ ```yaml
446
+ targets:
447
+ my-target:
448
+ platforms:
449
+ - linux/amd64
450
+ - linux/arm64
451
+ tags:
452
+ - "my-app:{{ checksum_self }}"
453
+ ```
454
+
455
+ ---
456
+
457
+ This baker-cli provides a powerful yet simple way to manage Docker builds with consistency between local development and CI/CD pipelines.