@git.zone/tsdocker 1.3.0 โ 1.4.1
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.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.dockerfile.d.ts +85 -0
- package/dist_ts/classes.dockerfile.js +366 -0
- package/dist_ts/classes.dockerregistry.d.ts +29 -0
- package/dist_ts/classes.dockerregistry.js +83 -0
- package/dist_ts/classes.registrystorage.d.ts +35 -0
- package/dist_ts/classes.registrystorage.js +76 -0
- package/dist_ts/classes.tsdockermanager.d.ts +53 -0
- package/dist_ts/classes.tsdockermanager.js +222 -0
- package/dist_ts/interfaces/index.d.ts +68 -0
- package/dist_ts/interfaces/index.js +2 -0
- package/dist_ts/tsdocker.cli.js +115 -8
- package/dist_ts/tsdocker.config.d.ts +3 -8
- package/dist_ts/tsdocker.config.js +10 -2
- package/dist_ts/tsdocker.plugins.d.ts +2 -1
- package/dist_ts/tsdocker.plugins.js +3 -2
- package/package.json +2 -2
- package/readme.hints.md +95 -26
- package/readme.md +323 -182
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.dockerfile.ts +462 -0
- package/ts/classes.dockerregistry.ts +91 -0
- package/ts/classes.registrystorage.ts +83 -0
- package/ts/classes.tsdockermanager.ts +254 -0
- package/ts/interfaces/index.ts +70 -0
- package/ts/tsdocker.cli.ts +123 -10
- package/ts/tsdocker.config.ts +14 -7
- package/ts/tsdocker.plugins.ts +2 -0
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @git.zone/tsdocker
|
|
2
2
|
|
|
3
|
-
> ๐ณ
|
|
3
|
+
> ๐ณ The ultimate Docker development toolkit for TypeScript projects โ build, test, and ship containerized applications with ease.
|
|
4
4
|
|
|
5
5
|
## Issue Reporting and Security
|
|
6
6
|
|
|
@@ -8,313 +8,454 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
|
|
|
8
8
|
|
|
9
9
|
## What is tsdocker?
|
|
10
10
|
|
|
11
|
-
**tsdocker**
|
|
11
|
+
**tsdocker** is a comprehensive Docker development and building tool that handles everything from testing npm packages in clean environments to building and pushing multi-architecture Docker images across multiple registries.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- ๐ **Reproducing CI behavior locally** โ No more "works on my machine" surprises
|
|
15
|
-
- ๐ง **Cross-platform development** โ Develop on macOS/Windows, test on Linux
|
|
16
|
-
- ๐ **Quick validation** โ Spin up isolated containers for testing without polluting your system
|
|
13
|
+
### ๐ฏ Key Capabilities
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
- ๐งช **Containerized Testing** โ Run your tests in pristine Docker environments
|
|
16
|
+
- ๐๏ธ **Smart Docker Builds** โ Automatically discover, sort, and build Dockerfiles by dependency
|
|
17
|
+
- ๐ **Multi-Registry Push** โ Ship to Docker Hub, GitLab, GitHub Container Registry, and more
|
|
18
|
+
- ๐ง **Multi-Architecture** โ Build for `amd64` and `arm64` with Docker Buildx
|
|
19
|
+
- โก **Zero Config Start** โ Works out of the box, scales with your needs
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
## Installation
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- Mounted docker.sock scenarios
|
|
23
|
+
```bash
|
|
24
|
+
# Global installation (recommended for CLI usage)
|
|
25
|
+
npm install -g @git.zone/tsdocker
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
# Or project-local installation
|
|
28
|
+
pnpm install --save-dev @git.zone/tsdocker
|
|
29
|
+
```
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
- Configurable test commands
|
|
31
|
-
- Environment variable injection via qenv
|
|
32
|
-
- Optional docker.sock mounting for nested container tests
|
|
31
|
+
## Quick Start
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
### ๐งช Run Tests in Docker
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
- Type-safe configuration
|
|
38
|
-
- Modern ESM with async/await patterns throughout
|
|
35
|
+
The simplest use case โ run your tests in a clean container:
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
```bash
|
|
38
|
+
tsdocker
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This pulls your configured base image, mounts your project, and executes your test command in isolation.
|
|
42
|
+
|
|
43
|
+
### ๐๏ธ Build Docker Images
|
|
44
|
+
|
|
45
|
+
Got `Dockerfile` files? Build them all with automatic dependency ordering:
|
|
41
46
|
|
|
42
47
|
```bash
|
|
43
|
-
|
|
44
|
-
# or for project-local installation
|
|
45
|
-
pnpm install --save-dev @git.zone/tsdocker
|
|
48
|
+
tsdocker build
|
|
46
49
|
```
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
tsdocker will:
|
|
52
|
+
1. ๐ Discover all `Dockerfile*` files in your project
|
|
53
|
+
2. ๐ Analyze `FROM` dependencies between them
|
|
54
|
+
3. ๐ Sort them topologically
|
|
55
|
+
4. ๐๏ธ Build each image in the correct order
|
|
56
|
+
|
|
57
|
+
### ๐ค Push to Registries
|
|
49
58
|
|
|
50
|
-
|
|
59
|
+
Ship your images to one or all configured registries:
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
```bash
|
|
62
|
+
# Push to all configured registries
|
|
63
|
+
tsdocker push
|
|
64
|
+
|
|
65
|
+
# Push to a specific registry
|
|
66
|
+
tsdocker push registry.gitlab.com
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## CLI Commands
|
|
70
|
+
|
|
71
|
+
| Command | Description |
|
|
72
|
+
|---------|-------------|
|
|
73
|
+
| `tsdocker` | Run tests in a fresh Docker container |
|
|
74
|
+
| `tsdocker build` | Build all Dockerfiles with dependency ordering |
|
|
75
|
+
| `tsdocker push [registry]` | Push images to configured registries |
|
|
76
|
+
| `tsdocker pull <registry>` | Pull images from a specific registry |
|
|
77
|
+
| `tsdocker test` | Run container test scripts (test_*.sh) |
|
|
78
|
+
| `tsdocker login` | Authenticate with configured registries |
|
|
79
|
+
| `tsdocker list` | Display discovered Dockerfiles and their dependencies |
|
|
80
|
+
| `tsdocker clean --all` | โ ๏ธ Aggressively clean Docker environment |
|
|
81
|
+
| `tsdocker vscode` | Launch containerized VS Code in browser |
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
Configure tsdocker in your `package.json` or `npmextra.json`:
|
|
53
86
|
|
|
54
87
|
```json
|
|
55
88
|
{
|
|
56
89
|
"@git.zone/tsdocker": {
|
|
57
90
|
"baseImage": "node:20",
|
|
58
91
|
"command": "npm test",
|
|
59
|
-
"dockerSock": false
|
|
92
|
+
"dockerSock": false,
|
|
93
|
+
"registries": ["registry.gitlab.com", "docker.io"],
|
|
94
|
+
"registryRepoMap": {
|
|
95
|
+
"registry.gitlab.com": "myorg/myproject"
|
|
96
|
+
},
|
|
97
|
+
"buildArgEnvMap": {
|
|
98
|
+
"NODE_VERSION": "NODE_VERSION"
|
|
99
|
+
},
|
|
100
|
+
"platforms": ["linux/amd64", "linux/arm64"],
|
|
101
|
+
"push": false,
|
|
102
|
+
"testDir": "./test"
|
|
60
103
|
}
|
|
61
104
|
}
|
|
62
105
|
```
|
|
63
106
|
|
|
64
|
-
###
|
|
107
|
+
### Configuration Options
|
|
65
108
|
|
|
66
|
-
|
|
67
|
-
tsdocker
|
|
68
|
-
```
|
|
109
|
+
#### Testing Options (Legacy)
|
|
69
110
|
|
|
70
|
-
|
|
111
|
+
| Option | Type | Description |
|
|
112
|
+
|--------|------|-------------|
|
|
113
|
+
| `baseImage` | `string` | Docker image for test environment (default: `hosttoday/ht-docker-node:npmdocker`) |
|
|
114
|
+
| `command` | `string` | Command to run inside container (default: `npmci npm test`) |
|
|
115
|
+
| `dockerSock` | `boolean` | Mount Docker socket for DinD scenarios (default: `false`) |
|
|
71
116
|
|
|
72
|
-
|
|
73
|
-
2. ๐๏ธ Build a test container with your specified base image
|
|
74
|
-
3. ๐ Mount your project directory
|
|
75
|
-
4. ๐ Execute your test command
|
|
76
|
-
5. ๐งน Clean up automatically
|
|
117
|
+
#### Build & Push Options
|
|
77
118
|
|
|
78
|
-
|
|
119
|
+
| Option | Type | Description |
|
|
120
|
+
|--------|------|-------------|
|
|
121
|
+
| `registries` | `string[]` | Registry URLs to push to |
|
|
122
|
+
| `registryRepoMap` | `object` | Map registries to different repository paths |
|
|
123
|
+
| `buildArgEnvMap` | `object` | Map Docker build ARGs to environment variables |
|
|
124
|
+
| `platforms` | `string[]` | Target architectures (default: `["linux/amd64"]`) |
|
|
125
|
+
| `push` | `boolean` | Auto-push after build (default: `false`) |
|
|
126
|
+
| `testDir` | `string` | Directory containing test scripts |
|
|
79
127
|
|
|
80
|
-
|
|
81
|
-
| ------------ | --------- | ---------------------------------------------------------------------- |
|
|
82
|
-
| `baseImage` | `string` | Docker image to use as the test environment base |
|
|
83
|
-
| `command` | `string` | CLI command to execute inside the container |
|
|
84
|
-
| `dockerSock` | `boolean` | Whether to mount `/var/run/docker.sock` for Docker-in-Docker scenarios |
|
|
128
|
+
## Registry Authentication
|
|
85
129
|
|
|
86
130
|
### Environment Variables
|
|
87
131
|
|
|
88
|
-
|
|
132
|
+
```bash
|
|
133
|
+
# Pipe-delimited format (supports DOCKER_REGISTRY_1 through DOCKER_REGISTRY_10)
|
|
134
|
+
export DOCKER_REGISTRY_1="registry.gitlab.com|username|password"
|
|
135
|
+
export DOCKER_REGISTRY_2="docker.io|username|password"
|
|
136
|
+
|
|
137
|
+
# Individual registry format
|
|
138
|
+
export DOCKER_REGISTRY_URL="registry.gitlab.com"
|
|
139
|
+
export DOCKER_REGISTRY_USER="username"
|
|
140
|
+
export DOCKER_REGISTRY_PASSWORD="password"
|
|
141
|
+
```
|
|
89
142
|
|
|
90
|
-
|
|
143
|
+
### Login Command
|
|
91
144
|
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
API_KEY: your-key-here
|
|
145
|
+
```bash
|
|
146
|
+
tsdocker login
|
|
95
147
|
```
|
|
96
148
|
|
|
97
|
-
|
|
149
|
+
Authenticates with all configured registries.
|
|
150
|
+
|
|
151
|
+
## Advanced Usage
|
|
98
152
|
|
|
99
|
-
###
|
|
153
|
+
### ๐ Multi-Architecture Builds
|
|
100
154
|
|
|
101
|
-
|
|
102
|
-
|
|
155
|
+
Build for multiple platforms using Docker Buildx:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"@git.zone/tsdocker": {
|
|
160
|
+
"platforms": ["linux/amd64", "linux/arm64"]
|
|
161
|
+
}
|
|
162
|
+
}
|
|
103
163
|
```
|
|
104
164
|
|
|
105
|
-
|
|
165
|
+
tsdocker automatically sets up a Buildx builder when multiple platforms are specified.
|
|
106
166
|
|
|
107
|
-
###
|
|
167
|
+
### ๐ฆ Dockerfile Naming Conventions
|
|
108
168
|
|
|
109
|
-
|
|
110
|
-
tsdocker clean --all
|
|
111
|
-
```
|
|
169
|
+
tsdocker discovers files matching `Dockerfile*`:
|
|
112
170
|
|
|
113
|
-
|
|
171
|
+
| File Name | Version Tag |
|
|
172
|
+
|-----------|-------------|
|
|
173
|
+
| `Dockerfile` | `latest` |
|
|
174
|
+
| `Dockerfile_v1.0.0` | `v1.0.0` |
|
|
175
|
+
| `Dockerfile_alpine` | `alpine` |
|
|
176
|
+
| `Dockerfile_##version##` | Uses `package.json` version |
|
|
114
177
|
|
|
115
|
-
|
|
116
|
-
- Removing all stopped containers
|
|
117
|
-
- Removing dangling images
|
|
118
|
-
- Removing all images
|
|
119
|
-
- Removing dangling volumes
|
|
178
|
+
### ๐ Dependency-Aware Builds
|
|
120
179
|
|
|
121
|
-
|
|
180
|
+
If you have multiple Dockerfiles that depend on each other:
|
|
122
181
|
|
|
123
|
-
|
|
182
|
+
```dockerfile
|
|
183
|
+
# Dockerfile_base
|
|
184
|
+
FROM node:20-alpine
|
|
185
|
+
RUN npm install -g typescript
|
|
124
186
|
|
|
125
|
-
|
|
126
|
-
|
|
187
|
+
# Dockerfile_app
|
|
188
|
+
FROM myproject:base
|
|
189
|
+
COPY . .
|
|
190
|
+
RUN npm run build
|
|
127
191
|
```
|
|
128
192
|
|
|
129
|
-
|
|
193
|
+
tsdocker automatically detects that `Dockerfile_app` depends on `Dockerfile_base` and builds them in the correct order.
|
|
194
|
+
|
|
195
|
+
### ๐งช Container Test Scripts
|
|
130
196
|
|
|
131
|
-
|
|
197
|
+
Create test scripts in your test directory:
|
|
132
198
|
|
|
133
199
|
```bash
|
|
134
|
-
|
|
200
|
+
# test/test_latest.sh
|
|
201
|
+
#!/bin/bash
|
|
202
|
+
node --version
|
|
203
|
+
npm --version
|
|
204
|
+
echo "Container tests passed!"
|
|
135
205
|
```
|
|
136
206
|
|
|
137
|
-
|
|
207
|
+
Run with:
|
|
138
208
|
|
|
139
|
-
|
|
209
|
+
```bash
|
|
210
|
+
tsdocker test
|
|
211
|
+
```
|
|
140
212
|
|
|
141
|
-
###
|
|
213
|
+
### ๐ง Build Args from Environment
|
|
142
214
|
|
|
143
|
-
|
|
215
|
+
Pass environment variables as Docker build arguments:
|
|
144
216
|
|
|
145
217
|
```json
|
|
146
218
|
{
|
|
147
219
|
"@git.zone/tsdocker": {
|
|
148
|
-
"
|
|
149
|
-
|
|
150
|
-
|
|
220
|
+
"buildArgEnvMap": {
|
|
221
|
+
"NPM_TOKEN": "NPM_TOKEN",
|
|
222
|
+
"NODE_VERSION": "NODE_VERSION"
|
|
223
|
+
}
|
|
151
224
|
}
|
|
152
225
|
}
|
|
153
226
|
```
|
|
154
227
|
|
|
155
|
-
|
|
228
|
+
```dockerfile
|
|
229
|
+
ARG NPM_TOKEN
|
|
230
|
+
ARG NODE_VERSION=20
|
|
231
|
+
FROM node:${NODE_VERSION}
|
|
232
|
+
RUN echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
|
|
233
|
+
```
|
|
156
234
|
|
|
157
|
-
###
|
|
235
|
+
### ๐ณ Docker-in-Docker Testing
|
|
158
236
|
|
|
159
|
-
|
|
237
|
+
Test Docker-related tools by mounting the Docker socket:
|
|
160
238
|
|
|
161
239
|
```json
|
|
162
240
|
{
|
|
163
241
|
"@git.zone/tsdocker": {
|
|
164
|
-
"baseImage": "
|
|
165
|
-
"command": "
|
|
242
|
+
"baseImage": "docker:latest",
|
|
243
|
+
"command": "docker version && docker ps",
|
|
244
|
+
"dockerSock": true
|
|
166
245
|
}
|
|
167
246
|
}
|
|
168
247
|
```
|
|
169
248
|
|
|
170
|
-
|
|
249
|
+
### ๐ Listing Dockerfiles
|
|
171
250
|
|
|
172
|
-
|
|
173
|
-
- `node:20-alpine` โ Lightweight Alpine-based images
|
|
174
|
-
- `node:lts` โ Long-term support Node.js version
|
|
251
|
+
Inspect your project's Dockerfiles and their relationships:
|
|
175
252
|
|
|
176
|
-
|
|
253
|
+
```bash
|
|
254
|
+
tsdocker list
|
|
255
|
+
```
|
|
177
256
|
|
|
178
|
-
|
|
257
|
+
Output:
|
|
258
|
+
```
|
|
259
|
+
Discovered Dockerfiles:
|
|
260
|
+
========================
|
|
261
|
+
|
|
262
|
+
1. Dockerfile_base
|
|
263
|
+
Tag: myproject:base
|
|
264
|
+
Base Image: node:20-alpine
|
|
265
|
+
Version: base
|
|
266
|
+
|
|
267
|
+
2. Dockerfile_app
|
|
268
|
+
Tag: myproject:app
|
|
269
|
+
Base Image: myproject:base
|
|
270
|
+
Version: app
|
|
271
|
+
Depends on: myproject:base
|
|
272
|
+
```
|
|
179
273
|
|
|
180
|
-
|
|
181
|
-
- Optimizes for CI execution patterns
|
|
274
|
+
### ๐บ๏ธ Registry Repo Mapping
|
|
182
275
|
|
|
183
|
-
|
|
276
|
+
Use different repository names for different registries:
|
|
277
|
+
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"@git.zone/tsdocker": {
|
|
281
|
+
"registries": ["registry.gitlab.com", "docker.io"],
|
|
282
|
+
"registryRepoMap": {
|
|
283
|
+
"registry.gitlab.com": "mygroup/myproject",
|
|
284
|
+
"docker.io": "myuser/myproject"
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
184
289
|
|
|
185
|
-
|
|
290
|
+
## Environment Variables
|
|
186
291
|
|
|
187
|
-
|
|
292
|
+
### qenv Integration
|
|
188
293
|
|
|
189
|
-
|
|
190
|
-
- Modified system configurations
|
|
191
|
-
- Cached dependencies
|
|
192
|
-
- Different Node.js versions
|
|
294
|
+
tsdocker automatically loads environment variables from `qenv.yml`:
|
|
193
295
|
|
|
194
|
-
|
|
296
|
+
```yaml
|
|
297
|
+
# qenv.yml
|
|
298
|
+
API_KEY: your-api-key
|
|
299
|
+
DATABASE_URL: postgres://localhost/test
|
|
300
|
+
```
|
|
195
301
|
|
|
196
|
-
|
|
302
|
+
These are injected into your test container automatically.
|
|
197
303
|
|
|
198
|
-
|
|
304
|
+
## Examples
|
|
199
305
|
|
|
200
|
-
|
|
201
|
-
โ
No dependency pollution between test runs
|
|
202
|
-
โ
Easy cross-platform testing
|
|
203
|
-
โ
Reproducible bug investigations
|
|
306
|
+
### Basic Test Configuration
|
|
204
307
|
|
|
205
|
-
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"@git.zone/tsdocker": {
|
|
311
|
+
"baseImage": "node:20",
|
|
312
|
+
"command": "npm test"
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
```
|
|
206
316
|
|
|
207
|
-
|
|
317
|
+
### Full Production Setup
|
|
208
318
|
|
|
209
|
-
```
|
|
210
|
-
|
|
319
|
+
```json
|
|
320
|
+
{
|
|
321
|
+
"@git.zone/tsdocker": {
|
|
322
|
+
"baseImage": "node:20-alpine",
|
|
323
|
+
"command": "pnpm test",
|
|
324
|
+
"registries": ["registry.gitlab.com", "ghcr.io", "docker.io"],
|
|
325
|
+
"registryRepoMap": {
|
|
326
|
+
"registry.gitlab.com": "myorg/myapp",
|
|
327
|
+
"ghcr.io": "myorg/myapp",
|
|
328
|
+
"docker.io": "myuser/myapp"
|
|
329
|
+
},
|
|
330
|
+
"buildArgEnvMap": {
|
|
331
|
+
"NPM_TOKEN": "NPM_TOKEN"
|
|
332
|
+
},
|
|
333
|
+
"platforms": ["linux/amd64", "linux/arm64"],
|
|
334
|
+
"testDir": "./docker-tests"
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
```
|
|
211
338
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
339
|
+
### CI/CD Integration
|
|
340
|
+
|
|
341
|
+
```yaml
|
|
342
|
+
# .gitlab-ci.yml
|
|
343
|
+
build:
|
|
344
|
+
stage: build
|
|
345
|
+
script:
|
|
346
|
+
- npm install -g @git.zone/tsdocker
|
|
347
|
+
- tsdocker build
|
|
348
|
+
- tsdocker push
|
|
349
|
+
|
|
350
|
+
# GitHub Actions
|
|
351
|
+
- name: Build and Push
|
|
352
|
+
run: |
|
|
353
|
+
npm install -g @git.zone/tsdocker
|
|
354
|
+
tsdocker login
|
|
355
|
+
tsdocker build
|
|
356
|
+
tsdocker push
|
|
357
|
+
env:
|
|
358
|
+
DOCKER_REGISTRY_1: "ghcr.io|${{ github.actor }}|${{ secrets.GITHUB_TOKEN }}"
|
|
220
359
|
```
|
|
221
360
|
|
|
222
361
|
## Requirements
|
|
223
362
|
|
|
224
|
-
- **Docker
|
|
225
|
-
- **Node.js
|
|
363
|
+
- **Docker** โ Docker Engine or Docker Desktop must be installed
|
|
364
|
+
- **Node.js** โ Version 18 or higher (ESM support required)
|
|
365
|
+
- **Docker Buildx** โ Required for multi-architecture builds (included in Docker Desktop)
|
|
226
366
|
|
|
227
|
-
##
|
|
367
|
+
## Why tsdocker?
|
|
228
368
|
|
|
229
|
-
|
|
369
|
+
### ๐ฏ The Problem
|
|
230
370
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
6. โถ๏ธ Runs your test command inside the container
|
|
237
|
-
7. ๐ Captures the exit code
|
|
238
|
-
8. ๐งน Cleans up containers and images
|
|
239
|
-
9. โ
Exits with the same code as your tests
|
|
371
|
+
Managing Docker workflows manually is tedious:
|
|
372
|
+
- Remembering build order for dependent images
|
|
373
|
+
- Pushing to multiple registries with different credentials
|
|
374
|
+
- Setting up Buildx for multi-arch builds
|
|
375
|
+
- Ensuring consistent test environments
|
|
240
376
|
|
|
241
|
-
|
|
377
|
+
### โจ The Solution
|
|
242
378
|
|
|
243
|
-
|
|
379
|
+
tsdocker automates the entire workflow:
|
|
380
|
+
- **One command** to build all images in dependency order
|
|
381
|
+
- **One command** to push to all registries
|
|
382
|
+
- **Automatic** Buildx setup for multi-platform builds
|
|
383
|
+
- **Consistent** containerized test environments
|
|
244
384
|
|
|
245
|
-
|
|
385
|
+
## TypeScript API
|
|
246
386
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
```
|
|
387
|
+
tsdocker exposes its types for programmatic use:
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
import type { ITsDockerConfig } from '@git.zone/tsdocker/dist_ts/interfaces/index.js';
|
|
391
|
+
import { TsDockerManager } from '@git.zone/tsdocker/dist_ts/classes.tsdockermanager.js';
|
|
250
392
|
|
|
251
|
-
|
|
393
|
+
const config: ITsDockerConfig = {
|
|
394
|
+
baseImage: 'node:20',
|
|
395
|
+
command: 'npm test',
|
|
396
|
+
dockerSock: false,
|
|
397
|
+
keyValueObject: {},
|
|
398
|
+
registries: ['docker.io'],
|
|
399
|
+
platforms: ['linux/amd64'],
|
|
400
|
+
};
|
|
252
401
|
|
|
253
|
-
|
|
402
|
+
const manager = new TsDockerManager(config);
|
|
403
|
+
await manager.prepare();
|
|
404
|
+
await manager.build();
|
|
405
|
+
await manager.push();
|
|
406
|
+
```
|
|
254
407
|
|
|
255
|
-
|
|
256
|
-
- Does your code have hardcoded paths?
|
|
257
|
-
- Are environment variables set correctly?
|
|
408
|
+
## Troubleshooting
|
|
258
409
|
|
|
259
|
-
###
|
|
410
|
+
### "docker not found"
|
|
260
411
|
|
|
261
|
-
|
|
412
|
+
Ensure Docker is installed and in your PATH:
|
|
262
413
|
|
|
263
414
|
```bash
|
|
264
|
-
|
|
265
|
-
# Then log out and back in
|
|
415
|
+
docker --version
|
|
266
416
|
```
|
|
267
417
|
|
|
268
|
-
|
|
418
|
+
### Multi-arch build fails
|
|
269
419
|
|
|
270
|
-
|
|
420
|
+
Make sure Docker Buildx is available:
|
|
271
421
|
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
"baseImage": "node:20",
|
|
276
|
-
"command": "npm test"
|
|
277
|
-
}
|
|
278
|
-
}
|
|
422
|
+
```bash
|
|
423
|
+
docker buildx version
|
|
424
|
+
docker buildx create --use
|
|
279
425
|
```
|
|
280
426
|
|
|
281
|
-
###
|
|
427
|
+
### Registry authentication fails
|
|
282
428
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
}
|
|
429
|
+
Check your environment variables are set correctly:
|
|
430
|
+
|
|
431
|
+
```bash
|
|
432
|
+
echo $DOCKER_REGISTRY_1
|
|
433
|
+
tsdocker login
|
|
290
434
|
```
|
|
291
435
|
|
|
292
|
-
###
|
|
436
|
+
### Circular dependency detected
|
|
293
437
|
|
|
294
|
-
|
|
295
|
-
{
|
|
296
|
-
"@git.zone/tsdocker": {
|
|
297
|
-
"baseImage": "docker:latest",
|
|
298
|
-
"command": "sh -c 'docker version && docker ps'",
|
|
299
|
-
"dockerSock": true
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
```
|
|
438
|
+
Review your Dockerfiles' `FROM` statements โ you have images depending on each other in a loop.
|
|
303
439
|
|
|
304
440
|
## Performance Tips
|
|
305
441
|
|
|
306
|
-
๐ **Use specific
|
|
307
|
-
|
|
308
|
-
๐ **
|
|
442
|
+
๐ **Use specific tags**: `node:20-alpine` is smaller and faster than `node:latest`
|
|
443
|
+
|
|
444
|
+
๐ **Leverage caching**: Docker layers are cached โ your builds get faster over time
|
|
445
|
+
|
|
446
|
+
๐ **Prune regularly**: `docker system prune` reclaims disk space
|
|
447
|
+
|
|
448
|
+
๐ **Use .dockerignore**: Exclude `node_modules`, `.git`, etc. from build context
|
|
309
449
|
|
|
310
|
-
## Migration from
|
|
450
|
+
## Migration from Legacy
|
|
311
451
|
|
|
312
|
-
|
|
452
|
+
Previously published as `npmdocker`, now `@git.zone/tsdocker`:
|
|
313
453
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
454
|
+
| Old | New |
|
|
455
|
+
|-----|-----|
|
|
456
|
+
| `npmdocker` command | `tsdocker` command |
|
|
457
|
+
| `"npmdocker"` config key | `"@git.zone/tsdocker"` config key |
|
|
458
|
+
| CommonJS | ESM with `.js` imports |
|
|
318
459
|
|
|
319
460
|
## License and Legal Information
|
|
320
461
|
|