Skip to content

Commit

Permalink
Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Oct 16, 2024
1 parent 37c11f6 commit ede4073
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 29 deletions.
67 changes: 57 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ on:
schedule:
- cron: '0 0 * * 1'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
# native build on desktop
desktop:
strategy:
matrix:
os: [ubuntu-latest]
include:
- host: linux
image: ubuntu-latest

runs-on: ${{ matrix.os }}
name: desktop/${{ matrix.os }}
runs-on: ${{ matrix.image }}
name: desktop/${{ matrix.host }}

steps:
- name: Checkout
Expand All @@ -35,10 +42,14 @@ jobs:
channel: stable
cache: true

- name: Install doit
uses: awalsh128/cache-apt-pkgs-action@v1.4.2
- name: Install python
uses: actions/setup-python@v5
with:
packages: python3-doit
python-version: 3.11

- name: Install doit
run: |
pip install doit
- name: Run dart analyzer
run: |
Expand All @@ -48,13 +59,22 @@ jobs:
run: |
doit test
# build for android on different hosts
android:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- host: linux
image: ubuntu-latest

runs-on: ${{ matrix.os }}
name: android/${{ matrix.os }}
- host: macos
image: macos-latest

- host: windows
image: windows-latest

runs-on: ${{ matrix.image }}
name: android/${{ matrix.host }}

steps:
- name: Checkout
Expand Down Expand Up @@ -97,9 +117,36 @@ jobs:
run: |
doit build:apk variant=release
# build for different targets on different hosts using docker
docker:
strategy:
matrix:
include:
- host: linux
target: android
image: ubuntu-latest

