Skip to content

Commit

Permalink
Merge pull request #112 from devkeon/feature/fileprocessing
Browse files Browse the repository at this point in the history
Feature/fileprocessing
  • Loading branch information
devkeon committed Dec 27, 2023
2 parents b076405 + 7a4f428 commit e782677
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ide-server-main-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
REPOSITORY: ${{ secrets.AWS_ECR_NAME }}
TAG1: ${{ secrets.AWS_ECR_TAG1 }}
TAG2: ${{ secrets.AWS_ECR_TAG2 }}
TAG3: ${{ secrets.AWS_ECR_TAG3 }}
TEST_DB_URL: ${{ secrets.TEST_DB_URL }}
TEST_DB_USERNAME: ${{ secrets.TEST_DB_USERNAME }}
TEST_DB_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }}
Expand All @@ -39,7 +40,7 @@ jobs:
- name: Generate Dockerrun.aws.json
run: |
echo '{"AWSEBDockerrunVersion": "2", "containerDefinitions": [{"name": "main", "image": "${{ secrets.AWS_ECR_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_ECR_NAME }}:${{ secrets.AWS_ECR_TAG1 }}", "essential": true, "memory": 512, "portMappings": [{"hostPort": 80, "containerPort": 8080}], "links": ["run"]}, {"name": "run", "image": "${{ secrets.AWS_ECR_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_ECR_NAME }}:${{ secrets.AWS_ECR_TAG2 }}", "essential": true, "memory": 512, "portMappings": [{"hostPort": 9090, "containerPort": 8080}]}]}' > Dockerrun.aws.json
echo '{"AWSEBDockerrunVersion": "2", "containerDefinitions": [{"name": "main", "image": "${{ secrets.AWS_ECR_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_ECR_NAME }}:${{ secrets.AWS_ECR_TAG1 }}", "essential": true, "memory": 512, "portMappings": [{"hostPort": 8080, "containerPort": 8080}], "links": ["run"]}, {"name": "run", "image": "${{ secrets.AWS_ECR_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_ECR_NAME }}:${{ secrets.AWS_ECR_TAG2 }}", "essential": true, "memory": 512, "portMappings": [{"hostPort": 9090, "containerPort": 8080}]},{"name": "nginx","image": "${{ secrets.AWS_ECR_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.AWS_ECR_NAME }}:${{ secrets.AWS_ECR_TAG3 }}","essential": true, "memory": 512,"portMappings": [{"hostPort": 80,"containerPort": 80}],"links": ["main"]}]}' > Dockerrun.aws.json
- name: Deploy to Elastic Beanstalk
uses: einaregilsson/beanstalk-deploy@v21
Expand Down
12 changes: 10 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "80:8080"
- "8080:8080"
environment:
DB_URL: ${DB_URL}
DB_USERNAME: ${DB_USERNAME}
Expand All @@ -32,4 +32,12 @@ services:
dockerfile: Dockerfile
image: ${REGISTRY}/${REPOSITORY}:${TAG2}
ports:
- "9090:8080"
- "9090:8080"

nginx:
build:
context: ./nginx
dockerfile: Dockerfile
image: ${REGISTRY}/${REPOSITORY}:${TAG3}
ports:
- "80:80"
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public FileProcessResponse<ExecuteResponse> executeCode(@Validated @RequestBody
String id = decode.get("id");

executeRequest.setUserId(Long.parseLong(id));

log.info("source code = {}", executeRequest.getSourceCode());
return service.executeAndSaveCode(executeRequest);
}

Expand All @@ -99,6 +99,7 @@ public FileProcessResponse<SubmitResponse> submitCode(@Validated @RequestBody Su
String id = decode.get("id");

submitRequest.setUserId(Long.parseLong(id));
log.info("source code = {}", submitRequest.getSourceCode());

return service.submitAndSaveCode(submitRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.goojeans.idemainserver.repository.membersolved.MemberSolvedRepository;
import com.goojeans.idemainserver.util.FileExtension;
import com.goojeans.idemainserver.util.Language;
import com.goojeans.idemainserver.util.SubmitResult;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -116,7 +115,7 @@ public FileProcessResponse<ExecuteResponse> executeAndSaveCode(ExecuteRequest re
throw new RuntimeException(response.getError());
}
} catch (Exception e) {
log.info("error={}", e.getStackTrace());
log.error(e.getMessage());
return new FileProcessResponse<>(6000, null, e.getMessage());
} finally {
if (uploadFile != null && uploadFile.exists()){
Expand Down
7 changes: 7 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx:latest

COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
50 changes: 50 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
user nginx;
worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
listen 80;

location /ws/chat {
proxy_pass http://main:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}

location / {
proxy_pass http://main:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';

if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
}
}

0 comments on commit e782677

Please sign in to comment.