Skip to content
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

Go Docker API #21

Merged
merged 4 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Included with the xaqt library is a simple REST api server. Two endpoints are ex

* GET `/languages/` : This will return a JSON list with the available target languages.
* POST `/evaluate/` : This evaluates code, encoded in a JSON body of the following form:

```
{
"language": "python",
Expand All @@ -46,3 +46,7 @@ Included with the xaqt library is a simple REST api server. Two endpoints are ex
```

Returned is a JSON object that reports success or failure of evaluation, and for each element of `stdins`, what the code has printed to `stdout` for that element.

## Development ##
### Vendoring ##
we currently use [`govendor`](https://github.com/kardianos/govendor) as our vendoring tool for external dependencies.
11 changes: 9 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (c *Context) Evaluate(language, code string, stdins []string) ([]string, Me
// input is n test calls seperated by newlines
// input and expected MUST end in newlines
func (c *Context) run(language, code, stdinGlob string) (string, Message) {
log.Printf("sandbox launching sandbox...\nLanguage: %s\nStdin: %sCode: Hidden\n", language, stdinGlob)
log.Printf("launching new %s sandbox", language)
// log.Printf("launching sandbox...\nLanguage: %s\nStdin: %sCode: Hidden\n", language, stdinGlob)

lang, ok := c.compilers[strings.ToLower(language)]
if !ok || lang.Disabled == "true" {
return "", Message{"error", "language not supported"}
Expand All @@ -70,8 +72,13 @@ func (c *Context) run(language, code, stdinGlob string) (string, Message) {
return "", Message{"error", "no code submitted"}
}

sb := newSandbox(lang.ExecutionDetails, code, stdinGlob, c.options)
sb, err := newSandbox(lang.ExecutionDetails, code, stdinGlob, c.options)
if err != nil {
log.Printf("sandbox initialization error: %v", err)
return "", Message{"error", fmt.Sprintf("%s", err)}
}

// run the new sandbox
output, err := sb.run()
if err != nil {
log.Printf("sandbox run error: %v", err)
Expand Down
18 changes: 9 additions & 9 deletions data/Payload/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,21 @@ addtionalArg=$4
#
########################################################################

# redirect stdout --> logfile.txt & stderr --> errors
exec 1> $"/usercode/logfile.txt"
exec 2> $"/usercode/errors"
#3>&1 4>&2 >


START=$(date +%s.%2N)
NL=$'\n'
FIRST_LINE="TRUE"
# the separator values below are also maintained in glob.go in project root dir...
IN_SEP="*-BRK-*"
OUT_SEP="*-BRK-*"
#Branch 1

# Branch 1: we are calling an interpreter (no compilation step)
if [ "$runner" = "" ]; then
# while read p; do
# echo -n $p | $compiler /usercode/$file
# done < $"/usercode/inputFile"
# Reads until reaching $SEP and then runs command with that
# block of input
# Reads until reaching $SEP and then runs command with that block of input
while read p; do
if [ "$p" = "$IN_SEP" ]; then

Expand Down Expand Up @@ -84,7 +83,8 @@ if [ "$runner" = "" ]; then
#Branch 2
else # runner was not blank
#In case of compile errors, redirect them to a file
$compiler /usercode/$file $addtionalArg > /dev/null #&> /usercode/errors.txt
$compiler /usercode/$file $addtionalArg > /dev/null #&> /usercode/errors.txt

#Branch 2a : exit code is zero aka success
if [ $? -eq 0 ]; then
while read p; do
Expand Down Expand Up @@ -118,7 +118,7 @@ else # runner was not blank
else
echo "Compilation Failed:"
#if compilation fails, display the output file
cat /usercode/errors.txt
cat /usercode/errors
fi
fi

Expand Down
16 changes: 16 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# XAQT Library
*TODO (cw|4.28.2018) create godocs instead of this file...these are mostly notes for myself during development.*

# Public Types
* **`xaqt.Context`**: entrypoint into all functionality. TODO Propose renaming?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah despite naming it that, I don't love it... especially now that we're using the Context library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i feel you, naming is hard and often doesn't feel like it holds up over time as the code progresses-- luckily this is a painless refactor at this point, so if we decide on a good rename we can change it. i won't do it in this PR since its not super relevant...but we can think it over :)

* **`xaqt.Compilers`**: list of compilters. Propose re-typing to `[]Compiler`.
* **`xaqt.Message`**: details on success or failure of execution

# Public Methods

``` go
func NewContext(xaqt.Compilers, ...option) // option should be public!
func (ctx *Context) ReadCompilers(string)
func (ctw *Context) Languages([]string) // rename -> GetSupportedLanguages ?
func (ctw *Context) Evaluate(string, string, []string)
```
Loading