Skip to content

Commit fea26e9

Browse files
authored
Merge pull request #61 from cheehongw/judge0
Self-host judge0
2 parents 201ed4f + 1a78227 commit fea26e9

File tree

7 files changed

+145
-27
lines changed

7 files changed

+145
-27
lines changed

.github/workflows/build_push_registry.yml

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build-push-artifact:
1414
runs-on: ubuntu-latest
1515
outputs:
16-
build_status: ${{ steps.set_output.outputs.build_status }}
16+
should_deploy: ${{ steps.deploy.outputs.BUILD_STEP_RAN }}
1717
steps:
1818
- name: "Checkout"
1919
uses: "actions/checkout@v3"
@@ -33,6 +33,9 @@ jobs:
3333
- 'matching_service/**'
3434
collab_service:
3535
- 'collab_service/**'
36+
code_execution:
37+
- 'code_execution/**'
38+
3639
3740
- name: 'Create env file'
3841
run: |
@@ -54,41 +57,82 @@ jobs:
5457
run: |-
5558
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
5659
57-
- name: Determine Build Status
58-
id: set_output
59-
run: echo "::set-output name=build_status::false"
60-
6160
- name: 1. Build and Push frontend
61+
id: a
6262
if: steps.changes.outputs.frontend == 'true'
6363
run: |
6464
docker-compose build frontend
6565
docker-compose push frontend
66-
echo "::set-output name=build_status::true"
6766
6867
- name: 2. Build and Push question-service
68+
id: b
6969
if: steps.changes.outputs.question_service == 'true'
7070
run: |
7171
docker-compose build question-service
7272
docker-compose push question-service
73-
echo "::set-output name=build_status::true"
7473
7574
- name: 3. Build and Push user-service
75+
id: c
7676
if: steps.changes.outputs.user_service == 'true'
7777
run: |
7878
docker-compose build user-service
7979
docker-compose push user-service
80-
echo "::set-output name=build_status::true"
8180
8281
- name: 4. Build and Push matching-service
82+
id: d
8383
if: steps.changes.outputs.matching_service == 'true'
8484
run: |
8585
docker-compose build matching-service
8686
docker-compose push matching-service
87-
echo "::set-output name=build_status::true"
8887
8988
- name: 5. Build and Push collab-service
89+
id: e
9090
if: steps.changes.outputs.collab_service == 'true'
9191
run: |
9292
docker-compose build collab-service
9393
docker-compose push collab-service
94-
echo "::set-output name=build_status::true"
94+
95+
- name: 6. Build and Push code-execution
96+
id: f
97+
if: steps.changes.outputs.code_execution == 'true'
98+
run: |
99+
docker-compose build code-execution
100+
docker-compose push code-execution
101+
102+
- name: determine deploy step
103+
id: deploy
104+
if: ${{ steps.a.conclusion == 'success' || steps.b.conclusion == 'success' || steps.c.conclusion == 'success' || steps.d.conclusion == 'success' || steps.e.conclusion == 'success' || steps.f.conclusion == 'success' }}
105+
run: |
106+
echo "BUILD_STEP_RAN=true" >> $GITHUB_OUTPUT
107+
108+
109+
deploy:
110+
needs: build-push-artifact
111+
if: ${{needs.build-push-artifact.outputs.should_deploy== 'true'}}
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: Checkout code
115+
uses: actions/checkout@v2
116+
117+
- name: "Set up google auth"
118+
id: auth
119+
uses: "google-github-actions/auth@v1"
120+
with:
121+
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
122+
123+
- name: "Use gcloud CLI"
124+
run: "gcloud info"
125+
126+
- name: "SSH to VM"
127+
id: 'compute-ssh'
128+
uses: 'google-github-actions/ssh-compute@v0'
129+
with:
130+
instance_name: 'peerprep-prod'
131+
zone: 'asia-southeast1-b'
132+
ssh_private_key: '${{ secrets.SSH_KEY }}'
133+
command: 'echo "${{ secrets.ENV_FILE }}" | sudo tee /usr/src/peerprep/.env > /dev/null && sudo chmod 777 /usr/src/peerprep/scripts/init.sh && sudo /usr/src/peerprep/scripts/init.sh'
134+
135+
- id: 'test'
136+
run: |-
137+
echo '${{ steps.compute-ssh.outputs.stdout }}'
138+
echo '${{ steps.compute-ssh.outputs.stderr }}'

.github/workflows/deployment.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ name: Deployment Workflow
33
on:
44
workflow_dispatch:
55
workflow_run:
6-
workflows: ["Selectively Build and Push to Artifact Registry", "Build and Push to Artifact Registry"]
6+
workflows: ["Build and Push to Artifact Registry"]
77
types:
88
- completed
99

