Skip to content

Commit

Permalink
Dockerize NoticeBoard (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkonidena authored Mar 23, 2024
1 parent 861dfb0 commit 4f633df
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 67 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Noticeboard Docker File",
"build": {
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [5037],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
"dockerRun": {"runArgs": ["--privileged"]}
}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: NoticeBoard
path: build/app/outputs/apk/release/NoticeBoardApp.apk
path: build/app/outputs/flutter-apk/app-release.apk
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: NoticeBoard
path: build/app/outputs/apk/release/NoticeBoardApp.apk
path: build/app/outputs/flutter-apk/app-release.apk
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Use ubuntu 22.04 LTS as Base Image
FROM ubuntu:22.04

# This sets up java in the container
RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget adb libjaxb-api-java

# Set up new user
RUN useradd -ms /bin/bash developer
WORKDIR /home/developer

# Prepare Android directories and system variables
RUN cd /home/developer
RUN mkdir -p Android/sdk
ENV ANDROID_SDK_ROOT /home/developer/Android/sdk
RUN mkdir -p .android && touch .android/repositories.cfg

# Set up Android SDK and accept licenses
RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools.zip && rm sdk-tools.zip
RUN cd /home/developer
RUN mv tools Android/sdk/tools
RUN cd Android/sdk/tools/bin && yes | ./sdkmanager --licenses
RUN cd /home/developer
RUN cd Android/sdk/tools/bin && touch /root/.android/repositories.cfg && ./sdkmanager "build-tools;29.0.2" "platform-tools" "platforms;android-29" "sources;android-29" "cmdline-tools;latest"
ENV PATH "$PATH:/home/developer/Android/sdk/platform-tools"

# Download Flutter SDK and add flutter to path
RUN cd /home/developer
RUN wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.19.1-stable.tar.xz
RUN tar -xvf flutter_linux_3.19.1-stable.tar.xz
RUN git config --global --add safe.directory /home/developer/flutter
WORKDIR /home/developer
ENV PATH "$PATH:/home/developer/flutter/bin"

# Run basic check to download Dark SDK
RUN flutter doctor

# Install JavaDevelopment Kit
RUN apt install -y openjdk-17-jdk

# Accept all Android-SDK licenses
RUN flutter doctor --android-licenses

# Verify android toolchain is set up for development
RUN flutter doctor -v

# Go to noticeboard-mobile directory
WORKDIR /workspaces/noticeboard-mobile-app/noticeboard


# Install dependencies
CMD [ "flutter" "pub" "get" ]



42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,48 @@ The official digital noticeboard of IITR. Provides easy access to the Channel i
- Bookmark notices on the go!
- Now after many demands from the iPhone users, noticeboard finally comes on the app store!

## Development Setup

### Prerequisites
- Visual Studio Code
- Docker
- Android phone with USB debugging enabled

### Installing VS Code Dev Container Extension
1. Open Visual Studio Code.
2. Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressing Ctrl+Shift+X.
3. Search for "Remote - Containers" and click Install.

### Opening the Project in a Dev Container
1. Clone the project repository.
2. Open the project folder in Visual Studio Code.
3. Press Cmd+Shift+P on Mac or Ctrl+Shift+P on Ubuntu/Windows to open the Command Palette.
4. Search for "Remote-Containers: Open Folder in Container" and select it.
5. Wait for the container to build (this may take some time, especially the first time).

### Setting up Android Phone for Debugging
1. Ensure your phone and PC are connected to the same Wi-Fi network.
2. Enable USB debugging on your phone:
- Go to Settings > About phone > Software information.
- Tap "Build number" seven times to enable Developer options.
- Go back to the main Settings screen, and now you should see "Developer options".
- Open Developer options and enable USB debugging.
3. Enable wireless debugging on your phone:
- Connect your phone to your computer via USB cable.
- Run `adb usb` from inside the dev container.
- Run `adb tcpip 5037` from inside the dev container.
- Run `adb connect <Phone's IP Address>:5037` from inside the dev container.
- Disconnect the USB cable.
- Run `flutter run`

### Running the App on Your Android Phone
1. After connecting your phone, wait for the app to build (this may take up to 15 minutes for the first build).
2. Once the build is complete, the app will be launched on your phone.
3. You can now make changes to the app and view updates in real-time on your phone.

Please replace `<Phone's IP Address>` with the actual IP address of your phone. If you encounter any issues with the connection, try running `adb connect <Phone's IP Address>:5555` instead.


## Privacy Policy
Link to privacy policy: https://docs.google.com/document/d/1vsbooZi9PIiVIMaLts2wv0tODEJafCaRT41zsENYN3I/edit

Expand Down
72 changes: 30 additions & 42 deletions noticeboard/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
Expand All @@ -21,59 +22,46 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
namespace 'com.img.noticeboard'
compileSdk 34
ndkVersion flutter.ndkVersion

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

android {
compileSdkVersion 33
kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.img.noticeboard"
minSdkVersion 19
targetSdkVersion 31
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
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 {
signingConfig signingConfigs.release
}
}

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
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:29.0.3')
implementation 'com.google.firebase:firebase-analytics'
}
dependencies {}
14 changes: 0 additions & 14 deletions noticeboard/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
buildscript {
ext.kotlin_version = '1.9.23'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.google.gms:google-services:4.3.14'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
31 changes: 23 additions & 8 deletions noticeboard/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "com.google.gms.google-services" version "4.3.14" apply false
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

include ":app"

0 comments on commit 4f633df

Please sign in to comment.