Browse Source

Merge pull request #372 from sendssf/dev

Chore: Add runner Dockerfile and add some shells
tags/0.1.0
Changli Tang GitHub 2 years ago
parent
commit
d72c7ac6a6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 162 additions and 40 deletions
  1. +28
    -0
      .github/workflows/docker.yml
  2. +1
    -1
      CAPI/shell/GeneratePythonProto.sh
  3. +15
    -0
      dependency/Dockerfile/Dockerfile_base
  4. +7
    -37
      dependency/Dockerfile/Dockerfile_cpp
  5. +19
    -0
      dependency/Dockerfile/Dockerfile_run
  6. +5
    -0
      dependency/Dockerfile/README.md
  7. +2
    -2
      dependency/shell/compile.sh
  8. +22
    -0
      dependency/shell/docker.sh
  9. +62
    -0
      dependency/shell/run.sh
  10. +1
    -0
      installer/Installer/Model.cs

+ 28
- 0
.github/workflows/docker.yml View File

@@ -0,0 +1,28 @@
name: "docker"
on:
push:
branches: [main,dev]

jobs:
upload_docker_images:
runs-on: ubuntu-latest
steps:
-uses: actions/checkout@v3
- name: Log in to DockerHub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Build base docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/thuai6_base:base -f ./dependency/Dockerfile/Dockerfile_base .
- name: Push base image to DockerHub
run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai6_base:base


- name: Build cpp_compile docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/thuai6_cpp:latest -f ./dependency/Dockerfile/Dockerfile_cpp .
- name: Push cpp_compile image to DockerHub
run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai6_cpp:latest

- name: Build run docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/thuai6_run:latest -f ./dependency/Dockerfile/Dockerfile_run .
- name: Push run image to DockerHub
run: docker push ${{ secrets.DOCKER_USERNAME }}/thuai6_run:latest

+ 1
- 1
CAPI/shell/GeneratePythonProto.sh View File

@@ -2,7 +2,7 @@

python -m pip install -r ./CAPI/python/requirements.txt

mkdir -p proto
mkdir -p ./CAPI/python/proto

python -m grpc_tools.protoc -I./CAPI/proto/ --python_out=./CAPI/python/proto --pyi_out=./CAPI/python/proto MessageType.proto
python -m grpc_tools.protoc -I./CAPI/proto/ --python_out=./CAPI/python/proto --pyi_out=./CAPI/python/proto Message2Clients.proto


+ 15
- 0
dependency/Dockerfile/Dockerfile_base View File

@@ -0,0 +1,15 @@
FROM python:3.9.16-bullseye
MAINTAINER eesast.com
WORKDIR /usr/local
RUN apt-get update && apt-get install --no-install-recommends -y gcc g++ make wget ca-certificates cmake autoconf automake libtool curl unzip git
RUN git clone -b v1.46.3 --depth 1 --shallow-submodules https://gitee.com/mirrors/grpc.git && wget -P . https://cloud.tsinghua.edu.cn/f/1f2713efd9e44255abd6/?dl=1 && mv 'index.html?dl=1' third_party.tar.gz
WORKDIR /usr/local/grpc
RUN rm -rf third_party && mv ../third_party.tar.gz . && tar -zxvf third_party.tar.gz && mkdir -p cmake/build
WORKDIR /usr/local/grpc/cmake/build
RUN cmake -DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
../.. && make -j$(nproc) && make install
WORKDIR /usr/local
RUN git clone https://gitee.com/mirrors/protobuf_source.git ./protobuf
WORKDIR /usr/local/protobuf
RUN git checkout 3.20.x && ./autogen.sh && ./configure && make -j$(nproc) && make install && ldconfig

+ 7
- 37
dependency/Dockerfile/Dockerfile_cpp View File

@@ -1,47 +1,17 @@
FROM ubuntu:22.04
#FROM ubuntu:18.04
FROM wangsk21/thuai6:base
MAINTAINER eesast.com
WORKDIR /usr/local
RUN mkdir /usr/local/PlayerCode
#安装主要工具
RUN apt-get update && apt-get install --no-install-recommends -y gcc g++ make wget ca-certificates cmake autoconf automake libtool curl unzip git
#安装grpc
RUN git clone -b v1.46.3 --depth 1 --shallow-submodules https://gitee.com/mirrors/grpc.git
RUN wget -P . https://cloud.tsinghua.edu.cn/f/1f2713efd9e44255abd6/?dl=1
RUN mv 'index.html?dl=1' third_party.tar.gz
WORKDIR /usr/local/grpc
RUN rm -rf third_party
RUN mv ../third_party.tar.gz .
RUN tar -zxvf third_party.tar.gz
RUN mkdir -p cmake/build
WORKDIR /usr/local/grpc/cmake/build
RUN cmake -DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
../..
RUN make -j$(nproc)
RUN make install

#安装protobuf
WORKDIR /usr/local
RUN git clone https://gitee.com/mirrors/protobuf_source.git ./protobuf
WORKDIR /usr/local/protobuf
RUN git checkout 3.20.x
RUN ./autogen.sh
RUN ./configure
RUN make -j$(nproc)
RUN make install
RUN ldconfig
#RUN git submodule update --init --recursive
#RUN cmake .
#RUN cmake --build . --parallel 10
#RUN make install

COPY ./CAPI /usr/local/PlayerCode/CAPI
COPY ./dependency /usr/local/PlayerCode/dependency
COPY ./CAPI/cpp /usr/local/PlayerCode/CAPI/cpp
COPY ./dependency/proto /usr/local/PlayerCode/dependency/proto
WORKDIR /usr/local/PlayerCode/dependency/proto
RUN ./cpp_output.sh
WORKDIR /usr/local/PlayerCode/CAPI/cpp
COPY ./dependency/shell/compile.sh .
ENTRYPOINT ["bash","./compile.sh"]
COPY ./dependency/shell/docker.sh /usr/local/
WORKDIR /usr/local
ENTRYPOINT ["bash","./docker.sh"]
#WORKDIR /usr/local/PlayerCode/CAPI/cpp
#RUN cmake ./CMakeLists.txt
#RUN make

+ 19
- 0
dependency/Dockerfile/Dockerfile_run View File

@@ -0,0 +1,19 @@
FROM wangsk21/thuai6:base
WORKDIR /usr/local
RUN mkdir /usr/local/team1 && mkdir /usr/local/team2 && mkdir /usr/local/playback
COPY ./dependency/shell/run.sh .
#COPY ./dependency/shell/runcpp.sh .
COPY ./dependency/shell/docker.sh .

COPY ./CAPI/python /usr/local/PlayerCode/CAPI/python
COPY ./dependency/proto /usr/local/PlayerCode/dependency/proto
WORKDIR /usr/local/PlayerCode/CAPI/python
RUN ./generate_proto.sh

WORKDIR /usr/local
RUN wget -P . https://cloud.tsinghua.edu.cn/f/e48940314a6d4cdb8bd0/?dl=1
RUN mv 'index.html?dl=1' Server.tar.gz
RUN tar -zxvf Server.tar.gz

ENV PARAMS = ""
ENTRYPOINT [ "bash","./docker.sh ${PARAMS}" ]

+ 5
- 0
dependency/Dockerfile/README.md View File

@@ -2,3 +2,8 @@

用于存放Docker配置文件Dockerfile

- 调用runner镜像的方法:
```shell
docker run -e PARAMS=-c 镜像名 #编译C++代码
docker run -e PARAMS=-r 镜像名 #运行程序(支持一个队既提交python又提交cpp)
```

+ 2
- 2
dependency/shell/compile.sh View File

@@ -17,7 +17,7 @@ do
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
curl $URL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"compile_status":"compiled"}' > $bind/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
curl $URL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"compile_status":"failed"}' > $bind/curl_log.txt
fi