1010
jobs:
1111
deploy:
1212
runs-on: ubuntu-latest
13-
if: >
14-
github.event_name == 'workflow_dispatch' ||
15-
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.outputs.build_status == 'true')
1613
steps:
1714
- name: Checkout code
1815
uses: actions/checkout@v2

code_execution/Dockerfile.prod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Stage 1: Build the application
2+
FROM node:18-alpine AS builder
3+
4+
WORKDIR /app
5+
COPY package*.json ./
6+
RUN npm ci
7+
COPY . .
8+
RUN npm run build
9+
10+
# Stage 2: Setup the production environment
11+
FROM node:18-alpine
12+
WORKDIR /usr/src/app
13+
COPY package*.json ./
14+
RUN npm ci --only=production
15+
COPY --from=builder /app/dist ./dist
16+
17+
# Command to run the application
18+
CMD ["npm", "run", "serve"]

code_execution/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"start": "ts-node src/index.ts",
9-
"build": "tsc --init"
9+
"build": "tsc",
10+
"serve": "node dist/index.js"
1011
},
1112
"keywords": [],
1213
"author": "",

collab_service/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

docker-compose.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,50 @@ services:
6666
ports:
6767
- "8082:8082"
6868

69+
code-execution:
70+
name: code-execution
71+
image: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/code-execution:latest
72+
build:
73+
context: ./code_execution
74+
dockerfile: Dockerfile.prod
75+
environment:
76+
- PORT=8090
77+
- JUDGE0_API_KEY=${JUDGE0_API_KEY}
78+
ports:
79+
- "8090:8090"
80+
volumes:
81+
- questions_test_cases:/app/question_test_cases
82+
83+
judge0-server:
84+
image: judge0/judge0:1.13.0
85+
ports:
86+
- "2358:2358"
87+
privileged: true
88+
environment:
89+
REDIS_PASSWORD: ${REDIS_PASSWORD}
90+
POSTGRES_HOST: postgres
91+
POSTGRES_USER: ${POSTGRES_USER}
92+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
93+
POSTGRES_DB: judge0
94+
POSTGRES_PORT: ${PG_PORT}
95+
96+
env_file:
97+
- config_env/config-judge0.env
98+
99+
judge0-workers:
100+
image: judge0/judge0:1.13.0
101+
command: ["./scripts/workers"]
102+
privileged: true
103+
environment:
104+
REDIS_PASSWORD: ${REDIS_PASSWORD}
105+
POSTGRES_HOST: postgres
106+
POSTGRES_USER: ${POSTGRES_USER}
107+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
108+
POSTGRES_DB: judge0
109+
POSTGRES_PORT: ${PG_PORT}
110+
env_file:
111+
- config_env/config-judge0.env
112+
69113
mongo:
70114
container_name: mongo
71115
image: mongo:6.0
@@ -104,6 +148,18 @@ services:
104148
retries: 5
105149
start_period: 30s
106150

151+
redis:
152+
container_name: redis
153+
image: redis:7
154+
ports:
155+
- "6379:6379"
156+
command: [
157+
"bash", "-c",
158+
'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"'
159+
]
160+
environment:
161+
REDIS_PASSWORD: ${REDIS_PASSWORD}
162+
107163
volumes:
108164
postgres_data:
109165
mongo-dev-data:

docker_compose_dev.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ services:
3030
- profile_pictures:/usr/src/app/public/profile_pictures
3131

3232
code-execution:
33+
name: code-execution
3334
build:
3435
context: ./code_execution
3536
environment:
@@ -59,7 +60,6 @@ services:
5960
- "8083:8083"
6061

6162
# judge0-server:
62-
# container_name: judge0-server
6363
# image: judge0/judge0:1.13.0
6464
# ports:
6565
# - "2358:2358"
@@ -126,17 +126,17 @@ services:
126126
retries: 5
127127
start_period: 30s
128128

129-
# redis:
130-
# container_name: redis
131-
# image: redis:7
132-
# ports:
133-
# - "6379:6379"
134-
# command: [
135-
# "bash", "-c",
136-
# 'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"'
137-
# ]
138-
# environment:
139-
# REDIS_PASSWORD: ${REDIS_PASSWORD}
129+
redis:
130+
container_name: redis
131+
image: redis:7
132+
ports:
133+
- "6379:6379"
134+
command: [
135+
"bash", "-c",
136+
'docker-entrypoint.sh --appendonly yes --requirepass "$$REDIS_PASSWORD"'
137+
]
138+
environment:
139+
REDIS_PASSWORD: ${REDIS_PASSWORD}
140140

141141

142142
volumes:

0 commit comments

Comments
 (0)