Skip to content

Commit

Permalink
Merge pull request #135 from pur1fying/docker_support
Browse files Browse the repository at this point in the history
Docker support
  • Loading branch information
pur1fying committed Aug 19, 2024
2 parents ca12e26 + 0c9c9a0 commit 9784dfd
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
!window.spec
!i18n.pro
!requirements-i18n.txt
!requirements-linux.txt
!dockerfile
!docker-compose.yaml
!entrypoint.sh
src/explore_task_data/__pycache__/normal_task_11.cpython-39.pyc
*.pyc
*.xml
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ GUI预览图:
- **推送的json格式为:**
`{"title":"Baas Error","desp":"error..."}`

### Docker 使用方法
> 本项目拟支持Docker部署,但目前Docker部署仍无法正常运行,如有解决方案,请提交PR
1. 确保你的电脑中存在Docker, 先clone本项目到本地
2. 进入项目目录,构建镜像:
```shell
docker build -t baas:v1.0 .
```
3. 运行容器方法一:使用docker run
```shell
docker run -it -v "$PWD:/app" -p 5900:5900 baas:v1.0
```
4. 运行容器方法二:使用docker-compose
```shell
docker-compose up -d
```
5. 可以通过VNC Viewer连接到GUI画面,端口默认为5900
6. 同时如果你的系统支持显示,可以通过修改`entrypoint.sh`中指示的内容,直接在本地运行。

## 如何上报bug How to Report Bugs
在提问题之前至少花费 5 分钟来思考和准备,才会有人花费他的 5 分钟来帮助你。

Expand Down
11 changes: 9 additions & 2 deletions core/notification.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
from win11toast import notify as _notify

# Check if the current OS is Windows
try:
from win10toast import ToastNotifier as _notify
except ImportError:
_notify = None
app_id = 'BlueArchiveAutoScript.exe'
icon_path = '/gui/assets/logo.png'

Expand All @@ -15,6 +18,10 @@ def get_root_path():

def notify(title=None, body=None):
root_path = get_root_path()
if _notify is None:
print(f"{title}: {body}")
return

