Get an example
To understand how the coding exercises work, we recommend starting off with a template. For this tutorial, we'll use the Python template, but feel free to choose the template for the language which you are most comfortable with.
Once you've selected your template, create it locally by cloning it using git.
Structure of a coding exercise
In our example, the coding exercise is stored in the
*-project folder. It consists of two files:
universe.py: This is a simple code snippet that will be displayed to the user, who will need to fix it.
test_universe.py: This is a file which will be used to test the presented code snippet when the user presses the "run" button.
Configuration of the exercise in techio.yml
techio.yml, the project is defined as such:
projects: python: root: /python-project runner: python:3
Here are the details:
projects:: This is where you define all the projects you need for your playground.
python:: This is the name of this project.
root: /python-project: This is where the project is stored.
runner: python:3: This is a Docker image used to run your project
Add the exercise to a markdown
welcome.md markdown, you can see a special tag that creates the exercise at the position you want:
@[Luke, how many stars are there in these galaxies?]( )
Let's explain this command:
@ [Luke, how many stars are there in these galaxies?]: Displays the text in a label at the top of the exercise.
stubs: ["universe.py"]: Define what files to show to the user.
command: "python3 test_universe.py": Test command given to the docker image (defined in
techio.yml) for this project when the user presses the run button.
Understanding the workflow
- When a coding exercise is displayed to a user, it shows a label and the stubs declared in the stubs property.
- When the user changes the snippet and clicks the "run" button, the docker image specified in
techio.ymlfor the project is instancied and launched
- The root folder of the project is mounted in the image (located in the
- The snippets that have been modified by the user are copied into the root folder and the initial ones are erased.
- The specified command is ran on the Docker instance.
- Techio commands (e.g.
TECHIO> success) can be called during this process to interact with the user.
The runner is the execution engine for your code. It packages your project and then runs your code exercises.
Technically speaking, it's a Docker image. You may use official images available on the Docker Hub or those made specifically for the Tech.io platform (which include extra tools and features). A complete documentation about the Runners can be find here.
Test the playground
It's time to test the playground:
- Push your code and navigate back to the main page of your playground.
- Once the new version is detected and sucessfully built, click the preview button.
- Check that your coding exercise are displayed as the stub content. You should see an interactive code editor.
- Click the "Run" button.
This will run the Docker image with the parameters that you set in the “command” property of your test exercise.
Here are interesting links to dive into the awesome world of Runners: