Refactored scripts to focues on compatibility with the real product.
This commit is contained in:
68
README.md
68
README.md
@@ -2,13 +2,25 @@
|
||||
|
||||
This is a simple guide that will help you set up and run the Azure Storage Emulator on your local machine. The Azure Storage Emulator allows you to develop and test your applications that use Azure Storage services without needing an actual Azure subscription nor Internet connection.
|
||||
|
||||
## Prerequisites
|
||||
Review the [Documentation](#reference) for more details on how to use the emulator and its features. This document will cover a scenario where you want to run the emulator as close to the real Azure Storage service as possible, which means using triple HTTPS endpoints and OAuth simulation.
|
||||
|
||||
- Any system that supports fairly recent versions of Node.js (LTS vesions are recommended).
|
||||
- A Bash shell (a Linux or macOS system or Windows with WSL2 installed).
|
||||
- Docker Community Edition or Docker Desktop (for running the emulator in a containerized environment).
|
||||
- Apple `container` command (for running the containerized version of the emulator on macOS).
|
||||
- (Optional) Caddy HTTP server (for running the emulator with triple HTTPS endpoints, as it would be in Azure).
|
||||
|
||||
## Docker Installation
|
||||
|
||||
To run the Azure Storage Emulator in a Docker container, follow these steps:
|
||||
|
||||
1. Ensure that a container runtime is installed. This repository supports both Docker and Apple `container` command.
|
||||
2. Build the emulator image using the provided Dockerfile:
|
||||
|
||||
```bash
|
||||
./build.sh
|
||||
```
|
||||
|
||||
3. Run the emulator container:
|
||||
|
||||
```bash
|
||||
./run.sh
|
||||
```
|
||||
|
||||
## Native Installation
|
||||
|
||||
@@ -47,37 +59,43 @@ To install the Azure Storage Emulator natively on your machine, follow these ste
|
||||
rm -rf azurite
|
||||
```
|
||||
|
||||
## Running the Emulator
|
||||
6. Install the Caddy HTTP server.
|
||||
|
||||
There are two ways to run the Azure Storage Emulator: as a development server exposing the API on localhost using high ports (10000-10002) or as a fake Azure Storage service. The first one is easy, just run the `azurite` command in your terminal and that's it. The second one is a bit more complex, but it allows you to use the emulator as if it were the real Azure Storage service, and connect to it applications that do not support custom endpoints (Terraform azurerm state storage backend for example).
|
||||
7. Create an `accounts.env` file in the same directory as the `run-server.sh` script with the following content:
|
||||
|
||||
Run the `make-certs.sh` script to generate a self-signed CA certificate and a server certificate signed by that CA. The server certificate will be used by the emulator to serve HTTPS traffic, and the CA certificate can be imported into your system's trusted root certificates store to avoid security warnings when connecting to the emulator.
|
||||
```bash
|
||||
AZURITE_ACCOUNTS=accountname:accountkey
|
||||
```
|
||||
|
||||
The `make-certs.sh` script will create a storage directory for the emulator and place the generated PEM files there. The script will create a certificate for the `devstoreaccount1.blob.core.windows.net`. You can change that by adding you own storage account name as a single positional parameter. You will also need to map that name to `127.0.0.1` in your hosts file.
|
||||
Replace `accountname` with the desired account name. Use OpenSSL to generate an account key.
|
||||
|
||||
```bash
|
||||
./make-certs.sh myaccount
|
||||
```
|
||||
```bash
|
||||
openssl rand -base64 32
|
||||
```
|
||||
|
||||
```
|
||||
127.0.0.1 devstoreaccount1.blob.core.windows.net devstoreaccount1.queue.core.windows.net devstoreaccount1.table.core.windows.net
|
||||
```
|
||||
You can also generate a deterministic account key using any string as a seed:
|
||||
|
||||
Next, create an empty `accounts.env` file in the same directory. This file will be used by the emulator to retrieve the storage accounts names and access keys. You can use a single key or a pair of keys for each account. The format of the file is as follows:
|
||||
```bash
|
||||
echo -n "your-seed-string" | base64
|
||||
```
|
||||
|
||||
```shell
|
||||
AZURITE_ACCOUNTS="account1:key1,key2;account2:key1,key2;..."
|
||||
```
|
||||
8. Add the following line to your `/etc/hosts` file to map the custom domain names to localhost:
|
||||
|
||||
Use `add-account.sh` script to add at least one account to the `accounts.env` file. The script will generate random key for each added account. You can use `list-accounts.sh` script to list all accounts and their keys. You can also specify a password that will be used as the value for the key. The key is always Base64 encoded, and you password will also be Base64 encoded before being stored in the `accounts.env` file. The benefit of using a password is that the account key will be deterministic, so you can easily recreate the same account with the same key if needed.
|
||||
```
|
||||
127.0.0.1 <accountname>.blob.core.windows.net <accountname>.queue.core.windows.net <accountname>.table.core.windows.net
|
||||
```
|
||||
|
||||
Finally, run the emulator using the `run-emulator.sh` script.
|
||||
9. Run the server:
|
||||
|
||||
You can specify `--oauth` to enable simulation of Entra ID Authentication. It requires the endpoints to be directly accessed via HTTPS.
|
||||
```bash
|
||||
./run-server.sh
|
||||
```
|
||||
|
||||
The `run-emulator.sh` will detect if Caddy HTTP server is installed on your system, and if it is, it will use it to serve the emulator on triple HTTPS endpoints (Blob, Queue and Table services) as it would be in Azure.
|
||||
You can add the `--oauth` or `-o` flag to simulate OAuth authentication.
|
||||
|
||||
Use `--no-caddy` to disable Caddy even if it is installed. It is required to test Entra ID Authentication simulation.
|
||||
```bash
|
||||
./run-server.sh --oauth
|
||||
```
|
||||
|
||||
## Reference
|
||||
|
||||
|
||||
Reference in New Issue
Block a user