-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add AzuriteContainer to Azure module #9661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eddumelendez
merged 13 commits into
testcontainers:main
from
nagyesta:feature/add-azurite-container
Jan 9, 2025
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9cca536
Add Azurite container to Azure module
nagyesta f7ac9a9
Add Azurite container to Azure module
nagyesta 41bd954
Add Azurite container to Azure module
nagyesta 2035435
Add Azurite container to Azure module
nagyesta 55c7212
Add Azurite container to Azure module
nagyesta 4c6ec20
Add Azurite container to Azure module
nagyesta eaaa094
Add Azurite container to Azure module
nagyesta 2c83a05
Add Azurite container to Azure module
nagyesta e197419
Add Azurite container to Azure module
nagyesta b971004
Add Azurite container to Azure module
nagyesta 0f11e4b
Add Azurite container to Azure module
nagyesta 4a522ba
Add Azurite container to Azure module
nagyesta 7541c38
Polish
eddumelendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
modules/azure/src/main/java/org/testcontainers/azure/AzuriteContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| package org.testcontainers.azure; | ||
|
|
||
| import org.testcontainers.containers.BindMode; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| /** | ||
| * Testcontainers implementation for Azurite Emulator. | ||
| * <p> | ||
| * Supported image: {@code mcr.microsoft.com/azure-storage/azurite} | ||
| * <p> | ||
| * Exposed ports: | ||
| * <ul> | ||
| * <li>10000 (blob port)</li> | ||
| * <li>10001 (queue port)</li> | ||
| * <li>10002 (table port)</li> | ||
| * </ul> | ||
| * <p> | ||
| * See command line options <a href="https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio%2Cblob-storage#command-line-options">here</a>. | ||
| */ | ||
| public class AzuriteContainer extends GenericContainer<AzuriteContainer> { | ||
|
|
||
| private static final String DEFAULT_HOST = "127.0.0.1"; | ||
|
|
||
| private static final String ALLOW_ALL_CONNECTIONS = "0.0.0.0"; | ||
|
|
||
| private static final int DEFAULT_BLOB_PORT = 10000; | ||
|
|
||
| private static final int DEFAULT_QUEUE_PORT = 10001; | ||
|
|
||
| private static final int DEFAULT_TABLE_PORT = 10002; | ||
|
|
||
| private static final String CONNECTION_STRING_FORMAT = | ||
| "DefaultEndpointsProtocol=%s;AccountName=%s;AccountKey=%s;BlobEndpoint=%s://%s:%d/%s;QueueEndpoint=%s://%s:%d/%s;TableEndpoint=%s://%s:%d/%s;"; | ||
|
|
||
| /** | ||
| * The account name of the default credentials. | ||
| */ | ||
| public static final String WELL_KNOWN_ACCOUNT_NAME = "devstoreaccount1"; | ||
|
|
||
| /** | ||
| * The account key of the default credentials. | ||
| */ | ||
| public static final String WELL_KNOWN_ACCOUNT_KEY = | ||
nagyesta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; | ||
|
|
||
| private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse( | ||
| "mcr.microsoft.com/azure-storage/azurite" | ||
| ); | ||
|
|
||
| private String host = DEFAULT_HOST; | ||
|
|
||
| private File cert = null; | ||
|
|
||
| private String certExtension = null; | ||
|
|
||
| private File key = null; | ||
|
|
||
| private String pwd = null; | ||
|
|
||
| /** | ||
| * @param dockerImageName specified docker image name to run | ||
| */ | ||
| public AzuriteContainer(final DockerImageName dockerImageName) { | ||
| super(dockerImageName); | ||
| dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
| } | ||
|
|
||
| /** | ||
| * Configure SSL with a custom certificate and password. | ||
| * | ||
| * @param pfxCert The PFX certificate file | ||
| * @param password The password securing the certificate | ||
| * @return this | ||
| */ | ||
| public AzuriteContainer withSsl(final File pfxCert, final String password) { | ||
| cert = pfxCert; | ||
| pwd = password; | ||
| certExtension = ".pfx"; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configure SSL with a custom certificate and private key. | ||
| * | ||
| * @param pemCert The PEM certificate file | ||
| * @param pemKey The PEM key file | ||
| * @return this | ||
| */ | ||
| public AzuriteContainer withSsl(final File pemCert, final File pemKey) { | ||
| cert = pemCert; | ||
| key = pemKey; | ||
| certExtension = ".pem"; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the hostname we want to use to connect to our emulator. (default: {@link #DEFAULT_HOST}) | ||
| * | ||
| * @param host The host name | ||
| * @return this | ||
| */ | ||
| public AzuriteContainer withHost(final String host) { | ||
| this.host = host; | ||
| return this; | ||
| } | ||
nagyesta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| protected void configure() { | ||
| withEnv("AZURITE_ACCOUNTS", WELL_KNOWN_ACCOUNT_NAME + ":" + WELL_KNOWN_ACCOUNT_KEY); | ||
nagyesta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| withCommand(getCommandLine()); | ||
eddumelendez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (cert != null) { | ||
| final String certAbsolutePath = cert.getAbsolutePath(); | ||
| logger().info("Using path for cert file: '{}'", certAbsolutePath); | ||
| withFileSystemBind(certAbsolutePath, "/cert" + certExtension, BindMode.READ_ONLY); | ||
nagyesta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (key != null) { | ||
| final String keyAbsolutePath = key.getAbsolutePath(); | ||
| logger().info("Using path for key file: '{}'", keyAbsolutePath); | ||
| withFileSystemBind(keyAbsolutePath, "/key.pem", BindMode.READ_ONLY); | ||
| } | ||
| } | ||
| withExposedPorts(DEFAULT_BLOB_PORT, DEFAULT_QUEUE_PORT, DEFAULT_TABLE_PORT); | ||
nagyesta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Returns the connection string for the default credentials. | ||
| * | ||
| * @return connection string | ||
| */ | ||
| public String getDefaultConnectionString() { | ||
| return getConnectionString(WELL_KNOWN_ACCOUNT_NAME, WELL_KNOWN_ACCOUNT_KEY); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the connection string for the account name and key specified. | ||
| * | ||
| * @param accountName The name of the account | ||
| * @param accountKey The account key | ||
| * @return connection string | ||
| */ | ||
| public String getConnectionString(final String accountName, final String accountKey) { | ||
eddumelendez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final String protocol = cert != null ? "https" : "http"; | ||
| return String.format( | ||
| CONNECTION_STRING_FORMAT, | ||
| protocol, | ||
| accountName, | ||
| accountKey, | ||
| protocol, | ||
| host, | ||
| getMappedPort(DEFAULT_BLOB_PORT), | ||
| accountName, | ||
| protocol, | ||
| host, | ||
| getMappedPort(DEFAULT_QUEUE_PORT), | ||
| accountName, | ||
| protocol, | ||
| host, | ||
nagyesta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| getMappedPort(DEFAULT_TABLE_PORT), | ||
| accountName | ||
| ); | ||
| } | ||
|
|
||
| String getCommandLine() { | ||
| final StringBuilder args = new StringBuilder("azurite"); | ||
| args.append(" --blobHost ").append(ALLOW_ALL_CONNECTIONS).append(" --blobPort ").append(DEFAULT_BLOB_PORT); | ||
| args.append(" --queueHost ").append(ALLOW_ALL_CONNECTIONS).append(" --queuePort ").append(DEFAULT_QUEUE_PORT); | ||
| args.append(" --tableHost ").append(ALLOW_ALL_CONNECTIONS).append(" --tablePort ").append(DEFAULT_TABLE_PORT); | ||
nagyesta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| args.append(" --location ").append("/data"); | ||
| if (cert != null) { | ||
| args.append(" --cert ").append("/cert").append(certExtension); | ||
| if (pwd != null) { | ||
| args.append(" --pwd ").append(pwd); | ||
| } else { | ||
| args.append(" --key ").append("/key.pem"); | ||
| } | ||
| } | ||
| final String cmd = args.toString(); | ||
| logger().debug("Using command line: '{}'", cmd); | ||
| return cmd; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.