diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2eac0dc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +.git +.env \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f64d07e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,31 @@ +name: Deploy to EC2 + +on: + push: + branches: + - ai + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts + + - name: Deploy to EC2 + run: | + ssh ${{ secrets.EC2_HOST }} << 'EOF' + set -e + echo "Pulling latest container..." + podman stop bun-backend || true + podman rm bun-backend || true + podman pull http://docker.io/abhishek194/resume-xpert-backend:latest + podman run -d --name bun-backend -p 3000:3000 --env-file /home/ubuntu/.env docker.io//:latest + EOF diff --git a/.github/workflows/gitlab-sync.yml b/.github/workflows/gitlab-sync.yml index c2e2cdb..2f8f3c9 100644 --- a/.github/workflows/gitlab-sync.yml +++ b/.github/workflows/gitlab-sync.yml @@ -21,5 +21,5 @@ jobs: git remote add gitlab https://oauth2:${{ secrets.GITLAB_TOKEN }}@gitlab.com/abhishek_nitdelhi/cvexpert-backend.git # Push only the master branch and tags - git push gitlab master + git push gitlab main git push gitlab --tags diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b9fc7b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Use official Node.js image as base +FROM oven/bun:1.1.13-alpine + +# Set working directory +WORKDIR /app + +# Copy package files and install dependencies +COPY package.json bun.lockb ./ +RUN bun install --production + +# Copy source code +COPY . . + +# Expose port (change if your app uses a different port) +EXPOSE 3000 + +# Start the backend server in production mode +CMD ["bun", "start"] diff --git a/package.json b/package.json index c69c8b4..d3fc6c1 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "module": "index.ts", "type": "module", "scripts": { - "dev": "bun --watch src/server.ts" + "dev": "bun --watch src/server.ts", + "run": "bun run src/server.ts" }, "devDependencies": { "@elysiajs/swagger": "^1.2.0", diff --git a/src/routes/analyzeRoutes.ts b/src/routes/analyzeRoutes.ts index a82c762..693cfe8 100644 --- a/src/routes/analyzeRoutes.ts +++ b/src/routes/analyzeRoutes.ts @@ -26,21 +26,37 @@ const analyzeRoute = new Elysia({ prefix: '/analyze' }) async ({ body, error }: any) => { console.log('Analyze Route called'); const { fileID, file, userID } = body; + let progress = 0; try { + // Step 1: File Upload + progress = 1; const access = await checkFileAccess(fileID, userID); if (!access) { - return error(403, 'You do not have access to this file'); + return { error: 'You do not have access to this file', progress }; } console.log('File access granted'); + // Step 2: Detecting Word Length + progress = 2; + // Simulate word length detection (replace with actual logic if needed) + // Step 3: Parsing + progress = 3; + // Simulate parsing (replace with actual logic if needed) + // Step 4: Scanning Fields + progress = 4; + // Simulate scanning fields (replace with actual logic if needed) + // Step 5: Analyzing Content + progress = 5; const response = await analyzeFileUsingAI(file, fileID); + // Step 6: Generating Report + progress = 6; if (response) { - return response; + return { ...response, progress }; } else { - return error(500, 'Failed to analyze the file'); + return { error: 'Failed to analyze the file', progress }; } } catch (err) { console.error(err); - return error(500, 'An internal error occurred while processing the file.'); + return { error: 'An internal error occurred while processing the file.', progress }; } }, {