Skip to content

Commit c97e294

Browse files
Separate testcontainers and modules into workspaces and publish as distinct packages into the testcontainers NPM organisation (#621)
1 parent 8674233 commit c97e294

File tree

325 files changed

+21319
-12268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

325 files changed

+21319
-12268
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/build/**

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ module.exports = {
55
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
66
rules: {
77
"prettier/prettier": "error",
8+
"@typescript-eslint/no-empty-function": "off",
89
},
910
};

.github/workflows/npm-publish.yml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
1-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3-
41
name: Node.js Package
52

63
on:
74
release:
85
types: [published]
96

107
jobs:
11-
commit-version:
8+
publish:
129
runs-on: ubuntu-22.04
1310
steps:
1411
- uses: actions/checkout@v3
1512
with:
1613
ref: main
14+
1715
- uses: actions/setup-node@v3
1816
with:
1917
node-version: 18
20-
- run: |
18+
19+
- name: Configure Git
20+
run: |
2121
git config user.name github-actions
2222
git config user.email [email protected]
23-
npm --no-git-tag-version version ${{ github.event.release.tag_name }}
23+
24+
- name: Update versions
25+
run: |
26+
npm version ${{ github.event.release.tag_name }} -ws
27+
for module in src/modules/*; do npm install testcontainers@${{ github.event.release.tag_name }} --save -w $module; done
2428
sed -i -E "s/(sonar.projectVersion)=.+/\1=${{ github.event.release.tag_name }}/" sonar-project.properties
25-
git add package.json package-lock.json sonar-project.properties
29+
30+
- name: Build packages
31+
run: |
32+
npm ci --no-optional
33+
npm run build -ws
34+
35+
- name: Git commit and push
36+
run: |
37+
git add \
38+
package-lock.json \
39+
src/**/package.json \
40+
src/testcontainers/src/version.ts \
41+
sonar-project.properties
2642
git commit -m "${{ github.event.release.tag_name }}"
2743
git push
2844
29-
publish-npm:
30-
needs: commit-version
31-
runs-on: ubuntu-22.04
32-
steps:
33-
- uses: actions/checkout@v3
34-
with:
35-
ref: main
36-
- uses: actions/setup-node@v3
37-
with:
38-
node-version: 18
39-
registry-url: https://registry.npmjs.org/
40-
- run: npm ci --no-optional
41-
- run: npm publish
45+
- name: Publish packages to NPM
46+
run: npm publish -ws
4247
env:
4348
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}

.github/workflows/test-main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ jobs:
126126
run: npm run test:ci -- generic-container.test.ts
127127

128128
rancher-desktop:
129+
if: false # https://github.com/rancher-sandbox/rancher-desktop/issues/5285
129130
runs-on: ${{ matrix.os-version }}
130131
strategy:
131132
fail-fast: false
@@ -220,9 +221,11 @@ jobs:
220221
node-version: ${{ matrix.node-version }}
221222
- name: Install dependencies
222223
run: npm ci --omit=optional
224+
- name: Build workspaces
225+
run: npm run build -ws
223226
- name: Remove dev dependencies
224227
run: npm prune --omit=dev
225228
- name: Run CommonJS module smoke test
226-
run: node smoke-test.js
229+
run: node src/testcontainers/smoke-test.js
227230
- name: Run ES module smoke test
228-
run: node smoke-test.mjs
231+
run: node src/testcontainers/smoke-test.mjs

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ jobs:
120120
run: npm run test:ci -- generic-container.test.ts
121121

