frenata / xaqt

Evaluate arbitrary user code in a docker based sandbox.
MIT License
7 stars 5 forks source link

Remove Dependence On External Assets #24

Open asmr-hex opened 6 years ago

asmr-hex commented 6 years ago

Overview

currently, xaqt relies on two external assets which must be accessed at runtime:

  1. data/compilers.json: read in to configure which compilers are available
  2. data/Payload: a directory which is moved into a mounted volume in the Docker container. this directory contains the scripts necessary for executing user code within the docker container. when the xaqt package is installed on the $GOPATH (e.g. from running go get github.com/frenata/xaqt) then the dependence on these external assets causes no problems since the path to these external assets is correctly maintained.

However, if the xaqt package is used as a library and is vendored, which is often the case with apps which require a stable deploy process, then the paths to these assets are no longer correctly maintained. This makes renders the library unusable in such situations.

The main problem that this PR addresses is the reliance of the library on external assets. This is achieved by hard-coding the compilers.json into a Compilers struct (naming it DEFAULT_COMPILERS since that is, in fact, what it is) and COPYing the data/Payload directory into the docker container at image build time rather than at runtime.

Major Changes

Caveats in Refactor

since we still need to mount a volume to insert the user code into the container, but we can't mount into the entrypoint directory without overwriting the directory (and thus deleting all the run scripts), we must mount/load the usercode into a separate directory than the run scripts. this results in the follows directory structure:

/usercode/ # this is where the usercode is loaded into
/entrypoint/ # this is where the run scripts are stored

this means that the run scripts need to call the code from the correct directory.

this PR resolves issue #23 and issue #11