Skip to content

Build EMBArk

Michael Messner edited this page Aug 27, 2021 · 18 revisions

Initial Setup

  1. Clone embark github repository i.e git clone [email protected]:e-m-b-a/embark.git
  2. Change directory to root of the repository i.e embark
  3. Clone original emba repository (git clone https://github.com/e-m-b-a/emba.git)
  4. Run cd emba && sudo ./installer.sh -F to force install all the dependencies on your host. This enables functionalities like CVE Search.
  5. Setup docker environment (see below)

Updating environment configuration

Refer to template.env, you will see the following env variables

DATABASE_NAME: Name of the sql database
DATABASE_USER: User of the database
DATABASE_PASSWORD: For for logging in to the database
DATABASE_HOST: host of the database
DATABASE_PORT: port
MYSQL_ROOT_PASSWORD: Root password. Always equal to DATABASE_PASSWORD for our dev setups
MYSQL_DATABASE: Database that gets created on MySql Container startup. Same as DATABASE_NAME
REDIS_HOST: Host of Redis DB
REDIS_PORT: Port of Redis DB
SECRET_KEY: DJANGO SECRET_KEY

We are not maintaining a central copy for now. Till then please maintain your own copy wherever you setup your dev environment.
To generate the django secret key you can use the following python command:
python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'

Building and running containers

  1. Build your image

docker-compose build

  1. Before bringing your containers up rename template.env -> .env and edit .env file:
DATABASE_NAME=<Name you are going to give your db>
DATABASE_USER=root
DATABASE_PASSWORD=<value of MYSQL_ROOT_PASSWORD>
DATABASE_HOST=0.0.0.0(or host.docker.internal for windows)
DATABASE_PORT=3306
MYSQL_ROOT_PASSWORD=<This should be set>
MYSQL_DATABASE=<Same as DATABASE_NAME> 
REDIS_HOST=0.0.0.0(or host.docker.internal for windows)
REDIS_PORT=7777
SECRET_KEY=<paste your key here>
  1. Bring your containers up

docker-compose up -d

  1. Restart your EMBArk container. This step is important to create the needed database environment!

docker-compose restart embark

  1. How to exec into your EMBArk container

docker exec -it embark_embark_1 bash

Testing Django setup

Test if the django application (uWSGI workers) came up with the following command:

curl -XGET 'http://0.0.0.0:80'
You should get a response like this:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>EMBArk home!</h1>
</body>

Updating code

Whenever you change something in the embark directory (the django project), you will have to make it live. Since all our code is mounted through compose, developers just need to run the following command:
docker-compose restart embark
If you change code in the templates or static area, just make sure your browser reloads the files e.g. just open in private browser window.

Exec inside the containers

If you want to run something from inside the container like a shell script to analyze a firmware

  1. Paste that firmware inside directory embark
  2. Start into a shell into your container with docker exec -it embark_embark_1 bash
  3. Run your commands.

Notes to take care

MAC or Windows: If you are using docker desktop on a Mac or windows machine. Remove line network_mode: host from docker-compose.yml

Windows: If you are using docker desktop windows machine. The database host inside env would be host.docker.internal

Version of docker-compose: Currently our compose file is compatible with docker-compose version 1.25.xand 1.27.x. 1.28.x and 1.29.x are already available and by default you will end up with latest version unless you specify explicitly while installing. Please install version1.27.x until we can test more current versions.