From fb261b1220c1801e9a17a440705068d4635076b8 Mon Sep 17 00:00:00 2001
From: SydneyOwl <84191144+SydneyOwl@users.noreply.github.com>
Date: Tue, 12 Nov 2024 21:56:51 +0800
Subject: [PATCH] :whale: User can compile it with docker now
---
.dockerignore | 25 ++++++++++++++++++++++
Dockerfile | 19 +++++++++++++++++
SenhaixFreqWriter.csproj | 2 ++
entrypoint.sh | 45 ++++++++++++++++++++++++++++++++++++++++
readme.md | 19 +++++++++++++++++
5 files changed, 110 insertions(+)
create mode 100644 .dockerignore
create mode 100644 Dockerfile
create mode 100644 entrypoint.sh
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..38bece4
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,25 @@
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/.idea
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/azds.yaml
+**/bin
+**/charts
+**/docker-compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..4c6284b
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,19 @@
+FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:6.0
+WORKDIR /source
+ENV TZ=Asia/Shanghai
+ARG DEBIAN_FRONTEND=noninteractive
+COPY . .
+RUN ls && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
+ sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && \
+ apt update -y && \
+ apt install --yes --no-install-recommends \
+ wget \
+ gcc && \
+ rm -rf /var/lib/apt/lists/* && \
+ wget -O ./amsat-all-frequencies.json https://cdn.jsdelivr.net/gh/palewire/amateur-satellite-database/data/amsat-all-frequencies.json && \
+ sed -i 's/@COMMIT_HASH@/DockerVersion/g' Properties/VERSION.cs && \
+ sed -i 's/@TAG_NAME@/DockerVersion/g' Properties/VERSION.cs && \
+ sed -i "s/@BUILD_TIME@/$(date)/g" Properties/VERSION.cs && \
+ chmod +x entrypoint.sh && mv entrypoint.sh /
+USER $APP_UID
+ENTRYPOINT ["/entrypoint.sh"]
\ No newline at end of file
diff --git a/SenhaixFreqWriter.csproj b/SenhaixFreqWriter.csproj
index d9322cd..dccf1b4 100644
--- a/SenhaixFreqWriter.csproj
+++ b/SenhaixFreqWriter.csproj
@@ -11,6 +11,8 @@
app.manifest
true
Asset\shx8800-icons\icon.ico
+ Linux
+ true
diff --git a/entrypoint.sh b/entrypoint.sh
new file mode 100644
index 0000000..53e9c62
--- /dev/null
+++ b/entrypoint.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+echo "Start building..."
+cd /source
+mkdir builddist
+ARCH="--linux-x64"
+
+if [ ! -z "$1" ]; then
+ ARCH="$1"
+fi
+
+if [[ "$ARCH" != "--linux-x64" && "$ARCH" != "--osx-x64" && "$ARCH" != "--win-x64" ]]; then
+ echo "Invalid arg '$ARCH'; Only --linux-x64/--osx-x64/--win-x64 is allowed."
+ exit 1
+fi
+
+case "$ARCH" in
+ --linux-x64)
+ echo "Building for linux x64..."
+ dotnet restore -r linux-x64
+ dotnet publish -c Release -r linux-x64 /p:PublishSingleFile=true --self-contained true
+ mv /source/bin/Release/net6.0/linux-x64/publish/* builddist
+ mv ./amsat-all-frequencies.json builddist
+ ;;
+ --osx-x64)
+ echo "Building for macos x64..."
+ dotnet restore -r osx-x64
+ dotnet msbuild -t:BundleApp -p:RuntimeIdentifier=osx-x64 -p:UseAppHost=true -property:Configuration=Release
+ mv /source/bin/Release/net6.0/osx-x64/publish/SenhaixFreqWriter.app builddist
+ cp Asset/shx8800-icons/icon.icns builddist/SenhaixFreqWriter.app/Contents/Resources
+ mv ./amsat-all-frequencies.json builddist/SenhaixFreqWriter.app/Contents/MacOS
+ ;;
+ --win-x64)
+ echo "Building for windows x64..."
+ dotnet restore -r win-x64
+ dotnet publish -c Release -r win-x64 /p:PublishSingleFile=true /p:TargetOS=Windows --self-contained true
+ mv /source/bin/Release/net6.0-windows10.0.19041.0/win-x64/publish/* builddist
+ mv ./amsat-all-frequencies.json builddist
+ ;;
+ *)
+ echo "Invalid Args"
+ exit 1
+ ;;
+esac
+
+echo "Done!"
\ No newline at end of file
diff --git a/readme.md b/readme.md
index 2dd2157..4509160 100644
--- a/readme.md
+++ b/readme.md
@@ -84,6 +84,25 @@
![](./readme_image/artifact.png)
+### Docker
+
+首先clone仓库并编译镜像:
+```shell
+git clone https://github.com/SydneyOwl/senhaix-freq-writer-enhanced
+cd senhaix-freq-writer-enhanced
+docker build -t "senhaix-freq-writer-builder" .
+```
+之后需要编译软件时,运行以下命令:
+```shell
+docker run --rm -it -v ./dister:/source/builddist build001 [arg]
+```
+其中`[arg]`可以是 `--win-x64`/`--osx-x64`/`linux-x64`,分别编译windows/macOS/Linux版本的写频软件。如未指定,默认编译Linux版本。
+
+注意:使用该方法编译的产物仅有软件本体,不含蓝牙插件!
+
+
+### 手动编译
+
如您使用`Rider`,按照`SenhaixFreqWriter.csproj`中的注释选择合适的框架,直接publish即可!
如您使用命令行编译,按照`SenhaixFreqWriter.csproj`中的注释选择合适的框架后,可以参考`.github/workflows/build.yml`进行编译。