changed code structure

This commit is contained in:
2021-03-02 09:29:45 +04:00
parent ebfac2321f
commit ce26e79118
7 changed files with 47 additions and 20 deletions

12
server/docker/Makefile Normal file
View File

@@ -0,0 +1,12 @@
SHELL := /bin/bash
.PHONY: set_virtualenv,install_docker_requirements,dockerproc
set_virtualenv:
virtualenv env
install_docker_requirements:
source env/bin/activate && pip install -r requirements.txt
dockerproc:
ADMIN_USER=admin ADMIN_PASSWORD=admin docker-compose -f dockprom/docker-compose.yml up -d

6
server/docker/README Normal file
View File

@@ -0,0 +1,6 @@
Docker Module P2P-rendering-computation
========================================
This module is incharge to spin up docker contaianers , create
SSH server and VNC server. This module is implemented using
python.

View File

@@ -1,7 +1,14 @@
'''
The follwing file is a docker module to interact with the p2p
system computation/redering system.
Functionality
1. --createvm: Creates a ubuntu virtualmachine using docker settings and takes name as the parameter
'''
#!/usr/bin/env python3
'''
FUTURE RELEASE TO BE CONVERTED TO GO LANG
TODO: FUTURE RELEASE TO BE CONVERTED TO GO LANG
'''
import click
@@ -14,7 +21,7 @@ import os
# ----------------------------------------------- CLI flags --------------------------------------------------------
@click.command()
@click.option("--createvm", is_flag=True, help="Creates docker default VM")
@click.option("--createvm", help="Creates docker default VM")
# -------------------------------------------------------------------------------------------------------------------
# -------------------------------------- Actions when flags are called ----------------------------------------------
@@ -23,8 +30,8 @@ def main(createvm):
# creates docker virtual machine
if createvm:
name = str(uuid.uuid4())
build_run_contianer(name)
#name = str(uuid.uuid4())
build_run_contianer(createvm)
else:
ctx = click.get_current_context()
@@ -45,24 +52,32 @@ def build_run_contianer(name):
vnc_free_port = str(get_free_tcp_port())
# Check if image is already exists (If already exists then delete and rebuild)
'''
Note:
Since system dependant functionality is being used here. The
Error handleing is yet to be implemented.
'''
try:
client.images.get(tag_name)
print("------ Image exists (Running Docker container " + name + ") --------")
#print("------ Image exists (Running Docker container " + name + ") --------")
# Run the docker continer
# Running interactive version until log files for results are created
os.system("docker run -d=true --name="+ name +" --restart=always -p 6901:6901 -p "+ free_port +":22 -v=/opt/data:/data "+ tag_name +" /start")
os.system("docker run -d=true --name="+ name +" --restart=always -p "+ vnc_free_port +":6901 -p "+ free_port +":22 -v=/opt/data:/data "+ tag_name +" /start > /dev/null")
except:
print("------ Image does not exists (building " + name + " and running image) ---------")
#print("------ Image does not exists (building " + name + " and running image) ---------")
# client.images.build(path=framework_image_path,tag=tag_name,rm=True)
os.system("docker build -t " + tag_name + " " + image_path)
print("------ Running Docker contianer " + name + " ---------")
#print("------ Running Docker contianer " + name + " ---------")
# Run the docker continer
# Running interactive version until log files for results are created
os.system("docker run -d=true --name="+ name +" --restart=always -p 6901:6901 -p "+ free_port +":22 -v=/opt/data:/data "+ tag_name +" /start")
os.system("docker run -d=true --name="+ name +" --restart=always -p "+ vnc_free_port +":6901 -p "+ free_port +":22 -v=/opt/data:/data "+ tag_name +" /start > /dev/null")
result = {"ssh_port":free_port,"vnc_port":vnc_free_port,"id": name}
print(result)
# -------------------------------------------------------------------------------------------------------------------
# ------------------------------------------ Get free TCP port ------------------------------------------------------

View File

@@ -1,2 +1,3 @@
docker
click
docker
pymake

View File

@@ -4,7 +4,6 @@ import (
"github.com/gin-gonic/gin"
"net/http"
"fmt"
docker "git.sr.ht/~akilan1999/p2p-rendering-computation/server/docker"
)
func Server() {