_notify(
title=title,
body=body,
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'
services:
baas_main:
image: baas:v1.0
tty: true
ports:
# You can change the first port number to any other port number.
# This is for VNC Viewer to access.
- "5900:5900"
restart: always
container_name: blue_archive_auto_script
volumes:
- ./:/app
37 changes: 37 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use the official Debian image as the base
FROM hub.atomgit.com/amd64/debian:latest

# Remove the original mirror
RUN rm -rf /etc/apt/sources.list.d && apt-get clean && apt-get update --fix-missing

# Alter the source to tsinghua mirror
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware\ndeb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware\ndeb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware\ndeb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware" > /etc/apt/sources.list

# Install Git Env
RUN apt-get update && apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget libglib2.0-dev git

# Install GL Runtime
RUN apt-get install -y libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0 libxcb-shape0 libxcb-xinerama0 libxcb-xkb1 libsm6 libxkbcommon-x11-0 libdbus-1-3

# Hard to Install due to the network. if you can't pass, please comment it.
# RUN apt-get install -y libqt5pdf5 libtiff5-dev --fix-missing

# Install Python Environment
RUN wget https://mirrors.aliyun.com/python-release/source/Python-3.9.18.tar.xz
RUN tar -xvJf Python-3.9.18.tar.xz
RUN cd Python-3.9.18 && ./configure --enable-optimizations
RUN cd Python-3.9.18 && make -j $(nproc) && make altinstall
RUN rm -rf Python-3.9.18.tar.xz Python-3.9.18


# Set the working directory in the container
WORKDIR /app

# Copy the requirements file to the container
COPY requirements.txt .

# Copy the rest of the application code to the container
COPY . .

# Set the command to run the application
CMD ["bash", "entrypoint.sh"]
120 changes: 120 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash

# For Debug
# export QT_DEBUG_PLUGINS=1

# Check the version
GIT_HOME="/usr/bin/git" # 修改为你的 git 可执行文件路径
REPO_URL_HTTP="https://gitee.com/pur1fy/blue_archive_auto_script.git" # 修改为你的仓库地址

# 设置虚拟环境的名称
VENV_NAME="env"

# 检查虚拟环境是否已经存在
if [ -d "$VENV_NAME" ]; then
echo "[INFO] Virtual environment '$VENV_NAME' already exists."
else
# 创建虚拟环境
echo "[INFO] Creating virtual environment '$VENV_NAME'..."
python3.9 -m venv "$VENV_NAME"

# 检查虚拟环境是否成功创建
if [ ! -d "$VENV_NAME" ]; then
echo "[ERROR] Failed to create the virtual environment."
exit 1
fi
fi

# 激活虚拟环境
echo "[INFO] Activating virtual environment '$VENV_NAME'..."
source "$VENV_NAME/bin/activate"

# 确认虚拟环境已激活
if [ "$VIRTUAL_ENV" != "" ]; then
echo "[INFO] Virtual environment '$VENV_NAME' activated successfully."
else
echo "[ERROR] Failed to activate the virtual environment."
exit 1
fi


echo "+--------------------------------+"
echo "| UPDATE BAAS |"
echo "+--------------------------------+"

remote_sha=$($GIT_HOME ls-remote --heads origin refs/heads/master | awk '{print $1}')
local_sha=$($GIT_HOME rev-parse HEAD)

echo "[INFO] Remote SHA: $remote_sha"
echo "[INFO] Local SHA: $local_sha"

if [ "$local_sha" = "$remote_sha" ] && [ -z "$($GIT_HOME diff)" ]; then
echo "[INFO] No updates available"
else
echo "[INFO] Pulling updates from the remote repository..."
$GIT_HOME reset --hard HEAD
$GIT_HOME pull "$REPO_URL_HTTP"

updated_local_sha=$($GIT_HOME rev-parse HEAD)

echo "[INFO] Updated SHA: $updated_local_sha"
if [ "$updated_local_sha" = "$remote_sha" ]; then
echo "[INFO] Update success"
else
echo "[ERROR] Failed to update the source code, please check your network or for conflicting files"
fi
fi

ATX_APK_URL="https://gitee.com/pur1fy/blue_archive_auto_script_assets/raw/master/ATX.apk"

APK_PATH="/app/src/atx_app/ATX.apk"

echo "[INFO] Checking atx-agent..."

# Check if ATX.apk exists
if [ ! -f "$APK_PATH" ]; then
echo "[INFO] Downloading atx-agent..."
# Download ATX.apk
wget -O "$APK_PATH" "$ATX_APK_URL"
else
echo "[INFO] Atx-agent already downloaded"
fi


# Install the env
echo "[INFO] Check and Update the runtime environment..."
pip3.9 install -r requirements-linux.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# Start the app
echo "[INFO] Starting the app..."

# If you have display, it's ok to comment the first block
# and uncomment the second block.

#########################################################
apt-get install -y xvfb x11vnc procps
xvfb-run python3.9 window.py &

# Wait until the xvfb is started
sleep 5

xvfb_info=$(ps -aux | grep '[X]vfb')
# Get Xvfb Info From proc


# Abstract ":99" and "-auth xxxxx"
display=$(echo "$xvfb_info" | grep -o ' :[0-9][0-9]')
auth=$(echo "$xvfb_info" | grep -oP '(?<=-auth )[^ ]+')

# Check the abstract status
if [ -n "$display" ] && [ -n "$auth" ]; then
# build and run x11vnc command
x11vnc_cmd="x11vnc -display $display -auth $auth"
echo "Running command: $x11vnc_cmd"
$x11vnc_cmd
else
echo "Failed to extract display or auth information."
fi
#########################################################
# xvfb-run python3.9 window.py #
#########################################################
13 changes: 13 additions & 0 deletions requirements-linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
lmdb
PyQt5
numpy
flask
cnocr
imgaug
onnxruntime
adbutils <= 2.2.1
uiautomator2
opencv-python-headless
PyQt-Fluent-Widgets

paddlepaddle

0 comments on commit 9784dfd

Please sign in to comment.