-
Notifications
You must be signed in to change notification settings - Fork 8
chore : update docker-compose file #405
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
Draft
StefanoDoc
wants to merge
4
commits into
main
Choose a base branch
from
chore/fix-docker-compose
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+282
−6
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c1bfdd8
add emulation to azure-storage image and switch cosmos to vnext-preview
StefanoDoc 3331a03
update docker-compose
StefanoDoc edca92c
add setup file for creating storage and queue locally with azure emul…
StefanoDoc 7e31480
add eventhub & kafka emulator & setup-cosmos-container
StefanoDoc 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,86 @@ | ||
| version: "3.9" | ||
| name: 'io-sign-dev' | ||
|
|
||
| services: | ||
| cosmos-db: | ||
| image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator | ||
| #preview version wich supports ARM | ||
| image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview | ||
| mem_limit: 3G | ||
| cpu_count: 2 | ||
| tty: true | ||
| environment: | ||
| - AZURE_COSMOS_EMULATOR_PARTITION_COUNT=3 | ||
| - AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true | ||
| - COSMOSDB_EMULATOR_URI=http://cosmos-db:8081 | ||
| - COSMOSDB_EMULATOR_KEY='C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==' | ||
| - NODE_TLS_REJECT_UNAUTHORIZED=0 | ||
| ports: | ||
| - 8081:8081 | ||
| - 1234:1234 | ||
| - 10251:10251 | ||
| - 10252:10252 | ||
| - 10253:10253 | ||
| - 10254:10254 | ||
| # volume persistence disabled for local debugging on macOS (permission issues) | ||
| # volumes: | ||
| # - cosmos-db-volume:/data/db | ||
|
|
||
| cosmos-db-setup: | ||
| image: node:20-alpine | ||
| working_dir: /app | ||
| depends_on: | ||
| - cosmos-db | ||
| environment: | ||
| - COSMOS_ENDPOINT=http://cosmos-db:8081 | ||
| - NODE_TLS_REJECT_UNAUTHORIZED=0 | ||
| volumes: | ||
| - cosmos-db-volume:/data/db | ||
| - ./setup-cosmos-containers.js:/app/setup-cosmos-containers.js | ||
| command: sh -c "npm install @azure/cosmos && node setup-cosmos-containers.js" | ||
|
|
||
| storage: | ||
| image: mcr.microsoft.com/azure-storage/azurite | ||
| command: "azurite -l /data --blobHost 0.0.0.0 --queueHost 0.0.0.0 --skipApiVersionCheck" | ||
| azurite: | ||
| platform: linux/amd64 | ||
| image: mcr.microsoft.com/azure-storage/azurite:latest | ||
| ports: | ||
| - 10000:10000 | ||
| - 10001:10001 | ||
| - 10002:10002 | ||
| command: azurite --skipApiVersionCheck --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 | ||
|
|
||
| azurite-setup: | ||
| image: node:20-alpine | ||
| working_dir: /app | ||
| depends_on: | ||
| - azurite | ||
| volumes: | ||
| - ./setup-azurite-containers.js:/app/setup-azurite-containers.js | ||
| command: sh -c "npm install @azure/storage-blob @azure/storage-queue @azure/data-tables && node setup-azurite-containers.js" | ||
|
|
||
| eventhubs: | ||
| image: "mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest@sha256:25ec4141efb69933a0c82e6a787fa147a3895519e7d236d4c41ba568e03100eb" | ||
| depends_on: | ||
| - "azurite" | ||
| ports: | ||
| - "5672:5672" | ||
| - "9092:9092" | ||
| - "9093:9093" | ||
| volumes: | ||
| - "./eventhubs-emulator.json:/Eventhubs_Emulator/ConfigFiles/Config.json" | ||
| environment: | ||
| BLOB_SERVER: azurite | ||
| METADATA_SERVER: azurite | ||
| ACCEPT_EULA: Y | ||
|
|
||
| kafka-ui: | ||
| image: "provectuslabs/kafka-ui:latest@sha256:8f2ff02d64b0a7a2b71b6b3b3148b85f66d00ec20ad40c30bdcd415d46d31818" | ||
| depends_on: | ||
| - "eventhubs" | ||
| ports: | ||
| - "8002:8080" | ||
| environment: | ||
| KAFKA_CLUSTERS_0_NAME: "local" | ||
| KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: "eventhubs:9092" | ||
| KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL: "SASL_PLAINTEXT" | ||
| KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM: "PLAIN" | ||
| KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG: 'org.apache.kafka.common.security.plain.PlainLoginModule required username="$$ConnectionString" password="Endpoint=sb://eventhubs;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;";' | ||
|
|
||
| volumes: | ||
| cosmos-db-volume: |
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,43 @@ | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/Azure/azure-event-hubs-emulator-installer/refs/heads/main/EventHub-Emulator/Schema/Config-schema.json", | ||
| "UserConfig": { | ||
| "NamespaceConfig": [ | ||
| { | ||
| "Type": "EventHub", | ||
| "Name": "emulatorNs1", | ||
| "Entities": [ | ||
| { | ||
| "Name": "sc-contracts", | ||
| "PartitionCount": 2, | ||
| "ConsumerGroups": [ | ||
| { | ||
| "Name": "Default" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "Name": "billing", | ||
| "PartitionCount": 2, | ||
| "ConsumerGroups": [ | ||
| { | ||
| "Name": "Default" | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "Name": "analytics", | ||
| "PartitionCount": 2, | ||
| "ConsumerGroups": [ | ||
| { | ||
| "Name": "Default" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "LoggingConfig": { | ||
| "Type": "Console" | ||
| } | ||
| } | ||
| } |
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,53 @@ | ||
| // this script creates the necessary containers, queues in the Azurite storage emulator | ||
|
|
||
| const { BlobServiceClient } = require("@azure/storage-blob"); | ||
| const { QueueServiceClient } = require("@azure/storage-queue"); | ||
|
|
||
| const connectionString = | ||
| "DefaultEndpointsProtocol=http;" + | ||
| "AccountName=devstoreaccount1;" + | ||
| "AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" + | ||
| "BlobEndpoint=http://azurite:10000/devstoreaccount1;" + | ||
| "QueueEndpoint=http://azurite:10001/devstoreaccount1;" + | ||
| "TableEndpoint=http://azurite:10002/devstoreaccount1;"; | ||
|
|
||
| const blobServiceClient = | ||
| BlobServiceClient.fromConnectionString(connectionString); | ||
| const queueServiceClient = | ||
| QueueServiceClient.fromConnectionString(connectionString); | ||
|
|
||
| const containers = ["uploaded-documents", "signed-documents","validated-documents"]; | ||
| const queues = [ | ||
| "on-signature-request-ready", | ||
| "waiting-for-signature-request-updates", | ||
| "on-signature-request-wait-for-signature", | ||
| "on-signature-request-signed", | ||
| "on-signature-request-rejected" | ||
| ]; | ||
|
|
||
| const createContainerIfNotExists = async (name) => { | ||
| try { | ||
| const containerClient = blobServiceClient.getContainerClient(name); | ||
| await containerClient.createIfNotExists(); | ||
| console.log(`Container ${name} created.`); | ||
| } catch (error) { | ||
| console.error(`Error creating container ${name}:`, error); | ||
| } | ||
| }; | ||
|
|
||
| const createQueueIfNotExists = async (name) => { | ||
| try { | ||
| const queueClient = queueServiceClient.getQueueClient(name); | ||
| await queueClient.createIfNotExists(); | ||
| console.log(`Queue ${name} created.`); | ||
| } catch (error) { | ||
| console.error(`Error creating queue ${name}:`, error); | ||
| } | ||
| }; | ||
|
|
||
| (async () => { | ||
| await Promise.all([ | ||
| ...containers.map(createContainerIfNotExists), | ||
| ...queues.map(createQueueIfNotExists), | ||
| ]); | ||
| })(); |
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,122 @@ | ||
|
|
||
| process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
|
|
||
| const { CosmosClient } = require("@azure/cosmos"); | ||
|
|
||
| const endpoint = process.env.COSMOS_ENDPOINT || "http://cosmos-db:8081"; | ||
| const key = | ||
| process.env.COSMOS_KEY || | ||
| "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; | ||
|
|
||
| const client = new CosmosClient({ endpoint, key, connectionPolicy: { enableEndpointDiscovery: false } }); | ||
|
|
||
| // Databases and their containers with specific partition keys | ||
| const databases = [ | ||
| { | ||
| id: "backoffice", | ||
| containers: [ | ||
| { id: "api-keys", partitionPath: "/institutionId" }, | ||
| { id: "api-keys-by-id", partitionPath: "/id" }, | ||
| { id: "consents", partitionPath: "/institutionId" }, | ||
| { id: "issuers", partitionPath: "/institutionId" }, | ||
| ], | ||
| }, | ||
| { | ||
| id: "issuer", | ||
| containers: [ | ||
| { id: "dossiers", partitionPath: "/issuerId" }, | ||
| { id: "issuers", partitionPath: "/subscriptionId" }, | ||
| { id: "issuers-by-subscription-id", partitionPath: "/id" }, | ||
| { id: "issuers-by-vat-number", partitionPath: "/id" }, | ||
| { id: "issuers-whitelist", partitionPath: "/id" }, | ||
| { id: "signature-requests", partitionPath: "/issuerId" }, | ||
| { id: "uploads", partitionPath: "/id" }, | ||
| ], | ||
| }, | ||
| { | ||
| id: "user", | ||
| containers: [ | ||
| { id: "signature-requests", partitionPath: "/signerId" }, | ||
| { id: "signatures", partitionPath: "/signerId" }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| const DEFAULT_PARTITION_PATH = "/id"; | ||
|
|
||
| const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); | ||
|
|
||
| async function createDatabaseAndContainers(dbDef) { | ||
| const { id: dbId, containers } = dbDef; | ||
| try { | ||
| const { database } = await client.databases.createIfNotExists({ id: dbId }); | ||
| console.log(`Database '${dbId}' ready.`); | ||
|
|
||
| for (const containerDef of containers) { | ||
| const containerId = containerDef.id || containerDef; | ||
| const partitionPath = containerDef.partitionPath || DEFAULT_PARTITION_PATH; | ||
| try { | ||
| await database.containers.createIfNotExists( | ||
| { | ||
| id: containerId, | ||
| partitionKey: { paths: [partitionPath], kind: "Hash" }, | ||
| }, | ||
| { offerThroughput: 400 } | ||
| ); | ||
| console.log(` Container '${containerId}' (partition: '${partitionPath}') created in DB '${dbId}'.`); | ||
| } catch (innerErr) { | ||
| console.error(` Error creating container '${containerId}' in DB '${dbId}':`, innerErr.message || innerErr); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error(`Error creating/reading database '${dbId}':`, err.message || err); | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| const maxAttempts = 30; | ||
| const delayMs = 2000; | ||
| let attempt = 0; | ||
|
|
||
| while (attempt < maxAttempts) { | ||
| try { | ||
| // quick call to check emulator availability | ||
| await client.database("" + databases[0].id).read(); | ||
| // If read doesn't throw, connection works (or DB exists). | ||
| break; | ||
| } catch (err) { | ||
| // Cosmos emulator returns 404 for read when DB doesn't exist; that's fine. | ||
| // We just want to verify the emulator is responding. | ||
| if (err.code === 404) { | ||
| console.log("Cosmos emulator is reachable (Database not found yet)."); | ||
| break; | ||
| } | ||
| const isNetworkErr = /ENOTFOUND|ECONNREFUSED|ECONNRESET|certificate|CERT_|EPROTO/i.test((err && err.code) || err.message || ""); | ||
| attempt++; | ||
| if (attempt >= maxAttempts) { | ||
| console.error("Cosmos emulator not reachable after retries, giving up."); | ||
| throw err; | ||
| } | ||
| console.log(`Waiting for Cosmos emulator (${attempt}/${maxAttempts})... reason: ${err.code || err.message}`); | ||
| await sleep(delayMs); | ||
| } | ||
| } | ||
|
|
||
| // Create databases and containers | ||
| for (const dbDef of databases) { | ||
| try { | ||
| await createDatabaseAndContainers(dbDef); | ||
| } catch (err) { | ||
| console.error(`Failed to provision DB '${dbDef.id}':`, err.message || err); | ||
| } | ||
| } | ||
|
|
||
| console.log("Cosmos provisioning finished."); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error("setup-cosmos-containers.js failed:", err.message || err); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
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.
Check failure
Code scanning / CodeQL
Disabling certificate validation High
Copilot Autofix
AI 1 day ago
In general, you should not globally disable TLS certificate validation. Instead, either (a) leave the default verification behavior in place, or (b) if you must trust a custom/self‑signed certificate (for an emulator or internal endpoint), explicitly configure a proper CA/certificate for that connection only, rather than changing
NODE_TLS_REJECT_UNAUTHORIZED.The single best fix here, without changing existing functionality beyond restoring secure defaults, is to remove the line that sets
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";. Cosmos DB client connections will then use standard TLS verification rules, and any other libraries in the process will no longer have their certificate checks disabled globally. No other code in this file appears to rely on this environment variable, and we do not need to add any imports or helper methods to achieve the fix. The change is localized to the very top ofsetup-cosmos-containers.js, removing line 2.