Let’s Deploy our Online Code Executor in Google Cloud
Tags: programming, computerscience, career
Published: 2021-02-15 19:16:19

We will deploy our online code execution system in google cloud.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cw2i784dz1rxge87y1gm.jpg)

<figcaption>Photo by Rajeshwar Bachu on Unsplash
</figcaption>

## Tutorials in this Series

   * Deploy our Online Code Executor in Google Cloud (this tutorial)
   * [Understanding the API of Judge0](https://levelup.gitconnected.com/lets-develop-an-online-code-editor-compiler-like-hackerrank-c433d8db060d)
   * [Creating an online code editor front-end](https://medium.com/javascript-in-plain-english/lets-develop-an-online-code-editor-compiler-like-hackerrank-702881803eee) 

## Youtube Demo

{% youtube axqFB7pDWug %}

This is what we will be creating finally
{% youtube x5YD1yOC8_c %}
<figcaption>Final Result</figcaption>

## Introduction

**Judge0** is a robust, scalable, and open-source **online code execution** system that can be used to build a wide range of applications that need online code execution features. It is used in multiple competitive programming platforms, code editors, e-learning platforms.

We will deploy judge0 in google cloud for our online code execution.
**Step 1: Create a project in google cloud and enable billing**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dhc2oo7kmqbeezo8dbdo.png)
**Step 2: Create a VM instance from Compute Engine**
Things to Note

 1. You get $300 free credits when you open the account.
 2. you have per-second billing, which is super awesome, pay as you use.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/w28yun7gstz6kfxydzaf.png)

<figcaption>go to compute engine and VM instance</figcaption>

You can select default options and check for firewall HTTP and HTTPS for incoming traffic.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/niqwtjwp3csbg39fqu9g.png)
<figcaption>create VM instance</figcaption>
**Step3: SSH to the terminal from the browser of the new VM**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/lam6l7b75v5e18mz2dpj.png)
<figcaption>open the terminal</figcaption>

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wm719pmsp905r1h5pmtw.png)

**Step 4: Install Docker and Docker Compose in the VM** 

Follow this page for detailed instructions for self-hosting of judge-0

{% github judge0/judge0 %}

Install docker and docker-compose from the official page.

Make sure [docker](https://medium.com/javarevisited/top-15-online-courses-to-learn-docker-kubernetes-and-aws-for-fullstack-developers-and-devops-d8cc4f16e773) is running

`sudo systemctl status docker`

Make docker-compose is running

`docker-compose --version`

Download and extract release judge0 archive

`wget https://github.com/judge0/judge0/releases/download/v1.12.0/judge0-v1.12.0.zip
unzip judge0-v1.12.0.zip`

Run all services and wait a few seconds until everything is initialized

`cd judge0-v1.12.0
sudo docker-compose up -d db redis
sleep 10s
sudo docker-compose up -d
sleep 5s`

## Resizing Disk space

You might get an error no space left on the device

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/67qsdmemuspwflhh2dcn.png)

You need to go to the Manage disk page, edit and increase the disk size

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/59215njxiciknyhul8n6.png)

Stop and start the VM again, so that resize works properly.

Run the last command again

`sudo docker-compose up -d`

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b1i4fwb2k3hfcy6fx5zy.png)
<figcaption>Docker is working</figcaption>

If everything goes well, you will see this screen.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8h0qh0z1jvnyluzn3sma.png)

Your instance of Judge0 v1.12.0 is now available at `http://<IP ADDRESS OF YOUR SERVER>`

If you open http://34.72.83.62/dummy-client.html and execute a sample code.
[Judge0 Dummy Client](http://34.72.83.62/dummy-client.html)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/h6iacy5jm262ybouadif.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ewtzpk6oxg4tmri252et.png)

<figcaption>Running hello world in the online judge</figcaption>

We will deep dive into the API and create front-end in upcoming tutorials

## Tutorials in this Series

1. Deploy our Online Code Executor in Google Cloud (this tutorial)
2. [Understanding the API of Judge0](https://levelup.gitconnected.com/lets-develop-an-online-code-editor-compiler-like-hackerrank-c433d8db060d)
3. [Creating an online code editor front-end](https://medium.com/javascript-in-plain-english/lets-develop-an-online-code-editor-compiler-like-hackerrank-702881803eee)