...
 
Commits (2)
    https://gitcode.net/t1019256391/1024/-/commit/f652a87d3bbc9766ce0e6feed665377cb473de93 tag rename 2022-10-30T13:14:08+00:00 635677437d755007c09848d3 635677437d755007c09848d3@devide https://gitcode.net/t1019256391/1024/-/commit/42338d6866ae2ce3af3471e2fc685495ef408a48 update 2022-10-30T13:17:09+00:00 635677437d755007c09848d3 635677437d755007c09848d3@devide
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
- 未支持标准输入 - 未支持标准输入
- stdout和stderr分开等等 - stdout和stderr分开等等
![image text](https://gitcode.net/t1019256391/1024/-/raw/main/static/pic1.jpg)
# 如何添加想要支持的语言 # 如何添加想要支持的语言
非常简单,仅需2步 非常简单,仅需2步
1.`config`目录下创建该语言的Dockerfile文件以及example文件 1.`config`目录下创建该语言的Dockerfile文件以及example文件
......
...@@ -18,7 +18,7 @@ EOF ...@@ -18,7 +18,7 @@ EOF
fi fi
# 其他镜像在python中异步创建 # 其他镜像在python中异步创建
docker build -f config/python/Dockerfile -t python . docker build -f config/python/Dockerfile -t webcode:python-1.0 .
pip install -r requirements -i https://mirrors.aliyun.com/pypi/simple/ pip install -r requirements -i https://mirrors.aliyun.com/pypi/simple/
python router.py python router.py
...@@ -2,7 +2,7 @@ import logging ...@@ -2,7 +2,7 @@ import logging
import os.path import os.path
from typing import Dict from typing import Dict
TAG_STR = "webcode_{}:1.0" TAG_STR = "webcode:{}-1.0"
DOCKER_CONFIG_DIR = "config/{}" DOCKER_CONFIG_DIR = "config/{}"
from docker import APIClient from docker import APIClient
...@@ -38,7 +38,7 @@ class Language: ...@@ -38,7 +38,7 @@ class Language:
def build_image(self): def build_image(self):
try: try:
generator = low_level_client.build(path=DOCKER_CONFIG_DIR.format(self.name), generator = low_level_client.build(path=DOCKER_CONFIG_DIR.format(self.name),
tag=self.name, tag=TAG_STR.format(self.name),
rm=True, decode=True) rm=True, decode=True)
while True: while True:
# 打印日志,防止build太久看不到进度条 # 打印日志,防止build太久看不到进度条
...@@ -49,7 +49,8 @@ class Language: ...@@ -49,7 +49,8 @@ class Language:
break break
else: else:
continue continue
print("正在创建镜像", self.name, output.get("stream", ""), output.get("status", ""), output.get("progress", "")) print("正在创建镜像", self.name, output.get("stream", ""), output.get("status", ""),
output.get("progress", ""))
except StopIteration: except StopIteration:
print("Docker image build complete.") print("Docker image build complete.")
return True return True
......
import docker import docker
import os
import json
import logging
from func_timeout import func_set_timeout, exceptions from func_timeout import func_set_timeout, exceptions
from docker.errors import ImageNotFound from docker.errors import ImageNotFound
import time
import threading
import common
from common import * from common import *
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -20,11 +13,11 @@ def get_and_set_image(name): ...@@ -20,11 +13,11 @@ def get_and_set_image(name):
if Languages[name].image: if Languages[name].image:
return Languages[name].image return Languages[name].image
try: try:
image = client.images.get(name) image = client.images.get(TAG_STR.format(name))
Languages[name].set_image(image) Languages[name].set_image(image)
return image return image
except ImageNotFound: except ImageNotFound:
logger.error("找不到%s的镜像", name) pass
return None return None
......