+ 22
- 0
dependency/shell/docker.sh View File

@@ -0,0 +1,22 @@

while getopts ':cr' 'OPT'; do
case ${OPT} in
'c') #传入cpp文件并编译
#echo v"$VERSION"
cd /usr/local/PlayerCode/CAPI/cpp
./compile.sh
exit
;;
'r') #运行
#NO_PROMPT='true'
cd /usr/local
./run.sh
;;
'l')

;;
'i')
INSTALL_VERSION="${OPTARG}"
;;
esac
done

+ 62
- 0
dependency/shell/run.sh View File

@@ -0,0 +1,62 @@
#!/usr/local

nice -10 ./Server/Server --port 8888 --studentCount 4 --trickerCount 1 --gameTimeInSecond 600
sleep 5
cd /usr/local/team1
if [-f "./capi1"];then
nice -0 ./capi1 -I 127.0.0.1 -P 8888 -p 0
fi
if [-f "./capi2"];then
nice -0 ./capi2 -I 127.0.0.1 -P 8888 -p 1
fi
if [-f "./capi3"];then
nice -0 ./capi3 -I 127.0.0.1 -P 8888 -p 2
fi
if [-f "./capi4"];then
nice -0 ./capi4 -I 127.0.0.1 -P 8888 -p 3
if [-f "./capi5"];then
nice -0 ./capi5 -I 127.0.0.1 -P 8888 -p 4
if [-f "./python/player1.py"];then
nice -0 python3 ./python/player1.py -I 127.0.0.1 -P 8888 -p 0
fi
if [-f "./python/player2.py"];then
nice -0 python3 ./python/player2.py -I 127.0.0.1 -P 8888 -p 1
fi
if [-f "./python/player3.py"];then
nice -0 python3 ./python/player3.py -I 127.0.0.1 -P 8888 -p 2
fi
if [-f "./python/player4.py"];then
nice -0 python3 ./python/player4.py -I 127.0.0.1 -P 8888 -p 3
fi
if [-f "./python/player5.py"];then
nice -0 python3 ./python/player5.py -I 127.0.0.1 -P 8888 -p 4
fi
cd /usr/local/team2
if [-f "./capi1"];then
nice -0 ./capi1 -I 127.0.0.1 -P 8888 -p 0
fi
if [-f "./capi2"];then
nice -0 ./capi2 -I 127.0.0.1 -P 8888 -p 1
fi
if [-f "./capi3"];then
nice -0 ./capi3 -I 127.0.0.1 -P 8888 -p 2
fi
if [-f "./capi4"];then
nice -0 ./capi4 -I 127.0.0.1 -P 8888 -p 3
if [-f "./capi5"];then
nice -0 ./capi5 -I 127.0.0.1 -P 8888 -p 4
if [-f "./python/player1.py"];then
nice -0 python3 ./python/player1.py -I 127.0.0.1 -P 8888 -p 0
fi
if [-f "./python/player2.py"];then
nice -0 python3 ./python/player2.py -I 127.0.0.1 -P 8888 -p 1
fi
if [-f "./python/player3.py"];then
nice -0 python3 ./python/player3.py -I 127.0.0.1 -P 8888 -p 2
fi
if [-f "./python/player4.py"];then
nice -0 python3 ./python/player4.py -I 127.0.0.1 -P 8888 -p 3
fi
if [-f "./python/player5.py"];then
nice -0 python3 ./python/player5.py -I 127.0.0.1 -P 8888 -p 4
fi

+ 1
- 0
installer/Installer/Model.cs View File

@@ -506,6 +506,7 @@ namespace Downloader
string secretId = "***"; //"云 API 密钥 SecretId";
string secretKey = "***"; //"云 API 密钥 SecretKey";


long durationSecond = 1000; // 每次请求签名有效时长,单位为秒
QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider(
secretId, secretKey, durationSecond


Loading…
Cancel
Save