Skip to content

Commit fcb5036

Browse files
Adds support for COPY TO/FROM Azure Blob Storage (#55)
Supports following Azure Blob uri forms: - `az://{container}/key` - `azure://{container}/key` - `https://{account}.blob.core.windows.net/{container}` **Configuration** The simplest way to configure object storage is by creating the standard [`~/.azure/config`](https://learn.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) file: ```bash $ cat ~/.azure/config [storage] account = devstoreaccount1 key = Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== ``` Alternatively, you can use the following environment variables when starting postgres to configure the Azure Blob Storage client: - `AZURE_STORAGE_ACCOUNT`: the storage account name of the Azure Blob - `AZURE_STORAGE_KEY`: the storage key of the Azure Blob - `AZURE_CONNECTION_STRING`: the connection string of the Azure Blob - `AZURE_STORAGE_SAS_TOKEN`: the storage SAS token for the Azure Blob - `AZURE_TENANT_ID`: the tenant id for client secret auth **(only via environment variables)** - `AZURE_CLIENT_ID`: the client id for client secret auth **(only via environment variables)** - `AZURE_CLIENT_SECRET`: the client secret for client secret auth **(only via environment variables)** - `AZURE_STORAGE_ENDPOINT`: the endpoint **(only via environment variables)** - `AZURE_ALLOW_HTTP`: allows http endpoints **(only via environment variables)** - `AZURE_CONFIG_FILE`: an alternative location for the config file **(only via environment variables)** **Bonus** Additionally, PR adds support to the following S3 uri forms: - `https://s3.amazonaws.com/{bucket}/key` - `https://{bucket}.s3.amazonaws.com/key` Closes #50
1 parent 2c1a62d commit fcb5036

File tree

17 files changed

+1362
-228
lines changed

17 files changed

+1362
-228
lines changed

.devcontainer/.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@ AWS_S3_TEST_BUCKET=testbucket
88
MINIO_ROOT_USER=minioadmin
99
MINIO_ROOT_PASSWORD=minioadmin
1010

11+
# Azure Blob tests
12+
AZURE_STORAGE_ACCOUNT=devstoreaccount1
13+
AZURE_STORAGE_KEY="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
14+
AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;"
15+
AZURE_STORAGE_ENDPOINT=http://localhost:10000/devstoreaccount1
16+
AZURE_ALLOW_HTTP=true
17+
AZURE_TEST_CONTAINER_NAME=testcontainer
18+
AZURE_TEST_READ_ONLY_SAS="se=2100-05-05&sp=r&sv=2022-11-02&sr=c&sig=YMPFnAHKe9y0o3hFegncbwQTXtAyvsJEgPB2Ne1b9CQ%3D"
19+
AZURE_TEST_READ_WRITE_SAS="se=2100-05-05&sp=rcw&sv=2022-11-02&sr=c&sig=TPz2jEz0t9L651t6rTCQr%2BOjmJHkM76tnCGdcyttnlA%3D"
20+
1121
# Others
1222
RUST_TEST_THREADS=1

.devcontainer/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ RUN apt-get update && apt-get -y install build-essential libreadline-dev zlib1g-
1212
curl lsb-release ca-certificates gnupg sudo git \
1313
nano net-tools awscli
1414

15+
# install azure-cli
16+
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/keyrings/microsoft.gpg > /dev/null
17+
RUN echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ `lsb_release -cs` main" | tee /etc/apt/sources.list.d/azure-cli.list
18+
RUN apt-get update && apt-get install -y azure-cli
19+
1520
# install Postgres
1621
RUN sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
1722
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

.devcontainer/docker-compose.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ services:
33
build:
44
context: .
55
dockerfile: Dockerfile
6-
command: sleep infinity
6+
entrypoint: "./entrypoint.sh"
77
network_mode: host
88
volumes:
99
- ..:/workspace
1010
- ${USERPROFILE}${HOME}/.ssh:/home/rust/.ssh:ro
1111
- ${USERPROFILE}${HOME}/.ssh/known_hosts:/home/rust/.ssh/known_hosts:rw
1212
- ${USERPROFILE}${HOME}/.gitconfig:/home/rust/.gitconfig:ro
13-
- ${USERPROFILE}${HOME}/.aws:/home/rust/.aws:ro
13+
- ${USERPROFILE}${HOME}/.aws:/home/rust/.aws:rw
14+
- ${USERPROFILE}${HOME}/.azure:/home/rust/.azure:rw
15+
- ./entrypoint.sh:/entrypoint.sh
1416
env_file:
1517
- .env
1618
cap_add:
1719
- SYS_PTRACE
1820
depends_on:
1921
- minio
22+
- azurite
2023

2124
minio:
2225
image: minio/minio
@@ -31,4 +34,16 @@ services:
3134
timeout: 2s
3235
retries: 3
3336
volumes:
34-
- ./minio-entrypoint.sh:/entrypoint.sh
37+
- ./minio-entrypoint.sh:/entrypoint.sh
38+
39+
azurite:
40+
image: mcr.microsoft.com/azure-storage/azurite
41+
env_file:
42+
- .env
43+
network_mode: host
44+
restart: unless-stopped
45+
healthcheck:
46+
test: ["CMD", "nc", "-z", "localhost", "10000"]
47+
interval: 6s
48+
timeout: 2s
49+
retries: 3

.devcontainer/entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
trap "echo 'Caught termination signal. Exiting...'; exit 0" SIGINT SIGTERM
4+
5+
# create azurite container
6+
az storage container create -n $AZURE_TEST_CONTAINER_NAME --connection-string $AZURE_STORAGE_CONNECTION_STRING
7+
8+
sleep infinity

.github/workflows/ci.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ jobs:
8585
postgresql-client-${{ env.PG_MAJOR }} \
8686
libpq-dev
8787
88+
- name: Install azure-cli
89+
run: |
90+
curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
91+
echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ `lsb_release -cs` main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
92+
sudo apt-get update && sudo apt-get install -y azure-cli
8893
8994
- name: Install and configure pgrx
9095
run: |
@@ -112,14 +117,28 @@ jobs:
112117
-p 9000:9000 \
113118
--entrypoint "./entrypoint.sh" \
114119
--volume ./.devcontainer/minio-entrypoint.sh:/entrypoint.sh \
115-
--name miniocontainer \
116120
minio/minio
117121
118122
while ! curl $AWS_ENDPOINT_URL; do
119123
echo "Waiting for $AWS_ENDPOINT_URL..."
120124
sleep 1
121125
done
122126
127+
- name: Start Azurite for Azure Blob Storage emulator tests
128+
run: |
129+
docker run -d \
130+
--env-file .devcontainer/.env \
131+
-p 10000:10000 \
132+
mcr.microsoft.com/azure-storage/azurite
133+
134+
while ! curl $AZURE_STORAGE_ENDPOINT; do
135+
echo "Waiting for $AZURE_STORAGE_ENDPOINT..."
136+
sleep 1
137+
done
138+
139+
# create container
140+
az storage container create -n $AZURE_TEST_CONTAINER_NAME --connection-string $AZURE_STORAGE_CONNECTION_STRING
141+
123142
- name: Run tests
124143
run: |
125144
# Run tests with coverage tool

0 commit comments

Comments
 (0)