Repository: LmeSzinc/AzurLaneAutoScript
Pull request: Improve docker deployment
- Migrate from anaconda3 to mambaforge:
  - mambaforge is minimal (138MB image vs 1GB image from anaconda3)
  - mamba is faster than conda in resolving dependecies -> faster build time
- Migrate to opencv-python-headless
  - `cv2` indeed requires `libgl1` to run but that's only for GUI tools of openCV (which we don't use)
  - Using `headless` dist will avoid this dependency problem
- Docker Compose
  - Now the setup is as simple as `docker compose up` or  `docker compose up -d` and the image will be build and run without the need of the `Docker-run.sh`
  - If we go through with this I'll edit the wiki before merge

Problem statement:
Better deployment experience on Linux
### Is your feature request related to a problem?

_No response_

### Describe the solution you'd like

Add a shell file to install Alas in one line of command. It's Alas server that need to be installed, emulator and AL are not included, Linux GUI is not required, Alas can be access via `127.0.0.1:22267`.

- Use docker.
- Generate a requirements file and specify all dependencies versions.
- Modify deploy settings in config/deploy.yaml such as `GitExecutable`, `PythonExecutable`, `AdbExecutable`; enable `UseOcrServer` and `StartOcrServer` by default.
- Write docs like the windows installation.

### Additional context

_No response_

Hints from issue discussion:

Commit message: docker-compose for one-line deployment

Patch to review:
diff --git a/dev_tools/Dockerfile b/dev_tools/Dockerfile
index 0ad040ce66..6fb82e9387 100644
--- a/dev_tools/Dockerfile
+++ b/dev_tools/Dockerfile
@@ -1,4 +1,4 @@
-FROM continuumio/anaconda3:2021.05
+FROM condaforge/mambaforge:4.12.0-0
 
 # Set remote and local dirs
 WORKDIR /app
@@ -6,15 +6,18 @@ ENV SOURCE=./
 
 # Install the base conda environment
 ENV PYROOT=/app/pyroot
-RUN conda create --prefix $PYROOT python==3.7.6 -y
+RUN mamba create --prefix $PYROOT python==3.7.6 -y
 
-# CV2 requires libGL.so.1
 RUN apt update
-RUN apt install -y libgl1 adb
+RUN apt install -y adb netcat
 
 # Install the requriements to the conda environment
 COPY $SOURCE/requirements-in.txt /app/requirements-in.txt
 RUN $PYROOT/bin/pip install -r /app/requirements-in.txt
 
+# Initial download of UIAutomator2 is really slow with appetizer mirror
+RUN sed -i "s#path = mirror_download(url,#path = cache_download(url,#" $PYROOT/lib/python3.7/site-packages/uiautomator2/init.py
+
 # When running the image, mount the ALAS folder into the container
+RUN git config --global --add safe.directory /app/AzurLaneAutoScript
 CMD $PYROOT/bin/python /app/AzurLaneAutoScript/gui.py
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000000..f17be3b90a
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,12 @@
+version: '3.7'
+services:
+    ALAS:
+        network_mode: host
+        volumes:
+            - '.:/app/AzurLaneAutoScript:rw'
+            - '/etc/localtime:/etc/localtime:ro'
+        container_name: 'alas'
+        image: 'alas'
+        build:
+            context: ./
+            dockerfile: ./dev_tools/Dockerfile
diff --git a/requirements-in.txt b/requirements-in.txt
index d15abe2a1d..c1b6d32bbb 100644
--- a/requirements-in.txt
+++ b/requirements-in.txt
@@ -1,7 +1,7 @@
 numpy==1.16.6
 scipy==1.4.1
 pillow
-opencv-python
+opencv-python-headless
 imageio
 lz4
 tqdm
@@ -25,4 +25,4 @@ alas-webapp==0.3.7
 rich==11.0.0
 zerorpc==0.6.3
 pyzmq==22.3.0
-atomicwrites
\ No newline at end of file
+atomicwrites


Code review comments:
diff_hunk: @@ -1,7 +1,7 @@
 numpy==1.16.6
 scipy==1.4.1
 pillow
-opencv-python
+opencv-python-headless
path: requirements-in.txt
text: @user1:
Don't change this. Some people is using `requirements-in.txt`, pip will install `opencv-python-headless` but won't uninstall `opencv-python` when they get upgrade. If multiple of the following opencv are installed, `import cv2` fails.
```
opencv-python
opencv-contrib-python
opencv-python-headless
opencv-contrib-python-headless
```

@author:
Actually, how about removing opencv-python, webapp, add headless to the copied version of req-in.txt with sed? Extra req.txt will be a pain to maintain

@user1:
I prefer a static file added into git instead of generating it dynamically, this will make things clear. You can imitate ./deploy/AidLux/requirements_generator. It's a ton of shitcode but do the trick.
FYI, AidLux is an terminal emulator on Android like termux, with pre-installed machine learning packages.