122122
rancher-desktop:
123+
if: false # https://github.com/rancher-sandbox/rancher-desktop/issues/5285
123124
runs-on: ${{ matrix.os-version }}
124125
strategy:
125126
fail-fast: false
@@ -214,9 +215,11 @@ jobs:
214215
node-version: ${{ matrix.node-version }}
215216
- name: Install dependencies
216217
run: npm ci --omit=optional
218+
- name: Build workspaces
219+
run: npm run build -ws
217220
- name: Remove dev dependencies
218221
run: npm prune --omit=dev
219222
- name: Run CommonJS module smoke test
220-
run: node smoke-test.js
223+
run: node src/testcontainers/smoke-test.js
221224
- name: Run ES module smoke test
222-
run: node smoke-test.mjs
225+
run: node src/testcontainers/smoke-test.mjs

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
dist/
1+
build/
2+
*.tsbuildinfo
23
node_modules/
34
coverage/
45

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/build/**

docs/features/compose.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,29 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
4343

4444
### With a pull policy
4545

46+
Testcontainers will automatically pull an image if it doesn't exist. This is configurable:
47+
4648
```javascript
47-
const { DockerComposeEnvironment, AlwaysPullPolicy } = require("testcontainers");
49+
const { DockerComposeEnvironment, PullPolicy } = require("testcontainers");
50+
51+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
52+
.withPullPolicy(PullPolicy.alwaysPull())
53+
.up();
54+
```
55+
56+
Create a custom pull policy:
57+
58+
```typescript
59+
const { GenericContainer, ImagePullPolicy } = require("testcontainers");
60+
61+
class CustomPullPolicy implements ImagePullPolicy {
62+
public shouldPull(): boolean {
63+
return true;
64+
}
65+
}
4866

4967
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
50-
.withPullPolicy(new AlwaysPullPolicy())
68+
.withPullPolicy(new CustomPullPolicy())
5169
.up();
5270
```
5371

docs/features/containers.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,26 @@ const container = await new GenericContainer("alpine:3.10").start();
2121
Testcontainers will automatically pull an image if it doesn't exist. This is configurable:
2222

2323
```javascript
24-
const { GenericContainer, AlwaysPullPolicy } = require("testcontainers");
24+
const { GenericContainer, PullPolicy } = require("testcontainers");
2525

2626
const container = await new GenericContainer("alpine")
27-
.withPullPolicy(new AlwaysPullPolicy())
27+
.withPullPolicy(PullPolicy.alwaysPull())
28+
.start();
29+
```
30+
31+
Create a custom pull policy:
32+
33+
```typescript
34+
const { GenericContainer, ImagePullPolicy } = require("testcontainers");
35+
36+
class CustomPullPolicy implements ImagePullPolicy {
37+
public shouldPull(): boolean {
38+
return true;
39+
}
40+
}
41+
42+
const container = await new GenericContainer("alpine")
43+
.withPullPolicy(new CustomPullPolicy())
2844
.start();
2945
```
3046

@@ -395,7 +411,7 @@ import {
395411
} from "testcontainers";
396412

397413
class CustomContainer extends GenericContainer {
398-
protected override async beforeContainerStarted(): Promise<void> {
414+
protected override async beforeContainerCreated(): Promise<void> {
399415
// ...
400416
}
401417

docs/features/images.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,33 @@ const container = await GenericContainer
2424
.build("my-custom-image", { deleteOnExit: false });
2525
```
2626

27-
### With pull policy
27+
### With a pull policy
2828

2929
Testcontainers will automatically pull an image if it doesn't exist. This is configurable:
3030

3131
```javascript
32-
const { GenericContainer, AlwaysPullPolicy } = require("testcontainers");
32+
const { GenericContainer, PullPolicy } = require("testcontainers");
3333

3434
const container = await GenericContainer
3535
.fromDockerfile("/path/to/build-context")
36-
.withPullPolicy(new AlwaysPullPolicy())
36+
.withPullPolicy(PullPolicy.alwaysPull())
37+
.build();
38+
```
39+
40+
Create a custom pull policy:
41+
42+
```typescript
43+
const { GenericContainer, ImagePullPolicy } = require("testcontainers");
44+
45+
class CustomPullPolicy implements ImagePullPolicy {
46+
public shouldPull(): boolean {
47+
return true;
48+
}
49+
}
50+
51+
const container = await GenericContainer
52+
.fromDockerfile("/path/to/build-context")
53+
.withPullPolicy(new CustomPullPolicy())
3754
.build();
3855
```
3956

0 commit comments

Comments
 (0)