Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automate docker and dos2unix installation in ec2 #65

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions apps/engine/src/utils/ec2Setup.ts
Original file line number Diff line number Diff line change
@@ -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.');
}
5 changes: 5 additions & 0 deletions apps/engine/src/utils/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down Expand Up @@ -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...');
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
engine:
image: ayush272002/automarker-engine:latest
environment:
- KAFKA_URI=sepp-
- KAFKA_URI=
- KAFKA_USERNAME=
- KAFKA_PASSWORD=
- DATABASE_URL=
Expand Down
Loading