Skip to content

Commit

Permalink
Added bank api-test-run dockerfiles generation test (#143)
Browse files Browse the repository at this point in the history
* Added bank api-test-run dockerfiles generation test

* Prettier
  • Loading branch information
aydarng authored Dec 11, 2024
1 parent 94fe673 commit ce615b2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion signify-ts-test/.prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/dist
**/dist
/signify-ts-test/test/data/
2 changes: 1 addition & 1 deletion signify-ts-test/test/run-bank-reports-download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const unpackZipFile = (
const confPath = path.join(__dirname, "./data/600-banks-test-data");

if (!includeAllSignedReports) {
const specificPrefix = "external_manifest_orig_bundle";
const specificPrefix = "external_manifest";
console.log(`Only moving reports with specific prefix: ${specificPrefix}`);
moveReports(
path.join(destFolder, bankName, `/reports/signed_reports`),
Expand Down
48 changes: 48 additions & 0 deletions signify-ts-test/test/run-generate-bank-dockerfiles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as fs from "fs";
import { number } from "mathjs";
import * as path from "path";

const baseKeriaUrl = 20001;
const baseKeriaBootUrl = 20003;
const outputDir = "../images";

// Run containers with --network host to have access to the locally running Kerias(ex. docker run --network host bank_1_api_test)

test("generate-bank-dockerfiles", async function run() {
// Generate dockerfiles for bank api tests
const bankAmount = process.env.BANK_COUNT || 1;
generateDockerfiles(number(bankAmount));
}, 3600000);

function generateDockerfiles(bankAmount: number) {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

// Generate Dockerfiles
for (let i = 1; i <= bankAmount; i++) {
const bankName = `Bank_${i}`;
const keriaUrl = `http://127.0.0.1:${baseKeriaUrl + (i - 1) * 10}`;
const keriaBootUrl = `http://127.0.0.1:${baseKeriaBootUrl + (i - 1) * 10}`;

const dockerfileContent = `
# Use a base image with the correct platform
FROM --platform=linux/amd64 node:20-alpine AS base
WORKDIR /signify-ts-test
COPY ../signify-ts-test .
RUN npm i
RUN npm run build
ENV BANK_NAME=${bankName}
ENV KERIA_URL=${keriaUrl}
ENV KERIA_BOOT_URL=${keriaBootUrl}
CMD ["npx", "jest", "start", "./test/run-workflow-bank-api.test.ts"]
`;

// Write the Dockerfile to the output directory
const filePath = path.join(outputDir, `bank_${i}.dockerfile`);
fs.writeFileSync(filePath, dockerfileContent.trim());
console.log(`Generated: ${filePath}`);
}
}

0 comments on commit ce615b2

Please sign in to comment.