Skip to content

Commit

Permalink
feat: migrate application from Python to Node.js with Docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
coderRaj07 committed Jan 13, 2025
1 parent d60f01e commit 68c31c9
Show file tree
Hide file tree
Showing 10 changed files with 3,785 additions and 204 deletions.
22 changes: 12 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM python:3.12-slim

# Install any Python dependencies your application needs, e.g.:
RUN pip install --no-cache-dir requests

RUN mkdir /sealed && chmod 777 /sealed
# Use the official Node.js image as the base image
FROM node:22

# Set the working directory inside the container
WORKDIR /app

COPY . /app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install the dependencies
RUN npm install

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code to the working directory
COPY . .

CMD ["python", "-m", "my_proof"]
# Command to run the script
CMD ["node", "main.js"]
79 changes: 79 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import fs from 'fs';
import path from 'path';
import unzipper from 'unzipper';
import dotenv from 'dotenv';
import { Proof } from './utils/proofValidation.js';

// Load environment variables from .env file
dotenv.config();

// Default to 'production' if NODE_ENV is not set
const environment = process.env.NODE_ENV || 'production';

// Set the input and output directories based on the environment
const INPUT_DIR = environment === 'development' ? './demo/input' : '/input';
const OUTPUT_DIR = environment === 'development' ? './demo/output' : '/output';
const SEALED_DIR = environment === 'development' ? './demo/sealed' : '/sealed';

function loadConfig() {
const config = {
dlpId: process.env.DLP_ID, // dlp_id is 24 for our datadao
inputDir: INPUT_DIR,
// salt: '5EkntCWI',
validatorBaseApiUrl: process.env.VALIDATOR_BASE_API_URL,
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
};
console.info(`Using config: ${JSON.stringify(config, null, 2)}`);
return config;
}

async function extractInput() {
const inputFiles = fs.readdirSync(INPUT_DIR);

for (const inputFilename of inputFiles) {
const inputFile = path.join(INPUT_DIR, inputFilename);

if (inputFile.endsWith('.zip')) {
await new Promise((resolve, reject) => {
fs.createReadStream(inputFile)
.pipe(unzipper.Extract({ path: INPUT_DIR }))
.on('close', () => {
console.info(`Extracted ${inputFile}`);
resolve();
})
.on('error', reject);
});
}
}
}

async function run() {
const config = loadConfig();
console.log('Running proof generation...', fs.existsSync(INPUT_DIR));
const inputFilesExist = fs.existsSync(INPUT_DIR) && fs.readdirSync(INPUT_DIR).length > 0;

if (!inputFilesExist) {
throw new Error(`No input files found in ${INPUT_DIR}`);
}

await extractInput();

// Assume Proof is asynchronous
const proof = new Proof(config);
const proofResponse = await proof.generate();

const outputPath = path.join(OUTPUT_DIR, 'results.json');
fs.writeFileSync(outputPath, JSON.stringify(proofResponse, null, 2));
console.info(`Proof generation complete: ${JSON.stringify(proofResponse, null, 2)}`);
}

// Call the run function immediately
(async () => {
try {
await run();
console.log('Run function executed successfully.');
} catch (error) {
console.error('Error executing run function:', error);
}
})();
Empty file removed my_proof/__init__.py
Empty file.
83 changes: 0 additions & 83 deletions my_proof/__main__.py

This file was deleted.

32 changes: 0 additions & 32 deletions my_proof/models/proof_response.py

This file was deleted.

79 changes: 0 additions & 79 deletions my_proof/proof.py

This file was deleted.

Loading

0 comments on commit 68c31c9

Please sign in to comment.