Skip to content

Commit 227316d

Browse files
committed
Remove explicit port binding in Azurite container
Switched from explicitly binding ports to relying on automatic assignment to avoid manual management of ports. Simplifies configuration and reduces potential conflicts.
1 parent 686a8c6 commit 227316d

File tree

2 files changed

+10
-78
lines changed

2 files changed

+10
-78
lines changed

packages/modules/azurite/src/azurite-container.test.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -113,34 +113,6 @@ describe("Azurite", () => {
113113
});
114114
// }
115115

116-
// customPorts {
117-
it("should be able to specify custom ports", async () => {
118-
const blobPort = 13000;
119-
const queuePort = 14000;
120-
const tablePort = 15000;
121-
const container = await new AzuriteContainer()
122-
.withBlobPort(blobPort)
123-
.withQueuePort(queuePort)
124-
.withTablePort(tablePort)
125-
.start();
126-
127-
expect(container.getBlobPort()).toBe(blobPort);
128-
expect(container.getQueuePort()).toBe(queuePort);
129-
expect(container.getTablePort()).toBe(tablePort);
130-
131-
const connectionString = container.getConnectionString();
132-
expect(connectionString).toContain("13000");
133-
expect(connectionString).toContain("14000");
134-
expect(connectionString).toContain("15000");
135-
136-
const serviceClient = BlobServiceClient.fromConnectionString(connectionString);
137-
const containerClient = serviceClient.getContainerClient("test");
138-
await containerClient.createIfNotExists();
139-
140-
await container.stop();
141-
});
142-
// }
143-
144116
// inMemoryPersistence {
145117
it("should be able to use in-memory persistence", async () => {
146118
const container = await new AzuriteContainer().withInMemoryPersistence().start();

packages/modules/azurite/src/azurite-container.ts

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export class AzuriteContainer extends GenericContainer {
2121
.withStartupTimeout(120_000);
2222
}
2323

24-
private blobPort: number = BLOB_PORT;
25-
private queuePort: number = QUEUE_PORT;
26-
private tablePort: number = TABLE_PORT;
2724
private accountName: string = DEFAULT_ACCOUNT_NAME;
2825
private accountKey: string = DEFAULT_ACCOUNT_KEY;
2926

@@ -49,33 +46,6 @@ export class AzuriteContainer extends GenericContainer {
4946
return this;
5047
}
5148

52-
/**
53-
* Sets the port to expose the Blob service on.
54-
* @param port The port to expose the Blob service on. Default is 10000.
55-
*/
56-
public withBlobPort(port: number): this {
57-
this.blobPort = port;
58-
return this;
59-
}
60-
61-
/**
62-
* Sets the port to expose the Queue service on.
63-
* @param port The port to expose the Queue service on. Default is 10001.
64-
*/
65-
public withQueuePort(port: number): this {
66-
this.queuePort = port;
67-
return this;
68-
}
69-
70-
/**
71-
* Sets the port to expose the Table service on.
72-
* @param port The port to expose the Table service on. Default is 10002.
73-
*/
74-
public withTablePort(port: number): this {
75-
this.tablePort = port;
76-
return this;
77-
}
78-
7949
/**
8050
* Disable persisting any data to disk and only store data in-memory. If the Azurite process is terminated, all data is lost.
8151
*/
@@ -119,11 +89,7 @@ export class AzuriteContainer extends GenericContainer {
11989
command.push("--skipApiVersionCheck");
12090
}
12191

122-
this.withCommand(command).withExposedPorts(
123-
{ container: BLOB_PORT, host: this.blobPort },
124-
{ container: QUEUE_PORT, host: this.queuePort },
125-
{ container: TABLE_PORT, host: this.tablePort }
126-
);
92+
this.withCommand(command).withExposedPorts(BLOB_PORT, QUEUE_PORT, TABLE_PORT);
12793

12894
if (this.accountName !== DEFAULT_ACCOUNT_NAME || this.accountKey !== DEFAULT_ACCOUNT_KEY) {
12995
this.withEnvironment({
@@ -137,9 +103,6 @@ export class AzuriteContainer extends GenericContainer {
137103
startedContainer,
138104
this.accountName,
139105
this.accountKey,
140-
this.blobPort,
141-
this.queuePort,
142-
this.tablePort
143106
);
144107
}
145108
}
@@ -149,9 +112,6 @@ export class StartedAzuriteContainer extends AbstractStartedContainer {
149112
startedTestContainer: StartedTestContainer,
150113
private readonly accountName: string,
151114
private readonly accountKey: string,
152-
private readonly blobPort: number,
153-
private readonly queuePort: number,
154-
private readonly tablePort: number
155115
) {
156116
super(startedTestContainer);
157117
}
@@ -164,28 +124,28 @@ export class StartedAzuriteContainer extends AbstractStartedContainer {
164124
return this.accountKey;
165125
}
166126

167-
public getBlobPort(): number {
168-
return this.blobPort;
127+
public getMappedBlobPort(): number {
128+
return this.getMappedPort(BLOB_PORT);
169129
}
170130

171-
public getQueuePort(): number {
172-
return this.queuePort;
131+
public getMappedQueuePort(): number {
132+
return this.getMappedPort(QUEUE_PORT);
173133
}
174134

175-
public getTablePort(): number {
176-
return this.tablePort;
135+
public getMappedTablePort(): number {
136+
return this.getMappedPort(TABLE_PORT);
177137
}
178138

179139
public getBlobEndpoint(): string {
180-
return this.getEndpoint(this.blobPort, this.accountName);
140+
return this.getEndpoint(this.getMappedBlobPort(), this.accountName);
181141
}
182142

183143
public getQueueEndpoint(): string {
184-
return this.getEndpoint(this.queuePort, this.accountName);
144+
return this.getEndpoint(this.getMappedQueuePort(), this.accountName);
185145
}
186146

187147
public getTableEndpoint(): string {
188-
return this.getEndpoint(this.tablePort, this.accountName);
148+
return this.getEndpoint(this.getMappedTablePort(), this.accountName);
189149
}
190150

191151
/**

0 commit comments

Comments
 (0)