@git.zone/tsdocker 1.4.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/package.json +1 -1
- package/readme.md +326 -177
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@git.zone/tsdocker',
|
|
6
|
-
version: '1.4.
|
|
6
|
+
version: '1.4.1',
|
|
7
7
|
description: 'develop npm modules cross platform with docker'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxvQkFBb0I7SUFDMUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLGdEQUFnRDtDQUM5RCxDQUFBIn0=
|
package/package.json
CHANGED
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,305 +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
|
|
49
56
|
|
|
50
|
-
###
|
|
57
|
+
### ๐ค Push to Registries
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
Ship your images to one or all configured registries:
|
|
60
|
+
|
|
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.
|
|
98
150
|
|
|
99
|
-
|
|
151
|
+
## Advanced Usage
|
|
100
152
|
|
|
101
|
-
|
|
102
|
-
|
|
153
|
+
### ๐ Multi-Architecture Builds
|
|
154
|
+
|
|
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
|
-
|
|
169
|
+
tsdocker discovers files matching `Dockerfile*`:
|
|
170
|
+
|
|
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 |
|
|
177
|
+
|
|
178
|
+
### ๐ Dependency-Aware Builds
|
|
179
|
+
|
|
180
|
+
If you have multiple Dockerfiles that depend on each other:
|
|
181
|
+
|
|
182
|
+
```dockerfile
|
|
183
|
+
# Dockerfile_base
|
|
184
|
+
FROM node:20-alpine
|
|
185
|
+
RUN npm install -g typescript
|
|
186
|
+
|
|
187
|
+
# Dockerfile_app
|
|
188
|
+
FROM myproject:base
|
|
189
|
+
COPY . .
|
|
190
|
+
RUN npm run build
|
|
111
191
|
```
|
|
112
192
|
|
|
113
|
-
|
|
193
|
+
tsdocker automatically detects that `Dockerfile_app` depends on `Dockerfile_base` and builds them in the correct order.
|
|
194
|
+
|
|
195
|
+
### ๐งช Container Test Scripts
|
|
114
196
|
|
|
115
|
-
|
|
116
|
-
- Removing all stopped containers
|
|
117
|
-
- Removing dangling images
|
|
118
|
-
- Removing all images
|
|
119
|
-
- Removing dangling volumes
|
|
197
|
+
Create test scripts in your test directory:
|
|
120
198
|
|
|
121
|
-
|
|
199
|
+
```bash
|
|
200
|
+
# test/test_latest.sh
|
|
201
|
+
#!/bin/bash
|
|
202
|
+
node --version
|
|
203
|
+
npm --version
|
|
204
|
+
echo "Container tests passed!"
|
|
205
|
+
```
|
|
122
206
|
|
|
123
|
-
|
|
207
|
+
Run with:
|
|
124
208
|
|
|
125
209
|
```bash
|
|
126
|
-
tsdocker
|
|
210
|
+
tsdocker test
|
|
127
211
|
```
|
|
128
212
|
|
|
129
|
-
|
|
213
|
+
### ๐ง Build Args from Environment
|
|
130
214
|
|
|
131
|
-
|
|
215
|
+
Pass environment variables as Docker build arguments:
|
|
132
216
|
|
|
133
|
-
|
|
217
|
+
```json
|
|
218
|
+
{
|
|
219
|
+
"@git.zone/tsdocker": {
|
|
220
|
+
"buildArgEnvMap": {
|
|
221
|
+
"NPM_TOKEN": "NPM_TOKEN",
|
|
222
|
+
"NODE_VERSION": "NODE_VERSION"
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
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
|
+
```
|
|
134
234
|
|
|
135
|
-
|
|
235
|
+
### ๐ณ Docker-in-Docker Testing
|
|
236
|
+
|
|
237
|
+
Test Docker-related tools by mounting the Docker socket:
|
|
136
238
|
|
|
137
239
|
```json
|
|
138
240
|
{
|
|
139
241
|
"@git.zone/tsdocker": {
|
|
140
242
|
"baseImage": "docker:latest",
|
|
141
|
-
"command": "docker
|
|
243
|
+
"command": "docker version && docker ps",
|
|
142
244
|
"dockerSock": true
|
|
143
245
|
}
|
|
144
246
|
}
|
|
145
247
|
```
|
|
146
248
|
|
|
147
|
-
|
|
249
|
+
### ๐ Listing Dockerfiles
|
|
250
|
+
|
|
251
|
+
Inspect your project's Dockerfiles and their relationships:
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
tsdocker list
|
|
255
|
+
```
|
|
256
|
+
|
|
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
|
+
```
|
|
148
273
|
|
|
149
|
-
###
|
|
274
|
+
### ๐บ๏ธ Registry Repo Mapping
|
|
150
275
|
|
|
151
|
-
|
|
276
|
+
Use different repository names for different registries:
|
|
152
277
|
|
|
153
278
|
```json
|
|
154
279
|
{
|
|
155
280
|
"@git.zone/tsdocker": {
|
|
156
|
-
"
|
|
157
|
-
"
|
|
281
|
+
"registries": ["registry.gitlab.com", "docker.io"],
|
|
282
|
+
"registryRepoMap": {
|
|
283
|
+
"registry.gitlab.com": "mygroup/myproject",
|
|
284
|
+
"docker.io": "myuser/myproject"
|
|
285
|
+
}
|
|
158
286
|
}
|
|
159
287
|
}
|
|
160
288
|
```
|
|
161
289
|
|
|
162
|
-
|
|
290
|
+
## Environment Variables
|
|
163
291
|
|
|
164
|
-
|
|
165
|
-
- `node:20-alpine` โ Lightweight Alpine-based images
|
|
166
|
-
- `node:lts` โ Long-term support Node.js version
|
|
292
|
+
### qenv Integration
|
|
167
293
|
|
|
168
|
-
|
|
294
|
+
tsdocker automatically loads environment variables from `qenv.yml`:
|
|
169
295
|
|
|
170
|
-
|
|
296
|
+
```yaml
|
|
297
|
+
# qenv.yml
|
|
298
|
+
API_KEY: your-api-key
|
|
299
|
+
DATABASE_URL: postgres://localhost/test
|
|
300
|
+
```
|
|
171
301
|
|
|
172
|
-
|
|
173
|
-
- Optimizes for CI execution patterns
|
|
302
|
+
These are injected into your test container automatically.
|
|
174
303
|
|
|
175
|
-
##
|
|
304
|
+
## Examples
|
|
305
|
+
|
|
306
|
+
### Basic Test Configuration
|
|
307
|
+
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"@git.zone/tsdocker": {
|
|
311
|
+
"baseImage": "node:20",
|
|
312
|
+
"command": "npm test"
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Full Production Setup
|
|
176
318
|
|
|
177
|
-
|
|
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
|
+
```
|
|
178
338
|
|
|
179
|
-
|
|
339
|
+
### CI/CD Integration
|
|
180
340
|
|
|
181
|
-
|
|
182
|
-
-
|
|
183
|
-
|
|
184
|
-
|
|
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 }}"
|
|
359
|
+
```
|
|
185
360
|
|
|
186
|
-
|
|
361
|
+
## Requirements
|
|
362
|
+
|
|
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)
|
|
366
|
+
|
|
367
|
+
## Why tsdocker?
|
|
187
368
|
|
|
188
|
-
### The
|
|
369
|
+
### ๐ฏ The Problem
|
|
189
370
|
|
|
190
|
-
|
|
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
|
|
191
376
|
|
|
192
|
-
|
|
193
|
-
โ
No dependency pollution between test runs
|
|
194
|
-
โ
Easy cross-platform testing
|
|
195
|
-
โ
Reproducible bug investigations
|
|
377
|
+
### โจ The Solution
|
|
196
378
|
|
|
197
|
-
|
|
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
|
|
198
384
|
|
|
199
|
-
|
|
385
|
+
## TypeScript API
|
|
386
|
+
|
|
387
|
+
tsdocker exposes its types for programmatic use:
|
|
200
388
|
|
|
201
389
|
```typescript
|
|
202
|
-
import type {
|
|
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';
|
|
203
392
|
|
|
204
|
-
const config:
|
|
393
|
+
const config: ITsDockerConfig = {
|
|
205
394
|
baseImage: 'node:20',
|
|
206
395
|
command: 'npm test',
|
|
207
396
|
dockerSock: false,
|
|
208
|
-
keyValueObject: {
|
|
209
|
-
|
|
210
|
-
|
|
397
|
+
keyValueObject: {},
|
|
398
|
+
registries: ['docker.io'],
|
|
399
|
+
platforms: ['linux/amd64'],
|
|
211
400
|
};
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
## Requirements
|
|
215
401
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
Under the hood, tsdocker:
|
|
222
|
-
|
|
223
|
-
1. ๐ Reads your `npmextra.json` configuration
|
|
224
|
-
2. ๐ Optionally loads environment variables from `qenv.yml`
|
|
225
|
-
3. ๐ณ Generates a temporary Dockerfile
|
|
226
|
-
4. ๐๏ธ Builds a Docker image with your base image
|
|
227
|
-
5. ๐ฆ Mounts your project directory (unless in CI)
|
|
228
|
-
6. โถ๏ธ Runs your test command inside the container
|
|
229
|
-
7. ๐ Captures the exit code
|
|
230
|
-
8. ๐งน Cleans up containers and images
|
|
231
|
-
9. โ
Exits with the same code as your tests
|
|
402
|
+
const manager = new TsDockerManager(config);
|
|
403
|
+
await manager.prepare();
|
|
404
|
+
await manager.build();
|
|
405
|
+
await manager.push();
|
|
406
|
+
```
|
|
232
407
|
|
|
233
408
|
## Troubleshooting
|
|
234
409
|
|
|
235
|
-
### "docker not found
|
|
410
|
+
### "docker not found"
|
|
236
411
|
|
|
237
|
-
|
|
412
|
+
Ensure Docker is installed and in your PATH:
|
|
238
413
|
|
|
239
414
|
```bash
|
|
240
415
|
docker --version
|
|
241
416
|
```
|
|
242
417
|
|
|
243
|
-
###
|
|
244
|
-
|
|
245
|
-
This often indicates environment-specific issues. Check:
|
|
418
|
+
### Multi-arch build fails
|
|
246
419
|
|
|
247
|
-
|
|
248
|
-
- Does your code have hardcoded paths?
|
|
249
|
-
- Are environment variables set correctly?
|
|
250
|
-
|
|
251
|
-
### Permission errors with docker.sock
|
|
252
|
-
|
|
253
|
-
If using `dockerSock: true`, ensure your user has permissions to access `/var/run/docker.sock`:
|
|
420
|
+
Make sure Docker Buildx is available:
|
|
254
421
|
|
|
255
422
|
```bash
|
|
256
|
-
|
|
257
|
-
|
|
423
|
+
docker buildx version
|
|
424
|
+
docker buildx create --use
|
|
258
425
|
```
|
|
259
426
|
|
|
260
|
-
|
|
427
|
+
### Registry authentication fails
|
|
261
428
|
|
|
262
|
-
|
|
429
|
+
Check your environment variables are set correctly:
|
|
263
430
|
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
"baseImage": "node:20",
|
|
268
|
-
"command": "npm test"
|
|
269
|
-
}
|
|
270
|
-
}
|
|
431
|
+
```bash
|
|
432
|
+
echo $DOCKER_REGISTRY_1
|
|
433
|
+
tsdocker login
|
|
271
434
|
```
|
|
272
435
|
|
|
273
|
-
###
|
|
436
|
+
### Circular dependency detected
|
|
274
437
|
|
|
275
|
-
|
|
276
|
-
{
|
|
277
|
-
"@git.zone/tsdocker": {
|
|
278
|
-
"baseImage": "node:20",
|
|
279
|
-
"command": "corepack enable && pnpm install && pnpm test"
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
```
|
|
438
|
+
Review your Dockerfiles' `FROM` statements โ you have images depending on each other in a loop.
|
|
283
439
|
|
|
284
|
-
|
|
440
|
+
## Performance Tips
|
|
285
441
|
|
|
286
|
-
|
|
287
|
-
{
|
|
288
|
-
"@git.zone/tsdocker": {
|
|
289
|
-
"baseImage": "docker:latest",
|
|
290
|
-
"command": "sh -c 'docker version && docker ps'",
|
|
291
|
-
"dockerSock": true
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
```
|
|
442
|
+
๐ **Use specific tags**: `node:20-alpine` is smaller and faster than `node:latest`
|
|
295
443
|
|
|
296
|
-
|
|
444
|
+
๐ **Leverage caching**: Docker layers are cached โ your builds get faster over time
|
|
445
|
+
|
|
446
|
+
๐ **Prune regularly**: `docker system prune` reclaims disk space
|
|
297
447
|
|
|
298
|
-
๐ **Use
|
|
299
|
-
๐ **Layer caching**: Docker caches image layers โ your base image only downloads once
|
|
300
|
-
๐ **Prune regularly**: Run `docker system prune` periodically to reclaim disk space
|
|
448
|
+
๐ **Use .dockerignore**: Exclude `node_modules`, `.git`, etc. from build context
|
|
301
449
|
|
|
302
|
-
## Migration from
|
|
450
|
+
## Migration from Legacy
|
|
303
451
|
|
|
304
|
-
|
|
452
|
+
Previously published as `npmdocker`, now `@git.zone/tsdocker`:
|
|
305
453
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
454
|
+
| Old | New |
|
|
455
|
+
|-----|-----|
|
|
456
|
+
| `npmdocker` command | `tsdocker` command |
|
|
457
|
+
| `"npmdocker"` config key | `"@git.zone/tsdocker"` config key |
|
|
458
|
+
| CommonJS | ESM with `.js` imports |
|
|
310
459
|
|
|
311
460
|
## License and Legal Information
|
|
312
461
|
|