From cad44a0f12f79782190302575b5dfa897aec60e2 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 3 May 2024 21:15:34 +0600 Subject: [PATCH] Cd/docker linux ar (#1468) * cd: use docker buildx * cd: use linux host for linux arm instead of macos m1 m1 doesn't support nested virtualization. (Apple truly sucks) * cd: don't specify arch in Dockerfile * cd: use custom Dockerfile from ubuntu instead of flutter image * cd: add setup java for android * cd: add flutter distributor pre-built docker image for arm * cd: save me from this cursed arm build * cd: ?? * cd: ?? * cd: use docker build --- .dockerignore | 2 + .github/Dockerfile | 23 +++---- .github/Dockerfile.flutter_distributor | 23 +++++++ .github/workflows/spotube-release-binary.yml | 69 ++++++++++++++------ 4 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 .github/Dockerfile.flutter_distributor diff --git a/.dockerignore b/.dockerignore index 55fee41a5..ddfd15179 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,5 @@ build dist .dart_tool .idea +.github +.git \ No newline at end of file diff --git a/.github/Dockerfile b/.github/Dockerfile index e4dacb0e9..007d1a6e7 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -1,32 +1,27 @@ ARG FLUTTER_VERSION -ARG BUILD_VERSION -FROM --platform=arm64 fischerscode/flutter-sudo:${FLUTTER_VERSION} +FROM --platform=linux/arm64 krtirtho/flutter_distributor_arm64:${FLUTTER_VERSION} -WORKDIR /app +ARG BUILD_VERSION -# Install dependencies -RUN sudo apt-get update &&\ - sudo apt-get install -y tar clang cmake ninja-build pkg-config libgtk-3-dev make python3-pip python3-setuptools desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace fuse libunwind-dev locate patchelf gir1.2-appindicator3-0.1 libappindicator3-1 libappindicator3-dev libsecret-1-0 libjsoncpp25 libsecret-1-dev libjsoncpp-dev libnotify-bin libnotify-dev mpv libmpv-dev rpm &&\ - sudo rm -rf /var/lib/apt/lists/* +WORKDIR /app COPY . . -RUN sudo chown -R $(whoami) /app +RUN chown -R $(whoami) /app RUN flutter pub get &&\ flutter config --enable-linux-desktop &&\ flutter pub get &&\ dart run build_runner build --delete-conflicting-outputs -RUN dart pub global activate flutter_distributor &&\ - alias dpkg-deb="dpkg-deb --Zxz" &&\ - flutter_distributor package --platform=linux --targets=deb &&\ - flutter_distributor package --platform=linux --targets=rpm +RUN alias dpkg-deb="dpkg-deb --Zxz" &&\ + flutter_distributor package --platform=linux --targets=deb RUN make tar VERSION=${BUILD_VERSION} ARCH=arm64 PKG_ARCH=aarch64 RUN mv build/spotube-linux-*-aarch64.tar.xz dist/ &&\ - mv dist/**/spotube-*-linux.deb dist/Spotube-linux-aarch64.deb &&\ - mv dist/**/spotube-*-linux.rpm dist/Spotube-linux-aarch64.rpm \ No newline at end of file + mv dist/**/spotube-*-linux.deb dist/Spotube-linux-aarch64.deb + +CMD [ "sleep", "5000000" ] \ No newline at end of file diff --git a/.github/Dockerfile.flutter_distributor b/.github/Dockerfile.flutter_distributor new file mode 100644 index 000000000..952b9158e --- /dev/null +++ b/.github/Dockerfile.flutter_distributor @@ -0,0 +1,23 @@ +FROM --platform=linux/arm64 ubuntu:22.04 + +ARG FLUTTER_VERSION + +RUN apt-get clean &&\ + apt-get update &&\ + apt-get install -y bash curl file git unzip xz-utils zip libglu1-mesa cmake tar clang ninja-build pkg-config libgtk-3-dev make python3-pip python3-setuptools desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace fuse libunwind-dev locate patchelf gir1.2-appindicator3-0.1 libappindicator3-1 libappindicator3-dev libsecret-1-0 libjsoncpp25 libsecret-1-dev libjsoncpp-dev libnotify-bin libnotify-dev mpv libmpv-dev rpm && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /home/flutter + +RUN git clone https://github.com/flutter/flutter.git -b ${FLUTTER_VERSION} --single-branch flutter-sdk + +RUN flutter-sdk/bin/flutter precache + +RUN flutter-sdk/bin/flutter config --no-analytics + +ENV PATH="$PATH:/home/flutter/flutter-sdk/bin" +ENV PATH="$PATH:/home/flutter/flutter-sdk/bin/cache/dart-sdk/bin" +ENV PATH="$PATH:/home/flutter/.pub-cache/bin" +ENV PUB_CACHE="/home/flutter/.pub-cache" + +RUN dart pub global activate flutter_distributor \ No newline at end of file diff --git a/.github/workflows/spotube-release-binary.yml b/.github/workflows/spotube-release-binary.yml index c77531550..c7fcbf446 100644 --- a/.github/workflows/spotube-release-binary.yml +++ b/.github/workflows/spotube-release-binary.yml @@ -207,35 +207,36 @@ jobs: limit-access-to-actor: true linux_arm: - runs-on: macos-14 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Get current date + id: date + run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - - name: Install Docker - run: brew install --cask docker + - name: Install Dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y pkg-config make python3-pip python3-setuptools - name: Replace pubspec version and BUILD_VERSION Env (nightly) if: ${{ inputs.channel == 'nightly' }} run: | - brew install yq + curl -sS https://webi.sh/yq | sh yq -i '.version |= sub("\+\d+", "+${{ inputs.channel }}.")' pubspec.yaml yq -i '.version += strenv(GITHUB_RUN_NUMBER)' pubspec.yaml echo "BUILD_VERSION=${{ inputs.version }}+${{ inputs.channel }}.${{ github.run_number }}" >> $GITHUB_ENV - - name: BUILD_VERSION Env (stable) if: ${{ inputs.channel == 'stable' }} run: | echo "BUILD_VERSION=${{ inputs.version }}" >> $GITHUB_ENV - - name: Get current date - id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - - - name: Replace Version in files - run: | - sed -i '' 's|%{{APPDATA_RELEASE}}%||' linux/com.github.KRTirtho.Spotube.appdata.xml - - name: Create Stable .env if: ${{ inputs.channel == 'stable' }} run: echo '${{ secrets.DOTENV_RELEASE }}' > .env @@ -244,20 +245,42 @@ jobs: if: ${{ inputs.channel == 'nightly' }} run: echo '${{ secrets.DOTENV_NIGHTLY }}' > .env - - name: Build Linux Arm + - name: Replace Version in files + run: | + sed -i 's|%{{APPDATA_RELEASE}}%||' linux/com.github.KRTirtho.Spotube.appdata.xml + + - name: Build Binaries (stable) + if: ${{ inputs.channel == 'stable' }} + run: | + docker buildx build --platform=linux/arm64 -f .github/Dockerfile . --build-arg FLUTTER_VERSION=${{env.FLUTTER_VERSION}} --build-arg BUILD_VERSION=${{env.BUILD_VERSION}} -t krtirtho/spotube_linux_arm:latest --load + + - name: Build Binaries (nightly) + if: ${{ inputs.channel == 'nightly' }} run: | - docker build -t spotube-linux-arm -f .github/Dockerfile . --build-arg BUILD_VERSION=${{ env.BUILD_VERSION }} --build-arg FLUTTER_VERSION=${{ env.FLUTTER_VERSION }} - docker create --name spotube-linux-arm spotube-linux-arm - docker cp spotube-linux-arm:/app/dist . - docker rm -f spotube-linux-arm + docker buildx build --platform=linux/arm64 -f .github/Dockerfile . --build-arg FLUTTER_VERSION=${{env.FLUTTER_VERSION}} --build-arg BUILD_VERSION=nightly -t krtirtho/spotube_linux_arm:latest --load + - name: Copy the built packages + run: | + docker images ls + docker create --name spotube_linux_arm krtirtho/spotube_linux_arm:latest + docker cp spotube_linux_arm:/app/dist/ dist/ + + - uses: actions/upload-artifact@v3 + if: ${{ inputs.channel == 'stable' }} + with: + if-no-files-found: error + name: Spotube-Release-Binaries + path: | + dist/Spotube-linux-aarch64.deb + dist/spotube-linux-${{ env.BUILD_VERSION }}-aarch64.tar.xz + - uses: actions/upload-artifact@v3 + if: ${{ inputs.channel == 'nightly' }} with: if-no-files-found: error name: Spotube-Release-Binaries path: | dist/Spotube-linux-aarch64.deb - dist/Spotube-linux-aarch64.rpm dist/spotube-linux-nightly-aarch64.tar.xz - name: Debug With SSH When fails @@ -266,7 +289,6 @@ jobs: with: limit-access-to-actor: true - android: runs-on: ubuntu-latest steps: @@ -275,6 +297,13 @@ jobs: with: cache: true flutter-version: ${{ env.FLUTTER_VERSION }} + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + cache: 'gradle' + check-latest: true - name: Install Dependencies run: |