This server receives HTTP requests with C/C++ code and returns the stackstrace of the first 300 lines that are run. The stacktrace contains the state of each line, both in the stack and heap: names, types and addresses of variables, the current function name and signature, etc.
It was inspired by this article on Tork engine and this fork of Philip Guo's Python Tutor.
This system also has a frontend repository.
There are 2 kinds of containers in this backend server (actually 3, but let's not focus on that for now): one that holds the Go application that uses Tork and other that is the sandbox where the C/C++ code is compiled and run with Valgrind.
See the big arrow in the image above? That is Tork managing and creating a container as a task when it receives a request. Inside this new container the code is compiled and run through a modified version of Valgrind (made by Philip Guo). It then returns the stacktrace of the code to the client.
The extra container mentioned at the beginning is the database used by Tork to manage tasks: PostgreSQL.
One caveat of this system is that the Valgrind version is very old: from 2013/2014. The original code run in a Ubuntu 14 container, with gcc 4.8.4. I managed to update to a Debian 9 container, with gcc 6.3.0 pulled from archived repositories of apt. Above that, some weird errors happens that I don't remember. With containers with gcc 10 it changes the error to "lack of debug symbols" (or something like that) from newer versions of libc6-dbg.
This project is composed of two images: One that will run the Go program and other that will be run by Tork.
So we need to first build the image that Tork will use (the one that will compile and run the custom valgrind):
sudo docker build -f Dockerfile -t gcc-compiler .Then, we build the main image:
sudo docker build -f Dockerfile.main -t hpw-server .apt install haveged # docker compose use of random things like.. name creation?
sudo docker compose up -dTo see logs, run:
sudo docker compose logs hpw-serverWe build and run postgres:
sudo docker run -d --name tork-postgres -p 5432:5432 -e POSTGRES_PASSWORD=tork -e POSTGRES_USER=tork -e PGDATA=/var/lib/postgresql/data/pgdata -e POSTGRES_DB=tork postgres:15.3As "Docker in docker" is unadvised, we run the main container using the -v flag that will bind the most internal container image docker socket to the external docker. Ps.: --network=host/--net=host don't work on Windows.
sudo docker run -v /var/run/docker.sock:/var/run/docker.sock --network=host -d hpw-serverExecute a code snippet. Example
curl \
-s \
-X POST \
-H "content-type:application/json" \
-d '{"language":"c","code":"#include <stdio.h>\n\nint main(){\nint i = 23;\nint *k = &i;\nreturn 0;\n}"}' \
http://localhost:8000/executeYou can try changing the language to c++.
go list -m -u github.com/runabol/tork #find last version
go get github.com/runabol/[email protected] #get last version
go mod tidy #syncronize dependencies- Make it don't jump commands inside for loops.

