From 95eb3a427c243a3259ac38f7ce48087e22d57a1f Mon Sep 17 00:00:00 2001 From: monkeyWie Date: Mon, 7 Nov 2022 16:32:52 +0800 Subject: [PATCH] feat: docker support (#43) --- .github/workflows/build.yml | 19 +++++++++++- Dockerfile | 21 ++++++++++++++ README.md | 10 +++++++ README_zh-CN.md | 10 +++++++ cmd/web/main.go | 2 +- ui/flutter/lib/api/api.dart | 5 +++- ui/flutter/lib/core/libgopeed_boot.dart | 2 +- .../lib/pages/setting/setting_view.dart | 5 +++- ui/flutter/lib/widget/directory_selector.dart | 29 ++++++++++--------- 9 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e825fb7f..858fdd3f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,6 +44,8 @@ jobs: cp $system\vcruntime140.dll $release cp $system\vcruntime140_1.dll $release + Compress-Archive -Path $release -DestinationPath build\windows\Output\Gopeed-$env:VERSION-windows-amd64.zip + cd build/windows echo @" ; Script generated by the Inno Setup Script Wizard. @@ -95,7 +97,7 @@ jobs: Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent "@ > setup.iss iscc.exe setup.iss - mv "Output\gopeed.exe" "Output\Gopeed-$env:VERSION-windows-amd64.exe" + mv "Output\gopeed.exe" "Output\Gopeed-$env:VERSION-windows-amd64-install.exe" - name: Upload uses: shogo82148/actions-upload-release-asset@v1 with: @@ -318,3 +320,18 @@ jobs: upload_url: ${{ needs.release.outputs.upload_url }} asset_path: dist/zip/* overwrite: true + build-docker: + runs-on: ubuntu-latest + needs: [get_release] + steps: + - uses: actions/checkout@v3 + - name: Build + env: + VERSION: ${{ needs.get_release.outputs.tag_name }} + run: | + tag=liwei2633/gopeed:$VERSION + docker build -t $tag . + docker login -u liwei2633 -p ${{ secrets.DOCKER_PASSWORD }} + docker push $tag + docker tag $tag liwei2633/gopeed:latest + docker push liwei2633/gopeed:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c5f43a75 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM cirrusci/flutter:3.3.7 AS flutter +WORKDIR /app +COPY ./ui/flutter/pubspec.yaml ./ui/flutter/pubspec.lock ./ +RUN flutter pub get +COPY ./ui/flutter ./ +RUN flutter build web + +FROM golang:1.19.3 AS go +WORKDIR /app +COPY ./go.mod ./go.sum ./ +RUN go mod download +COPY . . +COPY --from=flutter /app/build/web/* ./cmd/web/dist +RUN go build -tags nosqlite,web -ldflags="-s -w" -o dist/gopeed github.com/monkeyWie/gopeed/cmd/web + +FROM alpine:3.14.2 +LABEL maintainer="monkeyWie" +WORKDIR /app +COPY --from=go /app/dist/gopeed ./ +EXPOSE 9999 +ENTRYPOINT ["./gopeed"] \ No newline at end of file diff --git a/README.md b/README.md index d98f43a0..f1b71d58 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Gopeed is a high-speed downloader developed by `Golang`+`Flutter`, which support - [x] android - [ ] ios - [x] web +- [x] docker [To Release](https://github.com/monkeyWie/gopeed/releases/latest) @@ -32,6 +33,15 @@ use `go install`: go install github.com/monkeyWie/gopeed/cmd/gopeed ``` +### Docker + +```bash +docker run liwei2633/gopeed:latest -v /path/to/download:/download -p 9999:9999 +``` + +When the docker container is running, you can access the web page through `http://localhost:9999`. +> Tip: Modify the download path to `/download` on the setting page to access the downloaded files on the host. + ## Showcase ![](_docs/img/ui-demo.png) diff --git a/README_zh-CN.md b/README_zh-CN.md index 87bf2a15..5af0c0be 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -21,6 +21,7 @@ Gopeed 是一款由`Golang`+`Flutter`开发的高速下载器,支持(HTTP、 - [x] android - [ ] ios - [x] web +- [x] docker [点击前往](https://github.com/monkeyWie/gopeed/releases/latest) @@ -32,6 +33,15 @@ Gopeed 是一款由`Golang`+`Flutter`开发的高速下载器,支持(HTTP、 go install github.com/monkeyWie/gopeed/cmd/gopeed ``` +### Docker + +```bash +docker run liwei2633/gopeed:latest -v /path/to/download:/download -p 9999:9999 +``` + +当 docker 容器运行时,可以通过 `http://localhost:9999` 访问 web 页面。 +> 提示:在设置页面把下载路径修改为 `/download` 以便在宿主机访问下载完的文件。 + ## 界面展示 ![](_docs/img/ui-demo.png) diff --git a/cmd/web/main.go b/cmd/web/main.go index 8b25b17b..dc1d7835 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -26,7 +26,7 @@ func main() { cfg := &model.StartConfig{ Network: "tcp", Address: "127.0.0.1:9999", - Storage: model.StorageMem, + Storage: model.StorageBolt, WebEnable: true, WebFS: sub, } diff --git a/ui/flutter/lib/api/api.dart b/ui/flutter/lib/api/api.dart index 10207275..a6d1138e 100644 --- a/ui/flutter/lib/api/api.dart +++ b/ui/flutter/lib/api/api.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:dio/adapter.dart'; import 'package:dio/dio.dart'; +import 'package:gopeed/util/util.dart'; import 'model/create_task.dart'; import 'model/request.dart'; import 'model/resource.dart'; @@ -26,7 +27,9 @@ class _Client { final isUnixSocket = LibgopeedBoot.instance.config.network == 'unix'; dio.options.baseUrl = isUnixSocket ? 'http://127.0.0.1' - : 'http://${LibgopeedBoot.instance.config.address}'; + : (Util.isWeb() + ? "" + : 'http://${LibgopeedBoot.instance.config.address}'); _instance!.dio = dio; if (isUnixSocket) { (_instance!.dio.httpClientAdapter as DefaultHttpClientAdapter) diff --git a/ui/flutter/lib/core/libgopeed_boot.dart b/ui/flutter/lib/core/libgopeed_boot.dart index 07397072..2383636f 100644 --- a/ui/flutter/lib/core/libgopeed_boot.dart +++ b/ui/flutter/lib/core/libgopeed_boot.dart @@ -9,7 +9,7 @@ class LibgopeedConfig { LibgopeedConfig({ this.network = "tcp", - this.address = "127.0.0.1:9999", + this.address = "127.0.0.1:0", this.refreshInterval = 500, }); } diff --git a/ui/flutter/lib/pages/setting/setting_view.dart b/ui/flutter/lib/pages/setting/setting_view.dart index 6f942317..38f6d699 100644 --- a/ui/flutter/lib/pages/setting/setting_view.dart +++ b/ui/flutter/lib/pages/setting/setting_view.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:gopeed/i18n/messages.dart'; +import 'package:gopeed/util/util.dart'; import '../../setting/setting.dart'; import '../../widget/directory_selector.dart'; @@ -69,7 +70,9 @@ class SettingView extends GetView { controller.setting.value.downloadDir) { controller.setting.value.downloadDir = downloadDirController.text; - controller.clearTapStatus(); + if (Util.isDesktop()) { + controller.clearTapStatus(); + } await debounceSave(); } diff --git a/ui/flutter/lib/widget/directory_selector.dart b/ui/flutter/lib/widget/directory_selector.dart index 366277df..6fef9d37 100644 --- a/ui/flutter/lib/widget/directory_selector.dart +++ b/ui/flutter/lib/widget/directory_selector.dart @@ -1,6 +1,7 @@ import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:gopeed/util/util.dart'; import '../util/mac_secure_util.dart'; @@ -23,7 +24,7 @@ class _DirectorySelectorState extends State { children: [ Expanded( child: TextFormField( - readOnly: true, + readOnly: Util.isWeb() ? false : true, controller: widget.controller, decoration: widget.showLabel ? InputDecoration( @@ -34,18 +35,20 @@ class _DirectorySelectorState extends State { return v!.trim().isNotEmpty ? null : 'setting.downloadDirValid'.tr; }, )), - IconButton( - icon: const Icon(Icons.folder_open), - onPressed: () async { - if (GetPlatform.isDesktop) { - var dir = await getDirectoryPath(); - if (dir != null) { - widget.controller.text = dir; - MacSecureUtil.saveBookmark(dir); - } - } - }) - ], + !Util.isDesktop() + ? null + : IconButton( + icon: const Icon(Icons.folder_open), + onPressed: () async { + if (GetPlatform.isDesktop) { + var dir = await getDirectoryPath(); + if (dir != null) { + widget.controller.text = dir; + MacSecureUtil.saveBookmark(dir); + } + } + }) + ].where((e) => e != null).map((e) => e!).toList(), ); } }