-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from CS3219-AY2425S1/solomon/code-execute
Solomon/code execute
- Loading branch information
Showing
55 changed files
with
5,061 additions
and
4,573 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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.