Skip to content

Commit

Permalink
setup for local dev / ec2 environment
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcWeberFS committed Nov 11, 2024
1 parent 5d9f485 commit 5a5d462
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set local environment script path: $env:VIDEO_DOWNLOADER_SCRIPT_PATH = "C:\Code\video-downloader\video-downloader-backend\src\main\resources\scripts\video_downloader.py"
6 changes: 4 additions & 2 deletions video-downloader-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ FROM openjdk:17-jdk-slim
# Install Python and necessary dependencies
RUN apt-get update && \
apt-get install -y python3 python3-pip && \
pip3 install instaloader && \
pip3 install boto3 && \
pip3 install instaloader boto3 && \
rm -rf /var/lib/apt/lists/*

# Set working directory
Expand All @@ -17,6 +16,9 @@ COPY target/*.jar app.jar
# Copy the Python script into the container
COPY src/main/resources/scripts/video_downloader.py /app/scripts/

# Set environment variable for the script path
ENV VIDEO_DOWNLOADER_SCRIPT_PATH="/app/scripts/video_downloader.py"

# Expose the backend port
EXPOSE 8080

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "http://3.127.36.67")
@CrossOrigin(origins = "http://3.127.36.67, http://localhost:3000, http://localhost:8080")
public class VideoDownloadController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class InstagramVideoDownloaderDelegate implements JavaDelegate {

@Value("${video.downloader.script-path}")
private String scriptPath;

@Override
public void execute(DelegateExecution execution) throws Exception {

Expand All @@ -19,15 +23,21 @@ public void execute(DelegateExecution execution) throws Exception {
String s3Folder = "instagram-videos";

String result = downloadInstagramVideo(url, s3BucketName, s3Folder);

System.out.println("Download result: " + result);

execution.setVariable("downloadResult", result);
}

private String downloadInstagramVideo(String url, String s3BucketName, String s3Folder) {
String result = "";
try {
String pythonExecutable = "/usr/bin/python3";
String scriptPath = "/app/scripts/video_downloader.py";
String pythonExecutable = "python3";

if (scriptPath == null || scriptPath.isEmpty()) {
System.out.println("VIDEO_DOWNLOADER_SCRIPT_PATH environment variable not set. Using default script path.");
scriptPath = "/app/scripts/video_downloader.py";
}

ProcessBuilder processBuilder = new ProcessBuilder(
pythonExecutable,
Expand Down
7 changes: 6 additions & 1 deletion video-downloader-backend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ camunda:
bpm:
generic-properties:
properties:
historyTimeToLive: 5
historyTimeToLive: 5


video:
downloader:
script-path: C:/Code/video-downloader/video-downloader-backend/src/main/resources/scripts/video_downloader.py
9 changes: 4 additions & 5 deletions video-downloader-frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import './App.css';
import config from './config';

function App() {
const [url, setUrl] = useState('');
Expand All @@ -12,8 +13,7 @@ function App() {
setDownloadLink(null);

try {
// Start the download process and get the processInstanceId
const response = await fetch(`http://3.127.36.67:8080/api/start-download?url=${encodeURIComponent(url)}`, {
const response = await fetch(`${config.apiBaseUrl}/start-download?url=${encodeURIComponent(url)}`, {
method: 'POST',
});

Expand All @@ -34,15 +34,14 @@ function App() {
const pollForDownloadLink = (instanceId) => {
const intervalId = setInterval(async () => {
try {
const response = await fetch(`http://3.127.36.67:8080/api/download-link?processInstanceId=${instanceId}`);
const response = await fetch(`${config.apiBaseUrl}/download-link?processInstanceId=${instanceId}`);

if (response.ok) {
const result = await response.json();
setDownloadLink(result.downloadLink);
setMessage("Download link is ready!");
clearInterval(intervalId);
} else if (response.status === 204) {
// Link is not ready yet, keep polling
setMessage("Waiting for download link to be ready...");
} else {
setMessage("Failed to retrieve download link.");
Expand All @@ -53,7 +52,7 @@ function App() {
setMessage("An error occurred while waiting for the download link.");
clearInterval(intervalId);
}
}, 5000); // Poll every 5 seconds
}, 5000);
};

return (
Expand Down
8 changes: 8 additions & 0 deletions video-downloader-frontend/src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = {
apiBaseUrl: process.env.NODE_ENV === 'development'
? 'http://localhost:8080/api'
: 'http://3.127.36.67:8080/api' // Replace with your EC2 instance's IP
};

export default config;

0 comments on commit 5a5d462

Please sign in to comment.