Skip to content
Permalink
Browse files

feat: update to use instantbox-images

  • Loading branch information...
wei authored and import-yuefeng committed Mar 2, 2019
1 parent aa28d75 commit 1e52c0bd056f1e2389e9b519a0bbab041400cef5
Showing with 21 additions and 146 deletions.
  1. +2 −2 Dockerfile
  2. +5 −11 api/createContainer.py
  3. +14 −133 inspire.py
@@ -3,7 +3,7 @@ FROM python:3-alpine AS builder
WORKDIR /usr/src/app

COPY requirement.txt ./
RUN pip3 install -q --no-cache-dir -r requirement.txt -t ./ -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip3 install -q --no-cache-dir -r requirement.txt -t ./
COPY . .
ADD https://raw.githubusercontent.com/instantbox/instantbox-images/master/manifest.json .

@@ -28,4 +28,4 @@ ARG BUILD_DATE
ARG VCS_REF
LABEL \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-ref=$VCS_REF
org.label-schema.vcs-ref=$VCS_REF
@@ -15,24 +15,17 @@ def is_create_container(self,
open_port=None,
rand_port=None) -> bool:

shell = "bash"

if "alpine" in os_name:
shell = "sh"

if open_port is None:
port_dict = {str(web_shell_port) + '/tcp': str(web_shell_port)}
port_dict = {'1588/tcp': str(web_shell_port)}
else:
port_dict = {
str(web_shell_port) + '/tcp': str(web_shell_port),
'1588/tcp': str(web_shell_port),
str(open_port) + '/tcp': str(rand_port)
}

try:

self.client.containers.run(
image="catone/inspire:%s" % os_name,
command="ttyd_linux.x86_64 -p %s %s" % (web_shell_port, shell),
image=os_name,
cpu_period=100000,
cpu_quota=int("%s0000" % cpu),
mem_limit="%sm" % mem,
@@ -50,4 +43,5 @@ def is_create_container(self,

if __name__ == '__main__':
test = CreateContainer()
test.is_create_container("512", 1, 32233, "kldasf", "ubuntu16_04")
test.is_create_container("512", 1, 32233, "test_container",
"instantbox/ubuntu:latest")
@@ -24,135 +24,16 @@

SERVERURL = os.environ.get('SERVERURL')

OS_SWITCH = {
"10000": "ubuntu12_04",
"10001": "ubuntu14_04",
"10002": "ubuntu16_04",
"10003": "ubuntu18_04",
"10004": "ubuntuLatest",
"20000": "centos6_10",
"20001": "centos7",
"20002": "centosLatest",
"30000": "2018.12.01",
"30001": "archLatest",
"40000": "debian9_6_0",
"40001": "debianLatest",
"50000": "fedora28",
"50001": "fedora29",
"50002": "fedoraLatest",
"60000": "alpineLatest"
}

# yapf: disable
OS_LIST = [
{
"label": "Ubuntu",
"value": "Ubuntu",
"logoUrl": "https://cdn.jsdelivr.net/gh/instantbox/instantbox-images/icon/ubuntu.png",
"subList": [
{
"label": "12.04",
"osCode": "10000"
},
{
"label": "14.04",
"osCode": "10001"
},
{
"label": "16.04",
"osCode": "10002"
},
{
"label": "18.04",
"osCode": "10003"
},
{
"label": "latest",
"osCode": "10004"
}
]
},
{
"label": "CentOS",
"value": "CentOS",
"logoUrl": "https://cdn.jsdelivr.net/gh/instantbox/instantbox-images/icon/centos.png",
"subList": [
{
"label": "6.10",
"osCode": "20000"
},
{
"label": "7",
"osCode": "20001"
},
{
"label": "latest",
"osCode": "20002"
}
]
},
{
"label": "Arch Linux",
"value": "Arch Linux",
"logoUrl": "https://cdn.jsdelivr.net/gh/instantbox/instantbox-images/icon/arch.png",
"subList": [
{
"label": "2018.12.01",
"osCode": "30000"
},
{
"label": "latest",
"osCode": "30001"
}
]
},
{
"label": "Debian",
"value": "Debian",
"logoUrl": "https://cdn.jsdelivr.net/gh/instantbox/instantbox-images/icon/debian.png",
"subList": [
{
"label": "9.6.0",
"osCode": "40000"
},
{
"label": "latest",
"osCode": "40001"
}
]
},
{
"label": "Fedora",
"value": "Fedora",
"logoUrl": "https://cdn.jsdelivr.net/gh/instantbox/instantbox-images/icon/fedora.png",
"subList": [
{
"label": "28",
"osCode": "50000"
},
{
"label": "29",
"osCode": "50001"
},
{
"label": "latest",
"osCode": "50002"
}
]
},
{
"label": "Alpine",
"value": "Alpine",
"logoUrl": "https://cdn.jsdelivr.net/gh/instantbox/instantbox-images/icon/alpine.png",
"subList": [
{
"label": "latest",
"osCode": "60000"
}
]
}
]
# yapf: enable
OS_LIST = None
with open("manifest.json", "r") as os_manifest:
OS_LIST = json.load(os_manifest)
if OS_LIST is None:
raise Exception('Could not load manifest.json')

AVAILABLE_OS = []
for os in OS_LIST:
for ver in os['subList']:
AVAILABLE_OS.append(ver['osCode'])


def randPort():
@@ -249,7 +130,7 @@ def getOS():
openPort = ''

try:
os_info = request.args.get("os")
os_name = request.args.get("os")
except Exception:
response = Response(
json.dumps({
@@ -264,7 +145,7 @@ def getOS():
os_port = request.args.get("port")
os_timeout = request.args.get("timeout")
except Exception:
if os_info not in OS_SWITCH:
if os_name not in AVAILABLE_OS:
response = Response(
json.dumps({
"message":
@@ -290,7 +171,7 @@ def getOS():
cpu=os_cpu,
web_shell_port=webShellPort,
container_name=rand_string,
os_name=OS_SWITCH[os_info],
os_name=os_name,
)

else:
@@ -300,7 +181,7 @@ def getOS():
cpu=os_cpu,
web_shell_port=webShellPort,
container_name=rand_string,
os_name=OS_SWITCH[os_info],
os_name=os_name,
open_port=os_port,
rand_port=openPort)

0 comments on commit 1e52c0b

Please sign in to comment.
You can’t perform that action at this time.