Jelajahi Sumber

feat: flutter prod build

Fela Maslen 4 tahun lalu
induk
melakukan
ce4d5189f9

+ 1 - 1
Jenkinsfile

@@ -56,7 +56,7 @@ node {
 
     stage('Deploy') {
       if (env.BRANCH_NAME == "master") {
-        sh 'LIBRARY_DIRECTORY=/data/user/music/ogg ./k8s/deploy.sh'
+        sh 'LIBRARY_DIRECTORY=$GMUS_LIBRARY_DIRECTORY ./k8s/deploy.sh'
       }
     }
   }

+ 11 - 0
gmus-mobile/Makefile

@@ -0,0 +1,11 @@
+prepare.android:
+	@./scripts/prepare_android.sh
+
+build.android:
+	@flutter build appbundle --dart-define=API_URL=${GMUS_MOBILE_API_URL}
+
+run:
+	flutter run --dart-define=API_URL="${GMUS_MOBILE_API_URL}"
+
+test.flutter:
+	flutter test

+ 17 - 5
gmus-mobile/android/app/build.gradle

@@ -25,6 +25,12 @@ apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
 
+def keystoreProperties = new Properties()
+def keystorePropertiesFile = rootProject.file('key.properties')
+if (keystorePropertiesFile.exists()) {
+    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
+}
+
 android {
     compileSdkVersion 29
 
@@ -37,19 +43,25 @@ android {
     }
 
     defaultConfig {
-        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
-        applicationId "com.example.gmus_mobile"
+        applicationId "space.fela.gmus"
         minSdkVersion 16
         targetSdkVersion 29
         versionCode flutterVersionCode.toInteger()
         versionName flutterVersionName
     }
 
+    signingConfigs {
+        release {
+            keyAlias keystoreProperties['keyAlias']
+            keyPassword keystoreProperties['keyPassword']
+            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
+            storePassword keystoreProperties['storePassword']
+        }
+    }
+
     buildTypes {
         release {
-            // TODO: Add your own signing config for the release build.
-            // Signing with the debug keys for now, so `flutter run --release` works.
-            signingConfig signingConfigs.debug
+            signingConfig signingConfigs.release
         }
     }
 }

+ 2 - 1
gmus-mobile/android/app/src/main/AndroidManifest.xml

@@ -7,7 +7,7 @@
          FlutterApplication and put your custom class here. -->
     <application
         android:name="io.flutter.app.FlutterApplication"
-        android:label="gmus_mobile"
+        android:label="gmus"
         android:icon="@mipmap/launcher_icon">
         <activity
             android:name=".MainActivity"
@@ -44,4 +44,5 @@
             android:name="flutterEmbedding"
             android:value="2" />
     </application>
+    <uses-permission android:name="android.permission.INTERNET" />
 </manifest>

+ 2 - 2
gmus-mobile/lib/components/albums.dart

@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:http/http.dart' as http;
 
-import '../config.dart';
+import '../utils/url.dart';
 
 import './spinner.dart';
 
