-
Notifications
You must be signed in to change notification settings - Fork 2
Solomon/code execute #62
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b23580a
Add code execution service
solomonng2001 aa8be69
Add .env.example
solomonng2001 a1232e7
Add api test cases and api usage examples
solomonng2001 c7a72bf
Add accepted or attempted status and dockerise
solomonng2001 2e99740
Merge branch 'staging' into solomon/code-execute
solomonng2001 7994e7f
Update test.yml
solomonng2001 d3d5b05
Link frontend code execution to execution service and sync across mat…
solomonng2001 f32dd72
Update submission and execution logic
solomonng2001 ca7864d
Update README APIs
solomonng2001 f79896f
Add sandbox for python execution (to be debugged)
solomonng2001 1716efa
Dockerise execution of python code
solomonng2001 dd90eaf
Resolve merge conflicts and additional fixes
solomonng2001 fdd7a13
Update test.yml
solomonng2001 b5324e2
update test.yml
solomonng2001 70c52bd
Update optional population of tests
solomonng2001 66be207
Update test.yml
solomonng2001 eab5a68
Fix populate bug
solomonng2001 911ff0f
move decode_test to tests folder
chiaryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.env.example | ||
|
||
.git | ||
.gitignore | ||
|
||
.dockerignore | ||
Dockerfile | ||
|
||
README.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FIREBASE_CREDENTIAL_PATH=cs3219-staging-codeexecution-firebase-adminsdk-ce48j-00ab09514c.json | ||
PORT=8083 | ||
|
||
# If you are NOT USING docker, use the below variables | ||
# HISTORY_SERVICE_URL=http://localhost:8082/ | ||
|
||
# If you are USING docker, use the below variables | ||
HISTORY_SERVICE_URL=http://history-service:8082/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
cs3219-staging-codeexecution-firebase-adminsdk-ce48j-00ab09514c.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM golang:1.23 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# Install Docker CLI | ||
RUN apt-get update && apt-get install -y \ | ||
docker.io \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change | ||
COPY go.mod go.sum ./ | ||
|
||
RUN go mod tidy && go mod download && go mod verify | ||
|
||
COPY . . | ||
|
||
RUN go build -v -o /usr/local/bin/app ./main.go | ||
|
||
EXPOSE 8083 | ||
|
||
CMD ["app"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
# Execution Service | ||
|
||
### Installation | ||
|
||
1. Install dependencies: | ||
|
||
```bash | ||
go mod tidy | ||
``` | ||
|
||
2. Create the `.env` file from copying the `.env.example`, and copy the firebase JSON file into execution-service/ fill in the `FIREBASE_CREDENTIAL_PATH` with the path of the firebase credential JSON file. | ||
|
||
### Running the Application | ||
|
||
To start the server, run the following command: | ||
|
||
```bash | ||
go run main.go | ||
``` | ||
|
||
The server will be available at http://localhost:8083. | ||
|
||
## Running the Application via Docker | ||
|
||
To run the application via Docker, run the following command: | ||
|
||
```bash | ||
docker build -t execution-service . | ||
``` | ||
|
||
```bash | ||
docker run -p 8083:8083 --env-file .env -d execution-service | ||
``` | ||
|
||
The server will be available at http://localhost:8083. | ||
|
||
## API Endpoints | ||
|
||
- `POST /tests/populate` | ||
- `GET /tests/{questionDocRefId}/` | ||
- `POST /tests/{questionDocRefId}/execute` | ||
- `POST /tests/{questionDocRefId}/submit` | ||
|
||
## Managing Firebase | ||
|
||
To reset and repopulate the database, run the following command: | ||
|
||
```bash | ||
go run main.go | ||
``` | ||
|
||
## Repopulate test cases | ||
|
||
To repopulate test cases, you need to repopulate the questions in the question-service, which will automatically call the execution-service to populate the test cases. | ||
|
||
In question-service, run the following command: | ||
|
||
```bash | ||
go run main.go -populate | ||
``` | ||
|
||
## API Documentation | ||
|
||
`GET /tests/{questionDocRefId}/` | ||
|
||
To read visible test cases via a question ID, run the following command: | ||
|
||
```bash | ||
curl -X GET http://localhost:8083/tests/{questioinDocRefId}/ \ | ||
-H "Content-Type: application/json" | ||
``` | ||
|
||
The following json format will be returned: | ||
|
||
```json | ||
[ | ||
{ | ||
"input":"hello", | ||
"expected":"olleh" | ||
} | ||
] | ||
``` | ||
|
||
`POST /tests/{questionDocRefId}/execute` | ||
|
||
To execute test cases via a question ID without custom test cases, run the following command, with custom code and language: | ||
|
||
```bash | ||
curl -X POST http://localhost:8083/tests/{questioinDocRefId}/execute \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"code": "name = input()\nprint(name[::-1])", | ||
"language": "Python" | ||
}' | ||
``` | ||
|
||
The following json format will be returned: | ||
|
||
```json | ||
{ | ||
"visibleTestResults":[ | ||
{ | ||
"input":"hello", | ||
"expected":"olleh", | ||
"actual":"olleh", | ||
"passed":true, | ||
"error":"" | ||
} | ||
], | ||
"customTestResults":null | ||
} | ||
``` | ||
|
||
To execute visible and custom test cases via a question ID with custom test cases, run the following command, with custom code, language and custom test cases: | ||
|
||
```bash | ||
curl -X POST http://localhost:8083/tests/{questioinDocRefId}/execute \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"code": "name = input()\nprint(name[::-1])", | ||
"language": "Python", | ||
"customTestCases": "2\nHannah\nhannaH\nabcdefg\ngfedcba\n" | ||
}' | ||
``` | ||
|
||
The following json format will be returned: | ||
|
||
```json | ||
{ | ||
"visibleTestResults":[ | ||
{ | ||
"input":"hello", | ||
"expected":"olleh", | ||
"actual":"olleh", | ||
"passed":true, | ||
"error":"" | ||
} | ||
], | ||
"customTestResults":[ | ||
{ | ||
"input":"Hannah", | ||
"expected":"hannaH", | ||
"actual":"hannaH", | ||
"passed":true, | ||
"error":"" | ||
}, | ||
{ | ||
"input":"abcdefg", | ||
"expected":"gfedcba", | ||
"actual":"gfedcba", | ||
"passed":true, | ||
"error":"" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
`POST /tests/{questionDocRefId}/submit` | ||
|
||
To submit a solution and execute visible and hidden test cases via a question ID, run the following command, with custom code and language: | ||
|
||
```bash | ||
curl -X POST http://localhost:8083/tests/{questioinDocRefId}/submit \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"title": "Example Title", | ||
"code": "name = input()\nprint(name[::-1])", | ||
"language": "Python", | ||
"user": "user123", | ||
"matchedUser": "user456", | ||
"matchedTopics": ["topic1", "topic2"], | ||
"questionDifficulty": "Medium", | ||
"questionTopics": ["Loops", "Strings"] | ||
}' | ||
``` | ||
|
||
The following json format will be returned: | ||
|
||
```json | ||
{ | ||
"visibleTestResults":[ | ||
{ | ||
"input":"hello", | ||
"expected":"olleh", | ||
"actual":"olleh", | ||
"passed":true, | ||
"error":"" | ||
} | ||
], | ||
"hiddenTestResults":{ | ||
"passed":2, | ||
"total":2 | ||
}, | ||
"status":"Accepted" | ||
} | ||
``` | ||
|
||
If compilation error exists or any of the tests (visible and hidden) fails, status "Attempted" will be returned: | ||
|
||
```json | ||
{ | ||
"visibleTestResults":[ | ||
{ | ||
"input":"hello", | ||
"expected":"olleh", | ||
"actual":"", | ||
"passed":false, | ||
"error":"Command execution failed: Traceback (most recent call last):\n File \"/tmp/4149249165.py\", line 2, in \u003cmodule\u003e\n prit(name[::-1])\n ^^^^\nNameError: name 'prit' is not defined. Did you mean: 'print'?\n: %!w(*exec.ExitError=\u0026{0x4000364678 []})" | ||
} | ||
], | ||
"hiddenTestResults":{ | ||
"passed":0, | ||
"total":2 | ||
}, | ||
"status":"Attempted" | ||
} | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.