runs-on: ${{ matrix.image }}
name: docker/${{ matrix.target }}-${{ matrix.host }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build
if: runner.os != 'Windows'
run: |
./script/docker_build.py
- name: Build (Windows)
if: runner.os == 'Windows'
run: |
.\script\docker_build.bat
# build and publish github release
release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [desktop, android]
needs: [desktop, android, docker]

runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 5 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ android {
abortOnError false
}

signingConfigs {
release {
if (System.getenv("SIGNING_STORE_FILE") != null) {

if (System.getenv("SIGNING_STORE_FILE") != null) {
signingConfigs {
release {
storeFile file(System.getenv("SIGNING_STORE_FILE"))
storePassword System.getenv("SIGNING_STORE_PASSWORD")
keyAlias System.getenv("SIGNING_KEY_ALIAS")
Expand All @@ -110,7 +111,7 @@ android {
if (System.getenv("SIGNING_STORE_FILE") != null) {
signingConfig signingConfigs.release
} else {
signingConfig = signingConfigs.debug
signingConfig signingConfigs.debug
}
}
}
Expand Down
28 changes: 24 additions & 4 deletions docs/building/build_project.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
# Build project

First follow instructions to set up environment:
## Build with docker

The easiest way to build project is to use our pre-built [docker images](https://github.com/roc-streaming/dockerfiles) with Flutter SDK. In this case you don't need to set up build environment by yourself.

First install Docker CE ([Linux](https://docs.docker.com/engine/install/)) or Docker Desktop ([macOS](https://docs.docker.com/desktop/install/mac-install/), [Windows](https://docs.docker.com/desktop/install/windows-install/)). In case of Docker Desktop, don't forget to open GUI and start engine.

Then open terminal in project root and run:

* On macOS and Linux:

./script/docker_build.py

* On Windows:

.\script\docker_build.bat

After building, you can find APK here:

dist/android/release/roc-droid-<version>.apk

## Build without docker

First follow instructions to set up build environment:

* [Windows setup](./windows_setup.md)
* [macOS and Linux setup](./macos_linux_setup.md)
* [Windows setup](./windows_setup.md)

Then open terminal in project root and run:

Expand All @@ -12,5 +34,3 @@ Then open terminal in project root and run:
After building, you can find APK here:

dist/android/release/roc-droid-<version>.apk

You can upload it to device and tap to install.
23 changes: 13 additions & 10 deletions docs/building/macos_linux_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Install Flutter

* Installing Flutter using `brew` (macOS or Linux):
* Installing Flutter using `brew` (macOS):

* `brew install --cask flutter`

Expand All @@ -18,7 +18,7 @@

## Install Android Studio

* Installing Android Studio using `brew` (macOS or Linux):
* Installing Android Studio using `brew` (macOS):

* `brew install --cask android-studio`

Expand Down Expand Up @@ -50,13 +50,10 @@

If you don't use Android Studio, you can install Android SDK standalone.

* Installing Android SDK using `brew` (macOS or Linux):

* `brew install --cask android-sdk`

* Installing Android SDK using `snap` (Ubuntu):

* `sudo snap install androidsdk`
* `androidsdk --install "cmdline-tools;latest"`

* Installing manually: <https://thanhtunguet.info/posts/how-to-install-android-sdk-android-cmdline-tools-without-android-studio/>

Expand All @@ -80,15 +77,21 @@ For Android build, we require **JDK 17** or later.

* Configure Android Studio path (if you've installed it):

* `flutter config --android-studio-dir="/opt/android-studio"` (specify correct directory)
* `flutter config --android-studio-dir="/path/to/android/studio"`

(specify correct directory, e.g. `/Applications/Android Studio.app`, `/opt/android-studio`, `/snap/android-studio/current/android-studio`)

* Configure Android SDK path (if you've installed standalone sdk):
* Configure Android SDK path (if you use standalone sdk):

* `flutter config --android-sdk="/opt/android-studio"` (specify correct directory)
* `flutter config --android-sdk="/path/to/android/sdk"`

(specify correct directory, e.g. `$HOME/Library/Android`, `$HOME/AndroidSDK`)

* Configure JDK path:

* `flutter config --jdk-dir "/usr/lib/jvm/java-17-openjdk-amd64"` (specify correct directory)
* `flutter config --jdk-dir "/path/to/jdk"`

(specify correct directory, e.g. `/opt/homebrew/opt/openjdk@17/`, `/usr/lib/jvm/java-17-openjdk-amd64`)

* Run: `flutter doctor --android-licenses` (we agree to all license terms)

Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ nav:
- Agent: architecture/agent.md
- Building:
- Build project: building/build_project.md
- Windows setup: building/windows_setup.md
- macOS and Linux setup: building/macos_linux_setup.md
- Windows setup: building/windows_setup.md
- Development:
- Automation: development/automation.md
- Testing: development/testing.md
Expand Down
2 changes: 2 additions & 0 deletions script/docker_build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -ExecutionPolicy Unrestricted -File "%~dp0\docker_build.ps1" %*
89 changes: 89 additions & 0 deletions script/docker_build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
param (
[ValidateSet("android")]
[string]$Target = "android"
)

function Project-Version {
$content = Get-Content -Path "pubspec.yaml" -Raw
$match = [regex]::Match($content, "^version:\s*(\S+)\s*$", "Multiline")
return $match.Groups[1].Value
}

function Print-Msg ($msg) {
Write-Host "$msg" -ForegroundColor Blue
}

function Print-Err ($msg) {
Write-Host "$msg" -ForegroundColor Red
}

function Run-Cmd ($cmd) {
Write-Host ($cmd -join " ")

$proc = Start-Process -FilePath $cmd[0] -ArgumentList $cmd[1..$cmd.Length] `
-PassThru -Wait -NoNewWindow

if ($proc.ExitCode -ne 0) {
Print-Err "Command failed with code $($proc.ExitCode)"
Exit 1
}
}

docker info >$null 2>&1
if (-not $?) {
Print-Err "Docker Engine is not running"
Exit 1
}

Set-Location -Path (
Split-Path -Parent (Split-Path -Parent (Resolve-Path $PSScriptRoot)))

$cwd = Get-Location

if ($Target -eq "android") {
$workDir = "/root/build" # container
$cacheDirs = @{
# host: container
"${cwd}\build\dockercache\pub" = "/root/.pub-cache"
"${cwd}\build\dockercache\gradle" = "/root/.gradle"
"${cwd}\build\dockercache\android" = "/root/.android/cache"
}
}

$dockerCmd = @(
"docker", "run",
"--rm", "-t",
"-w", $workDir,
"-v", "${cwd}:${workDir}"
)

foreach ($pair in $cacheDirs.GetEnumerator()) {
$hostDir = $pair.Key
$containerDir = $pair.Value
New-Item -Path $hostDir -ItemType Directory -Force | Out-Null
$dockerCmd += @(
"-v", "${hostDir}:${containerDir}"
)
}

$dockerCmd += @(
"rocstreaming/env-flutter:${Target}"
)

if ($Target -eq "android") {
$dockerCmd += @(
"flutter", "build", "apk", "--release"
)
}

Print-Msg "Running ${Target} build in docker"
Run-Cmd $dockerCmd

if ($Target -eq "android") {
$appType = "apk"
$appFile = "roc-droid-$(Project-Version).apk"
}

Print-Msg
Print-Msg "Copied ${Target} ${appType} to dist\${Target}\release\${appFile}"
Get-ChildItem "dist\${Target}\release"
Loading

0 comments on commit ede4073

Please sign in to comment.