Skip to content

Commit

Permalink
add Dockerfile for cross-platform packaging using Wine.
Browse files Browse the repository at this point in the history
  • Loading branch information
WFA-lliu committed Feb 17, 2024
1 parent b9fa42d commit 2733e44
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 0 deletions.
88 changes: 88 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

## Usage:

<details>
<summary>from source (.py)</summary>

```sh
usage: sigmadouble.py [-h] [-v] [-f filename] [-i mapped_ipv4]
[-p mapped_port_base]
Expand All @@ -25,6 +28,32 @@ optional arguments:
-l mapping_loaded_filename, --load mapping_loaded_filename
mapping loaded filename, to UCC log; YAML formatted
```
</details>

<details>
<summary>from binary (.exe)</summary>

```sh
usage: sigmadouble.exe [-h] [-v] [-f filename] [-i mapped_ipv4] [-p mapped_port_base]
[-s mapping_stored_filename | -l mapping_loaded_filename]

CLI argument parsing

optional arguments:
-h, --help show this help message and exit
-v, --verbose verbosity
-f filename, --filename filename
filename of UCC log
-i mapped_ipv4, --ip mapped_ipv4
mapped IPv4 address; only for mapping stored filename
-p mapped_port_base, --port mapped_port_base
mapped TCP listening port base; only for mapping stored filename
-s mapping_stored_filename, --store mapping_stored_filename
mapping stored filename, from UCC log; YAML formatted
-l mapping_loaded_filename, --load mapping_loaded_filename
mapping loaded filename, to UCC log; YAML formatted
```
</details>

## Description:
A test double to **emulate** Sigma handshaking based on existing log.
Expand All @@ -44,3 +73,62 @@ The UCC core must alter:
> > Notice here, when DUT is one of testbeds, the handle (IP-port pair) of the testbed is recommended to be commented/removed.
Thus, when UCC core sends request to test double, then, test double will send corresponding response back; **just like replaying the tapes of music**.

## Build:

<details>
<summary>Cross-platform packaging using <b>Wine</b></summary>

Building _Windows 11_ binary executable steps under _Ubuntu 20.04_ are following.

* To build the docker image using existing Dockerfile; **Wine** installation is included in the Dockerfile
```sh
docker build -f ubuntu-20-04-wine.dockerfile -t wine-20-04 . --build-arg UID=$UID --build-arg USER=$USER --build-arg PASSWORD="demonslayer"
```
* To disable the access control of X-server
```sh
xhost +
```

* To launch the docker container; current working directory is mounted to _/mnt_
```sh
docker run -it --name wine-20-04-inst --device /dev/snd --device=/dev/dri -e DISPLAY=$DISPLAY -e XMODIFIERS=@im=fcitx -e QT_IM_MODULE=fcitx -e GTK_IM_MODULE=fcitx -v /tmp/.X11-unix:/tmp/.X11-unix:ro -v $(pwd):/mnt --net=host wine-20-04 bash
```

* To download a suitable python installer such as v3.8 under the container
```sh
wget https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe -O /mnt/python-3.8.10-amd64.exe
```

* To install the python installer under the container
```sh
WINEPREFIX=~/.wine64 wine /mnt/python-3.8.10-amd64.exe
```

* To install dependency for this _test double_ under the container
```sh
WINEPREFIX=~/.wine64 wine ~/.wine64/drive_c/users/`id -u -n`/AppData/Local/Programs/Python/Python38/python.exe -m pip install pyyaml
```

* To install dependency for packaging under the container
```sh
WINEPREFIX=~/.wine64 wine ~/.wine64/drive_c/users/`id -u -n`/AppData/Local/Programs/Python/Python38/python.exe -m pip install pyinstaller
```

* To package the binary executable under the container; the binary executable is stored in the distributable directory (i.e. _/mnt_)
```sh
WINEPREFIX=~/.wine64 wine ~/.wine64/drive_c/users/`id -u -n`/AppData/Local/Programs/Python/Python38/Scripts/pyinstaller.exe --clean --console --onefile /mnt/sigmadouble.py --distpath /mnt
```

* To exit the container
```sh
exit
```

* To enable the access control of X-server
```sh
xhost -
```

</details>

86 changes: 86 additions & 0 deletions ubuntu-20-04-wine.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
FROM --platform=amd64 ubuntu:20.04

ARG UID=9527
ARG USER=WFA
ARG PASSWORD="docker"
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
software-properties-common \
ca-certificates \
language-pack-en \
language-pack-zh-hant* \
locales \
locales-all \
wget

# Install Wine
RUN dpkg --add-architecture i386 && \
mkdir -pm755 /etc/apt/keyrings && \
wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key && \
wget -nc -P /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/$(lsb_release -sc)/winehq-$(lsb_release -sc).sources && \
apt-get update -y && \
# Wine 7.0 stable has some issues with some games I tested
# Use Wine 7.11 staging instead
apt-get install -y --install-recommends winehq-staging

# GStreamer plugins
RUN apt-get update -y && \
apt-get install -y --install-recommends \
gstreamer1.0-libav:i386
RUN apt-get update -y && \
apt-get install -y --install-recommends \
gstreamer1.0-plugins-bad:i386
RUN apt-get update -y && \
apt-get install -y --install-recommends \
gstreamer1.0-plugins-base:i386
RUN apt-get update -y && \
apt-get install -y --install-recommends \
gstreamer1.0-plugins-good:i386
RUN apt-get update -y && \
apt-get install -y --install-recommends \
gstreamer1.0-plugins-ugly:i386
RUN apt-get update -y && \
apt-get install -y --install-recommends \
gstreamer1.0-pulseaudio:i386

# Install dependencies for display scaling
RUN apt-get update -y && \
apt-get install -y --install-recommends \
build-essential \
bc \
git \
xpra \
xvfb \
python3 \
python3-pip

# Install OpenGL acceleration for display scaling
RUN pip3 install PyOpenGL==3.1.5 PyOpenGL_accelerate==3.1.5

# Install display scaling script
RUN cd /tmp && \
git clone https://github.com/kaueraal/run_scaled.git && \
cp /tmp/run_scaled/run_scaled /usr/local/bin/

# Install missing fonts for Chinese
RUN apt-get update -y && \
apt-get install -y --install-recommends \
fonts-wqy-microhei

# Install driver for Intel HD graphics
RUN apt-get -y install libgl1-mesa-glx libgl1-mesa-dri

ENV LC_ALL zh_TW.UTF-8
ENV LANG zh_TW.UTF-8
# Make sure the terminal is still English
ENV LANGUAGE en_US.UTF-8

RUN apt-get install -qqy sudo
RUN useradd -r -m -d /home/$USER -s /bin/bash -g root -g sudo -u $UID $USER
RUN echo "$USER:$PASSWORD" | chpasswd
RUN echo "root:$PASSWORD" | chpasswd
USER $USER
WORKDIR /home/$USER

0 comments on commit 2733e44

Please sign in to comment.