@@ -22,7 +22,7 @@ class Albums extends StatefulWidget {
 }
 
 Future<List<String>> fetchAlbums(String artist) async {
-  final response = await http.get(Uri.https(config['apiUrl'], '/albums', {
+  final response = await http.get(formattedUrl('/albums', {
     'artist': artist,
   }));
 

+ 3 - 2
gmus-mobile/lib/components/artists.dart

@@ -3,7 +3,8 @@ import 'dart:convert';
 import 'package:flutter/material.dart';
 import 'package:http/http.dart' as http;
 
-import '../config.dart';
+import '../utils/url.dart';
+
 import './spinner.dart';
 
 class Artists extends StatefulWidget {
@@ -18,7 +19,7 @@ class Artists extends StatefulWidget {
 }
 
 Future<List<String>> fetchArtists() async {
-  final response = await http.get(Uri.https(config['apiUrl'], '/artists'));
+  final response = await http.get(formattedUrl('/artists'));
 
   if (response.statusCode == 200) {
     return List<String>.from(jsonDecode(response.body)['artists']);

+ 0 - 1
gmus-mobile/lib/components/content.dart

@@ -20,4 +20,3 @@ class Content extends StatelessWidget {
     });
   }
 }
-

+ 2 - 2
gmus-mobile/lib/components/songs.dart

@@ -4,8 +4,8 @@ import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:http/http.dart' as http;
 
-import '../config.dart';
 import '../types/song.dart';
+import '../utils/url.dart';
 
 import './spinner.dart';
 
@@ -29,7 +29,7 @@ class Songs extends StatefulWidget {
 }
 
 Future<List<Song>> fetchSongs(String artist) async {
-  final response = await http.get(Uri.https(config['apiUrl'], '/songs', {
+  final response = await http.get(formattedUrl('/songs', {
     'artist': artist,
   }));
 

+ 3 - 1
gmus-mobile/lib/config.dart

@@ -1,6 +1,8 @@
 import 'package:flutter_dotenv/flutter_dotenv.dart';
 
+const apiUrl = String.fromEnvironment('API_URL') ?? 'localhost:3000';
+
 final config = {
   'isDevelopment': env['DART_ENV'] == 'development',
-  'apiUrl': env['API_URL'] ?? 'http://localhost:3000',
+  'apiUrl': env['API_URL'] ?? apiUrl,
 };

+ 14 - 0
gmus-mobile/lib/utils/url.dart

@@ -0,0 +1,14 @@
+import '../config.dart';
+
+Uri formattedUrl(String path, [Map<String, dynamic> query]) {
+  String apiUrl = config['apiUrl'];
+
+  if (apiUrl.indexOf('/') == -1) {
+    return Uri.https(apiUrl, path);
+  }
+
+  String host = apiUrl.substring(0, apiUrl.indexOf('/'));
+  String pathPrefix = apiUrl.substring(apiUrl.indexOf('/'));
+
+  return Uri.https(host, "$pathPrefix$path", query);
+}

+ 1 - 1
gmus-mobile/pubspec.yaml

@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
 # Read more about iOS versioning at
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
-version: 1.0.0+1
+version: 0.0.1+1
 
 environment:
   sdk: ">=2.7.0 <3.0.0"

+ 24 - 0
gmus-mobile/scripts/prepare_android.sh

@@ -0,0 +1,24 @@
+#!/bin/bash
+
+set -e
+
+cd "$(dirname $0)"
+
+if [[ -z "$GMUS_ANDROID_KEYSTORE_FILE" ]]; then
+  echo "Must set GMUS_ANDROID_KEYSTORE_FILE"
+  exit 1
+fi
+
+if [[ -z "$GMUS_ANDROID_KEYSTORE_PASSWORD" ]]; then
+  echo "Must set GMUS_ANDROID_KEYSTORE_PASSWORD"
+  exit 1
+fi
+
+cat > ../android/key.properties << EOF
+storePassword=$GMUS_ANDROID_KEYSTORE_PASSWORD
+keyPassword=$GMUS_ANDROID_KEYSTORE_PASSWORD
+keyAlias=key
+storeFile=$GMUS_ANDROID_KEYSTORE_FILE
+EOF
+
+exit 0

+ 2 - 2
gmus-mobile/test/components/status_test.dart

@@ -2,8 +2,8 @@ import 'package:flutter/widgets.dart';
 import 'package:flutter_test/flutter_test.dart';
 import 'package:get/get.dart';
 
-import 'package:gmus_mobile/components/status.dart';
-import 'package:gmus_mobile/controller.dart';
+import 'package:gmus/components/status.dart';
+import 'package:gmus/controller.dart';
 
 class TestStatusBar extends StatelessWidget {
   final Controller controller;

+ 2 - 2
gmus-mobile/test/controller_test.dart

@@ -1,6 +1,6 @@
 import 'package:flutter_test/flutter_test.dart';
-import 'package:gmus_mobile/actions.dart';
-import 'package:gmus_mobile/controller.dart';
+import 'package:gmus/actions.dart';
+import 'package:gmus/controller.dart';
 import 'package:mockito/mockito.dart';
 import 'package:web_socket_channel/io.dart';
 import 'package:web_socket_channel/web_socket_channel.dart';

+ 5 - 0
k8s/deploy.sh

@@ -7,6 +7,11 @@ cd $(dirname "$0")
 IMAGE_BACKEND=$(make -f ../gmus-backend/Makefile get_image)
 IMAGE_WEB=$(make -f ../gmus-web/Makefile get_image)
 
+if [[ -z $LIBRARY_DIRECTORY ]]; then
+  echo "Must set LIBRARY_DIRECTORY!"
+  exit 1
+fi
+
 namespace="gmus"
 
 cat ./manifest.yml \