Skip to content

Commit

Permalink
feat: add docker target
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Jan 26, 2024
1 parent 84a335d commit 5f0220a
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WIN_CLIENT_DOWNLOAD_PATH=
AND_CLIENT_DOWNLOAD_PATH=
40 changes: 40 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,43 @@ jobs:
with:
name: android
path: ${{ env.APP_NAME }}-${{ github.ref_name }}.apk

build-docker:
runs-on: ubuntu-latest
needs: [build-windows, build-web, build-android]
steps:
- name: Set env
run: |
echo "WIN_FILE_NAME=${{ env.APP_NAME }}-windows-${{ github.ref_name }}.zip" >> $GITHUB_ENV
echo "WEB_FILE_NAME=${{ env.APP_NAME }}-web-${{ github.ref_name }}.tar.gz" >> $GITHUB_ENV
echo "AND_FILE_NAME=${{ env.APP_NAME }}-${{ github.ref_name }}.apk" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Display structure of downloaded files
run: ls -R
- name: Extract web file
run: tar -zxvf $WEB_FILE_NAME -C ./docker/web
- name: Move other files
run: |
mv $WIN_FILE_NAME ./docker/$WIN_FILE_NAME
mv $AND_FILE_NAME ./docker/$AND_FILE_NAME
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./docker
file: ./docker/Dockerfile
push: true
tags: $GITHUB_REPOSITORY:${{ github.ref_name }}
build-args: |
WEB_FILE=web/*
WIN_FILE_NAME=$WIN_FILE_NAME
AND_FILE_NAME=$AND_FILE_NAME
27 changes: 27 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM nginx:stable-alpine

ARG WEB_FILE
ARG WIN_FILE_NAME
ARG AND_FILE_NAME

RUN apk add --no-cache --update miller

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d

COPY ${WEB_FILE} /usr/share/nginx/html
RUN touch /usr/share/nginx/html/.env
RUN echo "WIN_CLIENT_DOWNLOAD_PATH=/download/windows" > /usr/share/nginx/html/.env
RUN echo "AND_CLIENT_DOWNLOAD_PATH=/download/android" >> /usr/share/nginx/html/.env

COPY ${WIN_FILE_NAME} /download/${WIN_FILE_NAME}
COPY ${AND_FILE_NAME} /download/${AND_FILE_NAME}

RUN apk del miller

ENV WIN_FILE_NAME=${WIN_FILE_NAME}
ENV AND_FILE_NAME=${AND_FILE_NAME}

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
28 changes: 28 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
env WIN_FILE_NAME;
env AND_FILE_NAME;

server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

location /download/windows {
alias /download/$WIN_FILE_NAME;
add_header Content-Disposition 'attachment; filename="$WIN_FILE_NAME"';
}

location /download/android {
alias /download/$AND_FILE_NAME;
add_header Content-Disposition 'attachment; filename="$AND_FILE_NAME"';
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
2 changes: 2 additions & 0 deletions l10n_arb/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"buttonMinimizeToTray": "最小化到托盘",
"buttonCancel": "取消",
"webVersionFunctionLimited": "Web版本功能有限,仅供评估使用。",
"downloadClient": "下载客户端",
"continueInWebVersion": "继续使用网页版",

"durationJustNow": "刚刚",
"durationSeconds": "{number} 秒前",
Expand Down
12 changes: 12 additions & 0 deletions lib/consts.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

import 'route.dart';

Expand Down Expand Up @@ -45,3 +46,14 @@ const themeData = [
1,
),
];

class DotEnvValue {
final String? value;

DotEnvValue._(this.value);

static String winClientDownloadUrl =
dotenv.env['WIN_CLIENT_DOWNLOAD_PATH'] ?? '';
static String andClientDownloadUrl =
dotenv.env['AND_CLIENT_DOWNLOAD_PATH'] ?? '';
}
3 changes: 3 additions & 0 deletions lib/init.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
part of 'main.dart';

Future<MyApp> init() async {
// dotenv
await dotenv.load(fileName: '.env');

// dao

// https://github.com/hivedb/hive/issues/1044
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/intl/messages_zh-CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class MessageLookup extends MessageLookupByLibrary {
"buttonRetry": MessageLookupByLibrary.simpleMessage("重试"),
"chesed": MessageLookupByLibrary.simpleMessage("Chesed"),
"clickLoginToStart": MessageLookupByLibrary.simpleMessage("点击登录以开始"),
"continueInWebVersion": MessageLookupByLibrary.simpleMessage("继续使用网页版"),
"downloadClient": MessageLookupByLibrary.simpleMessage("下载客户端"),
"durationDays": m0,
"durationHours": m1,
"durationJustNow": MessageLookupByLibrary.simpleMessage("刚刚"),
Expand Down
20 changes: 20 additions & 0 deletions lib/l10n/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/hive_flutter.dart';
Expand Down
7 changes: 7 additions & 0 deletions lib/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import 'view/pages/settings/user/user_add_page.dart';
import 'view/pages/settings/user/user_edit_page.dart';
import 'view/pages/settings/user/user_manage_page.dart';
import 'view/pages/tiphereth/tiphereth_frame_page.dart';
import 'view/pages/web_landing_page.dart';
import 'view/pages/yesod/yesod_config_add_page.dart';
import 'view/pages/yesod/yesod_config_edit_page.dart';
import 'view/pages/yesod/yesod_config_page.dart';
Expand Down Expand Up @@ -90,6 +91,7 @@ class AppRoutes {
}

static const AppRoutes init = AppRoutes._('/');
static const AppRoutes webLanding = AppRoutes._('/webLanding');
static const AppRoutes login = AppRoutes._('/login');
static const String _imageViewer = '/imageViewer';
static AppRoutes imageViewer(int index) =>
Expand Down Expand Up @@ -285,6 +287,11 @@ GoRouter getRouter(MainBloc mainBloc, ApiHelper apiHelper) {
pageBuilder: (context, state) =>
const NoTransitionPage(child: MainWindow(child: InitPage())),
),
GoRoute(
path: AppRoutes.webLanding.toString(),
pageBuilder: (context, state) =>
const NoTransitionPage(child: WebLandingPage()),
),
GoRoute(
path: AppRoutes.login.toString(),
pageBuilder: (context, state) =>
Expand Down
9 changes: 9 additions & 0 deletions lib/view/pages/init_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../bloc/main_bloc.dart';
import '../../common/platform.dart';
import '../../consts.dart';
import '../../l10n/l10n.dart';
import '../../route.dart';
import '../components/toast.dart';
Expand Down Expand Up @@ -34,6 +36,13 @@ class _InitPageState extends State<InitPage> {
AppRoutes.tiphereth.go(context);
Toast(title: '', message: S.of(context).welcomeBack).show(context);
}
if (state is MainAutoLoginState &&
state.failed &&
PlatformHelper.isWeb() &&
(DotEnvValue.andClientDownloadUrl.isNotEmpty ||
DotEnvValue.winClientDownloadUrl.isNotEmpty)) {
AppRoutes.webLanding.go(context);
}
},
builder: (context, state) {
return Scaffold(
Expand Down
124 changes: 124 additions & 0 deletions lib/view/pages/web_landing_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../bloc/main_bloc.dart';
import '../../common/platform.dart';
import '../../consts.dart';
import '../../l10n/l10n.dart';
import '../../route.dart';
import '../components/toast.dart';
import '../helper/spacing.dart';
import '../layout/bootstrap_container.dart';

class WebLandingPage extends StatelessWidget {
const WebLandingPage({super.key});

@override
Widget build(BuildContext context) {
final primaryButtonStyle = ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
Theme.of(context).colorScheme.primary,
),
foregroundColor: MaterialStateProperty.all<Color>(
Theme.of(context).colorScheme.onPrimary,
),
);
return Theme(
data: Theme.of(context).copyWith(
scaffoldBackgroundColor: Theme.of(context).colorScheme.surfaceVariant,
),
child: BlocConsumer<MainBloc, MainState>(
listener: (context, state) {
if (state.currentUser != null) {
AppRoutes.tiphereth.go(context);
Toast(title: '', message: S.of(context).welcome).show(context);
}
},
builder: (context, state) {
return Scaffold(
body: BootstrapContainer(children: [
BootstrapColumn(
xxs: 12,
md: 8,
lg: 6,
child: Card(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
S.of(context).welcomeHeader,
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
SpacingHelper.defaultDivider,
Text(
S.of(context).downloadClient,
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton.icon(
onPressed:
DotEnvValue.winClientDownloadUrl.isNotEmpty
? () async {
final url = Uri.parse(
DotEnvValue.winClientDownloadUrl);
await launchUrl(url);
}
: null,
style: PlatformHelper.isWindows()
? primaryButtonStyle
: null,
icon: Icon(
const FaIcon(FontAwesomeIcons.windows).icon),
label: const Text('Windows'),
),
const SizedBox(width: 16),
ElevatedButton.icon(
onPressed:
DotEnvValue.andClientDownloadUrl.isNotEmpty
? () async {
final url = Uri.parse(
DotEnvValue.andClientDownloadUrl);
await launchUrl(url);
}
: null,
style: PlatformHelper.isAndroid()
? primaryButtonStyle
: null,
icon: Icon(
const FaIcon(FontAwesomeIcons.android).icon),
label: const Text('Android'),
),
],
),
const SizedBox(height: 16),
SpacingHelper.defaultDivider,
const SizedBox(height: 16),
OutlinedButton(
onPressed: () {
AppRoutes.login.go(context);
},
child: Text(S.of(context).continueInWebVersion),
),
],
),
),
),
),
]),
);
},
),
);
}
}
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ dependencies:
petitparser: ^6.0.2
url_launcher: ^6.2.3
flutter_markdown: ^0.6.18
flutter_dotenv: ^5.1.0
app_links: ^3.5.0

# others
json_annotation: ^4.8.1
Expand Down Expand Up @@ -148,6 +150,7 @@ flutter:
- web/icons/Icon-512.png
- windows/runner/resources/app_icon.ico
- PrivacyPolicy.md
- .env

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down

0 comments on commit 5f0220a

Please sign in to comment.