diff --git a/apps/engine/src/utils/ec2Setup.ts b/apps/engine/src/utils/ec2Setup.ts new file mode 100644 index 0000000..4d76936 --- /dev/null +++ b/apps/engine/src/utils/ec2Setup.ts @@ -0,0 +1,37 @@ +import { NodeSSH } from 'node-ssh'; + +export async function installDos2unix(ssh: NodeSSH) { + console.log('Installing dos2unix...'); + const result = await ssh.execCommand( + 'sudo apt-get update && sudo apt-get install -y dos2unix' + ); + if (result.code !== 0) { + console.error('Failed to install dos2unix:', result.stderr); + throw new Error('Failed to install dos2unix'); + } + console.log('dos2unix installed successfully.'); +} + +export async function installDocker(ssh: NodeSSH) { + console.log('Installing Docker...'); + const commands = [ + 'sudo apt-get update', + 'sudo apt-get install -y ca-certificates curl', + 'sudo install -m 0755 -d /etc/apt/keyrings', + 'sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc', + 'sudo chmod a+r /etc/apt/keyrings/docker.asc', + 'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null', + 'sudo apt-get update', + 'sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin', + ]; + + for (const command of commands) { + const result = await ssh.execCommand(command); + if (result.code !== 0) { + console.error(`Failed to execute command: ${command}`); + console.error('Error:', result.stderr); + throw new Error('Failed to install Docker'); + } + } + console.log('Docker installed successfully.'); +} diff --git a/apps/engine/src/utils/submission.ts b/apps/engine/src/utils/submission.ts index fa31d32..9116736 100644 --- a/apps/engine/src/utils/submission.ts +++ b/apps/engine/src/utils/submission.ts @@ -2,6 +2,7 @@ import { NodeSSH } from 'node-ssh'; import fs from 'fs'; import path from 'path'; import prisma from '@repo/db/client'; +import { installDocker, installDos2unix } from './ec2Setup'; async function convertLineEndings(ssh: NodeSSH, filePath: string) { const result = await ssh.execCommand(` @@ -35,6 +36,10 @@ export async function processSubmission(submission: any) { await ssh.connect({ host, username, privateKey }); console.log('Connected to EC2 instance.'); + console.log('Installing required packages on EC2...'); + await installDos2unix(ssh); + await installDocker(ssh); + const remoteWorkDir = `/tmp/${assignmentId}_work`; console.log('Creating working directory on EC2...'); diff --git a/docker-compose.yml b/docker-compose.yml index d7eb667..b3232c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: engine: image: ayush272002/automarker-engine:latest environment: - - KAFKA_URI=sepp- + - KAFKA_URI= - KAFKA_USERNAME= - KAFKA_PASSWORD= - DATABASE_URL=