148 lines
4.9 KiB
YAML
148 lines
4.9 KiB
YAML
name: Azure Storage Tests
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
paths:
|
|
- 'tests/integration/withServerInstance/storage.tests.js'
|
|
- 'Common/sources/storage/**'
|
|
- 'DocService/sources/routes/static.js'
|
|
- '.github/workflows/azureStorageTests.yml'
|
|
|
|
jobs:
|
|
azure-storage-tests:
|
|
name: Azure Storage Tests
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
AZURITE_CONTAINER: azurite-${{ github.run_id }}-${{ github.run_attempt }}
|
|
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Pre-run cleanup
|
|
run: |
|
|
docker rm -f "$AZURITE_CONTAINER" 2>/dev/null || true
|
|
|
|
- name: Setup and start Azurite
|
|
run: |
|
|
# Detect network and set network arguments
|
|
JOB_NET=$(docker inspect -f '{{range $k,$v := .NetworkSettings.Networks}}{{printf "%s\n" $k}}{{end}}' "$(hostname)" 2>/dev/null | head -n1 || true)
|
|
|
|
if [ -n "$JOB_NET" ]; then
|
|
NETWORK_ARGS="--network $JOB_NET"
|
|
else
|
|
NETWORK_ARGS=""
|
|
fi
|
|
|
|
# Start Azurite container
|
|
docker run --name "$AZURITE_CONTAINER" \
|
|
$NETWORK_ARGS \
|
|
-p 10000:10000 \
|
|
-p 10001:10001 \
|
|
-p 10002:10002 \
|
|
-d mcr.microsoft.com/azure-storage/azurite \
|
|
azurite-blob --blobHost 0.0.0.0 --loose
|
|
|
|
# Set host based on network configuration
|
|
if [ -n "$JOB_NET" ]; then
|
|
HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$AZURITE_CONTAINER")
|
|
else
|
|
HOST=127.0.0.1
|
|
fi
|
|
|
|
# Wait for Azurite to be ready
|
|
echo "Waiting for Azurite at $HOST:10000..."
|
|
for i in $(seq 1 15); do
|
|
if curl -sS "http://$HOST:10000/" >/dev/null 2>&1; then
|
|
echo "Azurite ready"
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# Verify Azurite is running
|
|
if ! curl -sS "http://$HOST:10000/" >/dev/null 2>&1; then
|
|
echo "Azurite failed to start"
|
|
docker logs "$AZURITE_CONTAINER" || true
|
|
exit 1
|
|
fi
|
|
|
|
# Export host for subsequent steps
|
|
echo "AZURITE_HOST=$HOST" >> "$GITHUB_ENV"
|
|
|
|
- name: Caching dependencies
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '20'
|
|
cache: 'npm'
|
|
cache-dependency-path: |
|
|
./npm-shrinkwrap.json
|
|
./Common/npm-shrinkwrap.json
|
|
./DocService/npm-shrinkwrap.json
|
|
|
|
- name: Install modules
|
|
run: |
|
|
npm ci
|
|
npm --prefix Common ci
|
|
npm --prefix DocService ci
|
|
|
|
- name: Setup Azure storage environment
|
|
run: |
|
|
# Create minimal Azure storage configuration
|
|
cat > Common/config/local.json << EOF
|
|
{
|
|
"storage": {
|
|
"name": "storage-az",
|
|
"region": "",
|
|
"endpoint": "http://${AZURITE_HOST:-127.0.0.1}:10000/devstoreaccount1",
|
|
"bucketName": "test-container",
|
|
"storageFolderName": "files",
|
|
"cacheFolderName": "data",
|
|
"accessKeyId": "devstoreaccount1",
|
|
"secretAccessKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
|
|
},
|
|
"persistentStorage": {
|
|
"storageFolderName": "files/persistent"
|
|
},
|
|
"commandOptions": {
|
|
"az": {
|
|
"uploadData": {},
|
|
"uploadStream": {},
|
|
"download": {},
|
|
"syncCopyFromURL": {},
|
|
"listBlobsFlat": {
|
|
"maxPageSize": 1000
|
|
},
|
|
"deleteBlob": {}
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
|
|
echo "Azure storage configuration created"
|
|
|
|
- name: Create Azure container using Node.js from Common directory
|
|
run: |
|
|
# Wait a bit more for Azurite to be fully ready
|
|
sleep 10
|
|
|
|
# Run Node.js script from Common directory where Azure dependencies are installed
|
|
cd Common
|
|
node -e "
|
|
(async () => {
|
|
const { BlobServiceClient, StorageSharedKeyCredential } = require('@azure/storage-blob');
|
|
const endpoint = 'http://' + (process.env.AZURITE_HOST || '127.0.0.1') + ':10000/devstoreaccount1';
|
|
const client = new BlobServiceClient(endpoint, new StorageSharedKeyCredential('devstoreaccount1', 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=='));
|
|
await client.getContainerClient('test-container').createIfNotExists();
|
|
console.log('Azure environment ready');
|
|
})().catch(console.error);
|
|
"
|
|
|
|
- name: Run storage tests
|
|
run: npm run storage-tests
|
|
|
|
- name: Final cleanup
|
|
if: always()
|
|
run: docker rm -f "$AZURITE_CONTAINER" || true
|