From d82af87df00e3f35b6dabda750e8d499ee49efdb Mon Sep 17 00:00:00 2001 From: KulkarniShashank Date: Fri, 29 Dec 2023 13:21:34 +0530 Subject: [PATCH 1/2] fix: create service name random in shell script Signed-off-by: KulkarniShashank --- Dockerfiles/Dockerfile.agnet-provisioning | 11 +++++++++++ .../AFJ/scripts/start_agent_ecs.sh | 15 +++++++++++++-- .../src/agent-provisioning.service.ts | 4 ++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Dockerfiles/Dockerfile.agnet-provisioning b/Dockerfiles/Dockerfile.agnet-provisioning index 134846452..ce8acdd0d 100644 --- a/Dockerfiles/Dockerfile.agnet-provisioning +++ b/Dockerfiles/Dockerfile.agnet-provisioning @@ -1,6 +1,11 @@ # Stage 1: Build the application FROM node:18-alpine as build RUN npm install -g pnpm +# Install AWS CLI +RUN apk update +RUN apk add openssh-client +RUN apk update +RUN apk add aws-cli # Set the working directory WORKDIR /app @@ -23,6 +28,12 @@ RUN pnpm run build agent-provisioning # Stage 2: Create the final image FROM node:18-alpine as prod +# Install AWS CLI +RUN apk update +RUN apk add openssh-client +RUN apk update +RUN apk add aws-cli + WORKDIR /app RUN npm install -g pnpm diff --git a/apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh b/apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh index e685f75a0..86c89ed85 100644 --- a/apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh +++ b/apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh @@ -24,6 +24,18 @@ CLUSTER_NAME=${19} TESKDEFINITION_FAMILY=${20} DESIRED_COUNT=1 + +generate_random_string() { + echo "$(date +%s%N | sha256sum | base64 | head -c 12)" +} + +# Call the function to generate a random string +random_string=$(generate_random_string) + +# Print the generated random string +echo "Random String: $random_string" + +SERVICE_NAME="${AGENCY}-${CONTAINER_NAME}-service-${random_string}" EXTERNAL_IP=$(echo "$2" | tr -d '[:space:]') ADMIN_PORT_FILE="$PWD/agent-provisioning/AFJ/port-file/last-admin-port.txt" INBOUND_PORT_FILE="$PWD/agent-provisioning/AFJ/port-file/last-inbound-port.txt" @@ -73,7 +85,6 @@ last_used_inbound_port=$(increment_port "$last_used_inbound_port" "$last_used_in echo "$last_used_inbound_port" > "$INBOUND_PORT_FILE" INBOUND_PORT="$last_used_inbound_port" -SERVICE_NAME="${AGENCY}-${CONTAINER_NAME}-service-${ADMIN_PORT}" echo "Last used admin port: $ADMIN_PORT" echo "Last used inbound port: $INBOUND_PORT" echo "AGENT SPIN-UP STARTED" @@ -242,7 +253,7 @@ EOF cat <${PWD}/agent-provisioning/AFJ/token/${AGENCY}_${CONTAINER_NAME}.json { - "token" : "$token" + "token" : "" } EOF diff --git a/apps/agent-provisioning/src/agent-provisioning.service.ts b/apps/agent-provisioning/src/agent-provisioning.service.ts index 7dc510df5..465e4087d 100644 --- a/apps/agent-provisioning/src/agent-provisioning.service.ts +++ b/apps/agent-provisioning/src/agent-provisioning.service.ts @@ -22,10 +22,10 @@ export class AgentProvisioningService { async walletProvision(payload: IWalletProvision): Promise { try { - const { containerName, externalIp, orgId, seed, walletName, walletPassword, walletStorageHost, walletStoragePassword, walletStoragePort, walletStorageUser, webhookEndpoint, agentType, protocol, afjVersion, tenant, indyLedger, apiKey } = payload; + const { containerName, externalIp, orgId, seed, walletName, walletPassword, walletStorageHost, walletStoragePassword, walletStoragePort, walletStorageUser, webhookEndpoint, agentType, protocol, afjVersion, tenant, indyLedger } = payload; if (agentType === AgentType.AFJ) { // The wallet provision command is used to invoke a shell script - const walletProvision = `${process.cwd() + process.env.AFJ_AGENT_SPIN_UP} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${afjVersion} ${indyLedger} ${apiKey} ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN} ${process.env.CLUSTER_NAME} ${process.env.TESKDEFINITION_FAMILY}`; + const walletProvision = `${process.cwd() + process.env.AFJ_AGENT_SPIN_UP} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${afjVersion} ${indyLedger} ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN} ${process.env.CLUSTER_NAME} ${process.env.TESKDEFINITION_FAMILY}`; const spinUpResponse: object = new Promise(async (resolve) => { await exec(walletProvision, async (err, stdout, stderr) => { From 4754574bc628023d05b61cb9997cd40d637eb7a2 Mon Sep 17 00:00:00 2001 From: KulkarniShashank Date: Fri, 29 Dec 2023 14:03:58 +0530 Subject: [PATCH 2/2] Solved issue regarding the sonar lint Signed-off-by: KulkarniShashank --- Dockerfiles/Dockerfile.agnet-provisioning | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Dockerfiles/Dockerfile.agnet-provisioning b/Dockerfiles/Dockerfile.agnet-provisioning index ce8acdd0d..3a5a6d8eb 100644 --- a/Dockerfiles/Dockerfile.agnet-provisioning +++ b/Dockerfiles/Dockerfile.agnet-provisioning @@ -1,11 +1,15 @@ # Stage 1: Build the application FROM node:18-alpine as build -RUN npm install -g pnpm +# RUN npm install -g pnpm # Install AWS CLI -RUN apk update -RUN apk add openssh-client -RUN apk update -RUN apk add aws-cli +# RUN apk update +# RUN apk add openssh-client +# RUN apk update +# RUN apk add aws-cli +RUN npm install -g pnpm \ + && apk update \ + && apk add openssh-client \ + && apk add aws-cli # Set the working directory WORKDIR /app @@ -29,10 +33,14 @@ RUN pnpm run build agent-provisioning # Stage 2: Create the final image FROM node:18-alpine as prod # Install AWS CLI -RUN apk update -RUN apk add openssh-client -RUN apk update -RUN apk add aws-cli +# RUN apk update +# RUN apk add openssh-client +# RUN apk update +# RUN apk add aws-cli +RUN npm install -g pnpm \ + && apk update \ + && apk add openssh-client \ + && apk add aws-cli WORKDIR /app RUN npm install -g pnpm