From 8849d762420bd0af966122fe15758cce9791a3dc Mon Sep 17 00:00:00 2001 From: sendssf <2336526392@qq.com> Date: Sun, 16 Apr 2023 23:28:42 +0800 Subject: [PATCH 1/3] merge --- installer/Installer/Model.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/Installer/Model.cs b/installer/Installer/Model.cs index 0a52066..35ab9e0 100644 --- a/installer/Installer/Model.cs +++ b/installer/Installer/Model.cs @@ -445,8 +445,8 @@ namespace Downloader .Build(); // 创建 CosXmlConfig 对象 // 永久密钥访问凭证 - string secretId = "***"; //"云 API 密钥 SecretId"; - string secretKey = "***"; //"云 API 密钥 SecretKey"; + string secretId = "AKIDvhEVXN4cv0ugIlFYiniV6Wk1McfkplYA"; //"云 API 密钥 SecretId"; + string secretKey = "YyGLGCJG4f5VsEUddnz9JSRPSSK8sYBo"; //"云 API 密钥 SecretKey"; long durationSecond = 1000; // 每次请求签名有效时长,单位为秒 From 0781c90e49070cb33c02c1cc4f7967c1c09114f1 Mon Sep 17 00:00:00 2001 From: sendssf <2336526392@qq.com> Date: Mon, 17 Apr 2023 21:06:25 +0800 Subject: [PATCH 2/3] Chore: Add ENTRYPOINT to dockerfile --- dependency/Dockerfile/Dockerfile_cpp | 8 ++-- dependency/py/upload.py | 68 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 dependency/py/upload.py diff --git a/dependency/Dockerfile/Dockerfile_cpp b/dependency/Dockerfile/Dockerfile_cpp index a4f178a..a9d9b61 100644 --- a/dependency/Dockerfile/Dockerfile_cpp +++ b/dependency/Dockerfile/Dockerfile_cpp @@ -39,6 +39,8 @@ COPY ./CAPI /usr/local/PlayerCode/CAPI COPY ./dependency /usr/local/PlayerCode/dependency WORKDIR /usr/local/PlayerCode/dependency/proto RUN ./cpp_output.sh -WORKDIR /usr/local/PlayerCode/CAPI/cpp -RUN cmake ./CMakeLists.txt -RUN make +WORKDIR /usr/local/PlayerCode/dependency/shell +ENTRYPOINT ["bash","./compile.sh"] +#WORKDIR /usr/local/PlayerCode/CAPI/cpp +#RUN cmake ./CMakeLists.txt +#RUN make diff --git a/dependency/py/upload.py b/dependency/py/upload.py new file mode 100644 index 0000000..8173378 --- /dev/null +++ b/dependency/py/upload.py @@ -0,0 +1,68 @@ +# -*- coding=utf-8 +from qcloud_cos import CosConfig +from qcloud_cos import CosS3Client +import sys +import os +import logging +import getopt +import hashlib +import json + +def upload(path): + response = client.upload_file( + Bucket='thuai6-1314234950', + LocalFilePath= path, + Key = "TEST", + PartSize=1, + MAXThread=10, + EnableMD5=False + ) + return response + +def generateHashFile(): + file = targetfolder + hashlist={} + for root, dirs, files in os.walk(file): + for file in files: + path = os.path.join(root, file) + with open(path, 'rb') as f: + data = f.read() + hashlist[path.replace(file)]=hashlib.md5(data) + res = json.dumps(hashlist) + + +try: + opts,args = getopt.getopt(sys.argv[1:],"t:i:k:") +except getopt.GetoptError: + print("upload.py -d -i -k") + +sKey="" +sId="" +targetfolder="" +for opt,arg in opts: + if opt == "-t": + targetfolder = arg + elif opt == "-i": + sId = arg + elif opt == "-k": + sKey = arg + +print("skey:"+sKey+" sid:"+sId+" tar:"+targetfolder) +# 正常情况日志级别使用 INFO,需要定位时可以修改为 DEBUG,此时 SDK 会打印和服务端的通信信息 +logging.basicConfig(level=logging.INFO, stream=sys.stdout) + +# 1. 设置用户属性, 包括 secret_id, secret_key, region等。Appid 已在 CosConfig 中移除,请在参数 Bucket 中带上 Appid。Bucket 由 BucketName-Appid 组成 +secret_id = sId # 用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140 +secret_key = sKey # 用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140 +region = 'ap-beijing' # 替换为用户的 region,已创建桶归属的 region 可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket + # COS 支持的所有 region 列表参见 https://cloud.tencent.com/document/product/436/6224 +token = None # 如果使用永久密钥不需要填入 token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见 https://cloud.tencent.com/document/product/436/14048 +scheme = 'https' # 指定使用 http/https 协议来访问 COS,默认为 https,可不填 + +config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme) +client = CosS3Client(config) + +generateHashFile() + +#### 高级上传接口(推荐) +# 根据文件大小自动选择简单上传或分块上传,分块上传具备断点续传功能。 From 8a80faa7e56fbcf8ad3fc86f227a4c6d87b5c70c Mon Sep 17 00:00:00 2001 From: sendssf <2336526392@qq.com> Date: Mon, 17 Apr 2023 21:27:03 +0800 Subject: [PATCH 3/3] Chore: Add ENTRYPOINT for dockerfile --- CAPI/cpp/API/src/AI.cpp | 6 +++--- dependency/Dockerfile/Dockerfile_cpp | 3 ++- dependency/shell/compile.sh | 23 +++++++++++++++++++++++ installer/Installer/Model.cs | 4 ++-- 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 dependency/shell/compile.sh diff --git a/CAPI/cpp/API/src/AI.cpp b/CAPI/cpp/API/src/AI.cpp index 5843e64..0caf5ff 100644 --- a/CAPI/cpp/API/src/AI.cpp +++ b/CAPI/cpp/API/src/AI.cpp @@ -17,7 +17,7 @@ extern const std::array studentType = { extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::Assassin; -//可以在AI.cpp内部声明变量与函数 +// 可以在AI.cpp内部声明变量与函数 void AI::play(IStudentAPI& api) { @@ -38,8 +38,8 @@ void AI::play(IStudentAPI& api) { // 玩家3执行操作 } - //当然可以写成if (this->playerID == 2||this->playerID == 3)之类的操作 - // 公共操作 + // 当然可以写成if (this->playerID == 2||this->playerID == 3)之类的操作 + // 公共操作 } void AI::play(ITrickerAPI& api) diff --git a/dependency/Dockerfile/Dockerfile_cpp b/dependency/Dockerfile/Dockerfile_cpp index a9d9b61..4819444 100644 --- a/dependency/Dockerfile/Dockerfile_cpp +++ b/dependency/Dockerfile/Dockerfile_cpp @@ -39,7 +39,8 @@ COPY ./CAPI /usr/local/PlayerCode/CAPI COPY ./dependency /usr/local/PlayerCode/dependency WORKDIR /usr/local/PlayerCode/dependency/proto RUN ./cpp_output.sh -WORKDIR /usr/local/PlayerCode/dependency/shell +WORKDIR /usr/local/PlayerCode/CAPI/cpp +COPY ./dependency/shell/compile.sh . ENTRYPOINT ["bash","./compile.sh"] #WORKDIR /usr/local/PlayerCode/CAPI/cpp #RUN cmake ./CMakeLists.txt diff --git a/dependency/shell/compile.sh b/dependency/shell/compile.sh new file mode 100644 index 0000000..2ed42a4 --- /dev/null +++ b/dependency/shell/compile.sh @@ -0,0 +1,23 @@ +#! /bin/bash +# WORKDIR /usr/local/PlayerCode/CAPI/cpp +i=1 +flag=1 +bind=/usr/local/mnt +while (( $i <= 4 )) +do + cp -f $bind/player$i.cpp ./API/src + mv ./API/src/player$i.cpp ./API/src/AI.cpp + cmake ./CMakeLists.txt && make >compile_log$i.txt 2>&1 + mv ./capi $bind/capi$i # executable file + if [ $? -ne 0 ]; then + flag=0 + fi + mv ./compile_log$i.txt $bind/compile_log$i.txt + let "i++" +done +# HTML request to update status. +if [ $flag -eq 1 ]; then + curl $URL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"compile_status":"compiled"}' > ../mnt/curl_log.txt +else + curl $URL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"compile_status":"failed"}' > ../mnt/curl_log.txt +fi \ No newline at end of file diff --git a/installer/Installer/Model.cs b/installer/Installer/Model.cs index 319cd83..da6488c 100644 --- a/installer/Installer/Model.cs +++ b/installer/Installer/Model.cs @@ -447,8 +447,8 @@ namespace Downloader .Build(); // 创建 CosXmlConfig 对象 // 永久密钥访问凭证 - string secretId = "AKIDvhEVXN4cv0ugIlFYiniV6Wk1McfkplYA"; //"云 API 密钥 SecretId"; - string secretKey = "YyGLGCJG4f5VsEUddnz9JSRPSSK8sYBo"; //"云 API 密钥 SecretKey"; + string secretId = "***"; //"云 API 密钥 SecretId"; + string secretKey = "***"; //"云 API 密钥 SecretKey"; long durationSecond = 1000; // 每次请求签名有效时长,单位为秒