Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f17e1ad075 | ||
![]() |
e5593790c0 | ||
![]() |
6e3d16458c | ||
![]() |
e01ba723d4 |
@ -17,7 +17,7 @@ RUN mkdir -p /app
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
RUN chmod -R 755 /app
|
||||
RUN ln -s /usr/bin/x86_64-linux-gnu-g++-9 /usr/bin/g++
|
||||
#RUN ln -s /usr/bin/x86_64-linux-gnu-g++-9 /usr/bin/g++
|
||||
RUN /usr/bin/bash /app/boundle.sh
|
||||
CMD ["bash"]
|
||||
#CMD ["/app/boundle.sh"]
|
@ -2,5 +2,5 @@ GAME_ID=2005
|
||||
PROJECT_NAME=wsproxy${GAME_ID}
|
||||
SRC_EXE_NAME=wsproxy${GAME_ID}
|
||||
SOURCE_PATH=third_party/wsproxy/server/wsproxy
|
||||
COMPILE_FLAGS="-DGAME_ID=${GAME_ID} -DMASTER_MODE=1 -DRELEASE=1 ."
|
||||
COMPILE_FLAGS="-DGAME_ID=${GAME_ID} -DMASTER_MODE=1 -DRELEASE=1 -DLIB_DIR=ubuntu20.04_g++-9 ."
|
||||
PRE_COMPILE_CMD=""
|
||||
|
95
deploy_docker.py
Normal file
95
deploy_docker.py
Normal file
@ -0,0 +1,95 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# in prod-salt-01 ,run start ,bound,remove docker ,get gz file from 10.10.2.3
|
||||
from fabric import Connection
|
||||
import os
|
||||
import pdb
|
||||
|
||||
|
||||
#todo :remove dock image && docker
|
||||
class DeployDocker:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.target = os.path.abspath('.').split('/')[-1].strip()
|
||||
self.image_name = f"{self.target.split('.')[0]}:{'.'.join(self.target.split('.')[1:])}"
|
||||
self.hostip = '10.10.2.3'
|
||||
self.remote_base_dir = "/tmp/miles"
|
||||
self.base_image = "k_ub20:v1"
|
||||
self.remote_dir = f"{self.remote_base_dir}/{self.target}"
|
||||
self.user = "root"
|
||||
self.docker_files = "Dockerfile"
|
||||
|
||||
def _check_result(self, data):
|
||||
if data.exited == 0:
|
||||
print(f"run {data.command} Success!\n{data.stdout.strip()}")
|
||||
return True
|
||||
else:
|
||||
print(
|
||||
f"run {data.command} Failed!\n{data.stdout.strip()}\t{data.stderr.strip()}"
|
||||
)
|
||||
return False
|
||||
|
||||
def _pre_start(self):
|
||||
sync_cmd = f"rsync -av ../{self.target} root@{self.hostip}:{self.remote_base_dir}"
|
||||
with Connection(host=self.hostip, user=self.user) as c:
|
||||
result = c.local(sync_cmd)
|
||||
assert result.exited == 0
|
||||
return True
|
||||
|
||||
def _build_docker(self):
|
||||
with Connection(host=self.hostip, user=self.user) as c:
|
||||
|
||||
cmd = f"cd {self.remote_dir} && docker build -t {self.image_name} -f {self.docker_files} ."
|
||||
result = c.run(cmd)
|
||||
assert result.exited == 0
|
||||
#self._check_result(result)
|
||||
return True
|
||||
|
||||
def _run_docker(self):
|
||||
with Connection(host=self.hostip, user=self.user) as c:
|
||||
#pdb.set_trace()
|
||||
run_docker = f"docker run -d {self.image_name} bash"
|
||||
result = c.run(run_docker)
|
||||
assert result.exited == 0
|
||||
find_docker = f"docker ps -a --filter ancestor={self.image_name}"
|
||||
result_find = c.run(find_docker).stdout.strip()
|
||||
container_id = result_find.split('\n')[-1].split(" ")[0]
|
||||
assert container_id
|
||||
get_gz_cmd = f"docker cp {container_id}:/app/target/app.tar.gz {self.remote_dir}/app.tar.gz"
|
||||
result_get_docker = c.run(get_gz_cmd)
|
||||
assert result_get_docker.exited == 0
|
||||
remote_file = f"{self.remote_dir}/app.tar.gz"
|
||||
local_file = f"./target/{self.target}.tar.gz"
|
||||
result_get_remote = c.local(
|
||||
f"rsync root@{self.hostip}:/{remote_file} {local_file}")
|
||||
assert result_get_remote.exited == 0
|
||||
self._clean()
|
||||
return True
|
||||
|
||||
def _clean(self):
|
||||
with Connection(host=self.hostip, user=self.user) as c:
|
||||
find_docker = f"docker ps -a --filter ancestor={self.image_name}"
|
||||
result_find = c.run(find_docker).stdout.strip()
|
||||
container_id = result_find.split('\n')[-1].split(" ")[0]
|
||||
assert container_id
|
||||
remove_docker = f"docker stop {container_id} && docker rm {container_id} &&docker image rm {self.image_name}"
|
||||
return True
|
||||
|
||||
def _start(self):
|
||||
if self._build_docker():
|
||||
if self._run_docker():
|
||||
return True
|
||||
else:
|
||||
self._clean()
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
def run(self):
|
||||
if self._pre_start():
|
||||
if self._start():
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
dd = DeployDocker()
|
||||
dd.run()
|
2
third_party/wsproxy
vendored
2
third_party/wsproxy
vendored
@ -1 +1 @@
|
||||
Subproject commit 58e7d6df7e3fa0a7134067d7c738b265f375636b
|
||||
Subproject commit 8504e406e5e16b70d8b52cb53c17d161426373a3
|
Loading…
x
Reference in New Issue
Block a user