-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate application from Python to Node.js with Docker support
- Loading branch information
1 parent
d60f01e
commit 68c31c9
Showing
10 changed files
with
3,785 additions
and
204 deletions.
There are no files selected for viewing
This file contains 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,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"] |
This file contains 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,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.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.