Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# do not use this env file. make a copy of it, save it as .env and make sure to update HE_CLIENT_SECRET
HE_CLIENT_SECRET=your_secret
# set to False in prod
HACKIDE_DEBUG=True
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=example
MONGO_INITDB_USER=test_user
MONGO_INITDB_PWD=test_password
MONGO_INITDB_DATABASE=codes
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea/
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand All @@ -7,6 +10,7 @@ __pycache__/
*.so

# Distribution / packaging
.env
.Python
env/
build/
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:2.7-buster
RUN apt-get install default-libmysqlclient-dev libcurl4-openssl-dev
# fix mysql error: ‘MYSQL {aka struct st_mysql}’ has no member named ‘reconnect’
RUN sed '/st_mysql_options options;/a unsigned int reconnect;' /usr/include/mysql/mysql.h -i.bkp

RUN useradd -ms /bin/bash app_runner
USER app_runner

ENV PYTHONBUFFERED=1
ENV PATH "$PATH:/home/app_runner/.local/bin"

WORKDIR /home/app_runner/code

COPY requirements.txt /home/app_runner/code/
RUN pip install -r requirements.txt
COPY . /home/app_runner/code/
USER root
RUN chown -R app_runner:app_runner *
USER app_runner
31 changes: 3 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,19 @@ hackIDE is an online code editor, compiler and interpreter based on Django, powe
## Screenshot-
![Screenshot for HackIDE](/hackIDE/static/hackIDE/img/screenshot.png?raw=true "Screenshot for HackIDE")

## Getting set up
Depending on your environment, you may need to install some libraries. On Debian/Ubuntu, you will need to:
```shell
sudo apt-get install libmysqlclient-dev libcurl4-gnutls-dev
```

To get your Python environment properly set up, you can create a virtual environment and use the requirements.txt file to install the proper versions of various libraries.

```shell
# Navigate to a directory of your choosing, where you will store your virtual environment.
$ mkdir virtualEnvs
$ cd virtualEnvs
$ virtualenv hackIDE_venv # We need python2. If you are using 3 by default, type virtualenv -p /usr/bin/python2.7 hackIDE_venv
$ source ~/virtualEnvs/hackIDE_venv/bin/activate
$ cd /location/of/your/copy/of/hackIDE
$ pip install -r requirements.txt
```


## How to run the server locally
To run the server locally, you will need to do two things:
1. Get a hackerearth API "Client Secret Key"
2. Change the hackIDE_project/settings.py file
1. Get a hackerearth API "Client Secret Key" (see section below)
2. Create a copy of .env.example, save it as .env and replace HE_CLIENT_SECRET with your token

### Get a Client Secret Key
Go to https://www.hackerearth.com/api/register/, create a HackerEarth profile and register a URL. You can register http://google.com, for example. Then you will be provided with a Client Secret Key.

### Change the hackIDE_project/settings.py file.
Change the ALLOWED_HOSTS line to
```shell
ALLOWED_HOSTS = ['*'] if not DEBUG else ['*']
```

### Then, startup the server with:

```shell
$ python manage.py collectstatic
$ HE_CLIENT_SECRET=your_token_here python manage.py runserver
$ docker-compose up
```

Then, you can connect to the site at 0.0.0.0:8000.
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.9"
# base compose. utilizes overrides
# dev: docker-compose up. deployment: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
services:
web:
env_file:
- .env
volumes:
- ./:/home/app_runner/code/
user: app_runner
build: .
image: hackide
command: sh -c "python manage.py collectstatic --no-input && python manage.py runserver 0.0.0.0:8000"
# command: sh -c "python manage.py runserver 0.0.0.0:8000"
ports:
- 8000:8000
mongo:
image: mongo
env_file:
- .env
restart: always
volumes:
- ./mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro
5 changes: 1 addition & 4 deletions hackIDE/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
COMPILE_URL = "https://api.hackerearth.com/v3/code/compile/"
RUN_URL = "https://api.hackerearth.com/v3/code/run/"

# access config variable
DEBUG = (os.environ.get('HACKIDE_DEBUG') != None)
# DEBUG = (os.environ.get('HACKIDE_DEBUG') or "").lower() == "true"
CLIENT_SECRET = os.environ['HE_CLIENT_SECRET'] if not DEBUG else ""
CLIENT_SECRET = os.environ.get('HE_CLIENT_SECRET', '')

permitted_languages = ["C", "CPP", "CSHARP", "CLOJURE", "CSS", "HASKELL", "JAVA", "JAVASCRIPT", "OBJECTIVEC", "PERL", "PHP", "PYTHON", "R", "RUBY", "RUST", "SCALA"]

Expand Down
4 changes: 2 additions & 2 deletions hackIDE_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
}

# use your db creds here
# TODO: Update with new host details before making live on heroku
connect(host='mongodb://JSSaini08:[email protected]:11705/codes')
# connect(host='mongodb://JSSaini08:[email protected]:11705/codes')
connect(host='mongodb://{}:{}@mongo:27017/{}'.format(os.environ.get('MONGO_INITDB_USER'), os.environ.get('MONGO_INITDB_PWD'), os.environ.get('MONGO_INITDB_DATABASE')))

# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
Expand Down
20 changes: 20 additions & 0 deletions mongo-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set -e

mongo <<EOF
use $MONGO_INITDB_DATABASE


db.createUser(
{
user: '$MONGO_INITDB_USER',
pwd: '$MONGO_INITDB_PWD',
roles: [
{
role: "readWrite",
db: '$MONGO_INITDB_DATABASE'
}
]
}
);

EOF