From b154d08c243ca0099ef43dc8b1ea74beaf24f9dd Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Thu, 11 Dec 2025 14:46:31 +0100 Subject: [PATCH] Update Docker build and GitHub actions to always build core libs (#1404) --- .github/actions/build-android-app/action.yml | 27 +++++++- .../build-browser-extension/action.yml | 34 ++++++++- .../actions/build-core-libraries/action.yml | 69 +++++++++++++++++++ .github/actions/build-ios-app/action.yml | 27 +++++++- .github/workflows/browser-extension-build.yml | 45 ++---------- .github/workflows/e2e-tests.yml | 40 ++++++++++- .github/workflows/mobile-app-build.yml | 6 ++ apps/mobile-app/android/build.sh | 21 ++++++ apps/mobile-app/ios/build-and-submit.sh | 16 +++++ apps/server/AliasVault.Client/Dockerfile | 22 ++++++ dockerfiles/all-in-one/Dockerfile | 24 ++++++- 11 files changed, 285 insertions(+), 46 deletions(-) create mode 100644 .github/actions/build-core-libraries/action.yml diff --git a/.github/actions/build-android-app/action.yml b/.github/actions/build-android-app/action.yml index 1c0a45cda..5e6815549 100644 --- a/.github/actions/build-android-app/action.yml +++ b/.github/actions/build-android-app/action.yml @@ -17,12 +17,37 @@ inputs: runs: using: "composite" steps: - - uses: actions/setup-node@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' cache-dependency-path: apps/mobile-app/package-lock.json + - name: Build core libraries + shell: bash + run: | + cd ./core + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + + - name: Verify core library distribution + shell: bash + run: | + TARGET_DIRS=( + "apps/mobile-app/utils/dist/core/identity-generator" + "apps/mobile-app/utils/dist/core/password-generator" + "apps/mobile-app/utils/dist/core/models" + "apps/mobile-app/utils/dist/core/vault" + ) + for dir in "${TARGET_DIRS[@]}"; do + if [ ! -d "$dir" ]; then + echo "Error: Directory $dir does not exist" + exit 1 + fi + done + echo "Core library distribution verified" + - name: Install dependencies run: npm ci shell: bash diff --git a/.github/actions/build-browser-extension/action.yml b/.github/actions/build-browser-extension/action.yml index b2c52f864..bb83086f2 100644 --- a/.github/actions/build-browser-extension/action.yml +++ b/.github/actions/build-browser-extension/action.yml @@ -12,12 +12,44 @@ inputs: runs: using: "composite" steps: - - uses: actions/setup-node@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' cache-dependency-path: apps/browser-extension/package-lock.json + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + with: + workspaces: core/rust + + - name: Install wasm-pack + shell: bash + run: cargo install wasm-pack --locked + + - name: Build core libraries + shell: bash + run: | + cd ./core + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + + - name: Verify core library distribution + shell: bash + run: | + # Verify critical rust WASM files exist + if [ ! -f "apps/browser-extension/src/utils/dist/core/rust/aliasvault_core_bg.wasm" ]; then + echo "Error: Rust WASM files not found in browser extension" + exit 1 + fi + echo "Core library distribution verified" + - name: Install dependencies run: npm ci shell: bash diff --git a/.github/actions/build-core-libraries/action.yml b/.github/actions/build-core-libraries/action.yml new file mode 100644 index 000000000..7dfcdb85a --- /dev/null +++ b/.github/actions/build-core-libraries/action.yml @@ -0,0 +1,69 @@ +name: "Build Core Libraries" +description: "Builds and distributes all core libraries including TypeScript packages and Rust WASM" +inputs: + working-directory: + description: "Working directory (default: repository root)" + required: false + default: "." + +runs: + using: "composite" + steps: + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + + - name: Install wasm-pack + shell: bash + run: cargo install wasm-pack --locked + + - name: Build and distribute core libraries + shell: bash + working-directory: ${{ inputs.working-directory }} + run: | + cd ./core + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + + - name: Verify core library distribution + shell: bash + working-directory: ${{ inputs.working-directory }} + run: | + # Check if files exist and were recently modified + TARGET_DIRS=( + "apps/browser-extension/src/utils/dist/core/identity-generator" + "apps/browser-extension/src/utils/dist/core/password-generator" + "apps/browser-extension/src/utils/dist/core/models" + "apps/browser-extension/src/utils/dist/core/vault" + "apps/browser-extension/src/utils/dist/core/rust" + "apps/mobile-app/utils/dist/core/identity-generator" + "apps/mobile-app/utils/dist/core/password-generator" + "apps/mobile-app/utils/dist/core/models" + "apps/mobile-app/utils/dist/core/vault" + ) + + for dir in "${TARGET_DIRS[@]}"; do + if [ ! -d "$dir" ]; then + echo "Warning: Directory $dir does not exist (may be expected for some builds)" + continue + fi + + # Check if files were modified in the last 10 minutes + find "$dir" -type f -mmin -10 | grep -q . || { + echo "Warning: Files in $dir were not recently modified" + } + done + + # Verify critical rust WASM files exist + if [ ! -f "apps/browser-extension/src/utils/dist/core/rust/aliasvault_core_bg.wasm" ]; then + echo "Error: Rust WASM files not found in browser extension" + exit 1 + fi + + echo "Core library distribution verified" diff --git a/.github/actions/build-ios-app/action.yml b/.github/actions/build-ios-app/action.yml index f1468fde8..3c019b963 100644 --- a/.github/actions/build-ios-app/action.yml +++ b/.github/actions/build-ios-app/action.yml @@ -17,12 +17,37 @@ inputs: runs: using: "composite" steps: - - uses: actions/setup-node@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' cache-dependency-path: apps/mobile-app/package-lock.json + - name: Build core libraries + shell: bash + run: | + cd ./core + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + + - name: Verify core library distribution + shell: bash + run: | + TARGET_DIRS=( + "apps/mobile-app/utils/dist/core/identity-generator" + "apps/mobile-app/utils/dist/core/password-generator" + "apps/mobile-app/utils/dist/core/models" + "apps/mobile-app/utils/dist/core/vault" + ) + for dir in "${TARGET_DIRS[@]}"; do + if [ ! -d "$dir" ]; then + echo "Error: Directory $dir does not exist" + exit 1 + fi + done + echo "Core library distribution verified" + - name: Install dependencies run: npm ci shell: bash diff --git a/.github/workflows/browser-extension-build.yml b/.github/workflows/browser-extension-build.yml index 7da8288c3..e4971e68c 100644 --- a/.github/workflows/browser-extension-build.yml +++ b/.github/workflows/browser-extension-build.yml @@ -12,49 +12,16 @@ concurrency: cancel-in-progress: true jobs: - build-shared-libraries: + build-core-libraries: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Build and distribute core libraries - run: | - cd ./core - chmod +x build-and-distribute.sh - ./build-and-distribute.sh - - - name: Verify core library distribution - run: | - # Check if files exist and were recently modified - TARGET_DIRS=( - "apps/browser-extension/src/utils/dist/core/identity-generator" - "apps/browser-extension/src/utils/dist/core/password-generator" - "apps/browser-extension/src/utils/dist/core/models" - "apps/browser-extension/src/utils/dist/core/vault" - ) - - for dir in "${TARGET_DIRS[@]}"; do - if [ ! -d "$dir" ]; then - echo "❌ Directory $dir does not exist" - exit 1 - fi - - # Check if files were modified in the last 5 minutes - find "$dir" -type f -mmin -5 | grep -q . || { - echo "❌ Files in $dir were not recently modified" - exit 1 - } - done - - echo "✅ Shared library distribution verified" + - name: Build Core Libraries + uses: ./.github/actions/build-core-libraries build-chrome-extension: - needs: build-shared-libraries + needs: build-core-libraries runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -65,7 +32,7 @@ jobs: browser: chrome build-firefox-extension: - needs: build-shared-libraries + needs: build-core-libraries runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -76,7 +43,7 @@ jobs: browser: firefox build-edge-extension: - needs: build-shared-libraries + needs: build-core-libraries runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 66b0af77f..8efa919fb 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -105,7 +105,26 @@ jobs: with: node-version: '20' - - name: Install dependencies + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + with: + workspaces: core/rust + + - name: Install wasm-pack + run: cargo install wasm-pack --locked + + - name: Build core libraries + run: | + cd ./core + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + + - name: Install .NET dependencies working-directory: apps/server run: dotnet workload install wasm-tools @@ -158,6 +177,25 @@ jobs: cache: 'npm' cache-dependency-path: apps/browser-extension/package-lock.json + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + with: + workspaces: core/rust + + - name: Install wasm-pack + run: cargo install wasm-pack --locked + + - name: Build core libraries + run: | + cd ./core + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + - name: Install .NET dependencies working-directory: apps/server run: dotnet workload install wasm-tools diff --git a/.github/workflows/mobile-app-build.yml b/.github/workflows/mobile-app-build.yml index 4f090778d..8b08b616d 100644 --- a/.github/workflows/mobile-app-build.yml +++ b/.github/workflows/mobile-app-build.yml @@ -99,6 +99,12 @@ jobs: cache: 'npm' cache-dependency-path: apps/mobile-app/package-lock.json + - name: Build core libraries + run: | + cd ../../core + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + - name: Install dependencies run: npm ci diff --git a/apps/mobile-app/android/build.sh b/apps/mobile-app/android/build.sh index ccbf14282..f43a5ffb6 100755 --- a/apps/mobile-app/android/build.sh +++ b/apps/mobile-app/android/build.sh @@ -1,4 +1,25 @@ +#!/usr/bin/env bash + +# ------------------------------------------ +# Build core libraries if needed +# ------------------------------------------ + +CORE_DIR="../../core" +MOBILE_CORE_DIST="../utils/dist/core" + +if [ ! -d "$MOBILE_CORE_DIST/models" ] || [ ! -d "$MOBILE_CORE_DIST/vault" ]; then + echo "Building core libraries..." + pushd "$CORE_DIR" > /dev/null + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + popd > /dev/null + echo "Core libraries built successfully" +fi + +# ------------------------------------------ # Build Android app in release mode +# ------------------------------------------ + ./gradlew bundleRelease # Open directory that should contain the .aab file if build was successful diff --git a/apps/mobile-app/ios/build-and-submit.sh b/apps/mobile-app/ios/build-and-submit.sh index 510a9d86b..8551a303b 100755 --- a/apps/mobile-app/ios/build-and-submit.sh +++ b/apps/mobile-app/ios/build-and-submit.sh @@ -12,6 +12,22 @@ EXPORT_PLIST="$PWD/exportOptions.plist" # Put the fastlane API key in the home directory API_KEY_PATH="$HOME/APPSTORE_CONNECT_FASTLANE.json" +# ------------------------------------------ +# Build core libraries if needed +# ------------------------------------------ + +CORE_DIR="../../../core" +MOBILE_CORE_DIST="../utils/dist/core" + +if [ ! -d "$MOBILE_CORE_DIST/models" ] || [ ! -d "$MOBILE_CORE_DIST/vault" ]; then + echo "Building core libraries..." + pushd "$CORE_DIR" > /dev/null + chmod +x build-and-distribute.sh + ./build-and-distribute.sh + popd > /dev/null + echo "Core libraries built successfully" +fi + # ------------------------------------------ if [ ! -f "$API_KEY_PATH" ]; then diff --git a/apps/server/AliasVault.Client/Dockerfile b/apps/server/AliasVault.Client/Dockerfile index 0f0321deb..e009f7af6 100644 --- a/apps/server/AliasVault.Client/Dockerfile +++ b/apps/server/AliasVault.Client/Dockerfile @@ -1,6 +1,24 @@ FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base WORKDIR /app +# ============================================ +# Stage: Build core libraries +# ============================================ +FROM node:20-slim AS core-builder + +WORKDIR /src + +# Copy core library source files +COPY core/ ./core/ + +# Build core libraries +RUN cd ./core && \ + chmod +x build-and-distribute.sh && \ + ./build-and-distribute.sh + +# ============================================ +# Stage: Build .NET application +# ============================================ FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS build ARG TARGETARCH ARG BUILD_CONFIGURATION=Release @@ -21,6 +39,10 @@ RUN dotnet workload install wasm-tools # Copy all project files COPY apps/server /src +# Copy built core libraries from core-builder stage +COPY --from=core-builder /src/core/ /src-core/ +RUN cp -r /src-core/apps/server/AliasVault.Client/wwwroot/js/dist/core/* /src/AliasVault.Client/wwwroot/js/dist/core/ 2>/dev/null || true + # Build the Client project WORKDIR "/src/AliasVault.Client" RUN dotnet build "AliasVault.Client.csproj" \ diff --git a/dockerfiles/all-in-one/Dockerfile b/dockerfiles/all-in-one/Dockerfile index d67268079..cbf79b784 100644 --- a/dockerfiles/all-in-one/Dockerfile +++ b/dockerfiles/all-in-one/Dockerfile @@ -1,7 +1,22 @@ # Multi-stage build for AliasVault single container deployment # ============================================ -# Stage 1: Build .NET applications +# Stage 1: Build core libraries +# ============================================ +FROM node:20-slim AS core-builder + +WORKDIR /src + +# Copy core library source files +COPY core/ ./core/ + +# Build core libraries +RUN cd ./core && \ + chmod +x build-and-distribute.sh && \ + ./build-and-distribute.sh + +# ============================================ +# Stage 2: Build .NET applications # ============================================ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS dotnet-builder @@ -16,6 +31,9 @@ WORKDIR /src COPY apps/server/ ./apps/server/ COPY shared/ ./shared/ +# Copy built core libraries from core-builder stage +COPY --from=core-builder /src/core/ ./core/ + # Install required .NET workloads and restore packages once for the entire solution WORKDIR /src/apps/server @@ -56,7 +74,7 @@ RUN find /app -name "*.pdb" -delete && \ find /app -name "web.config" -delete # ============================================ -# Stage 2: Download s6-overlay separately +# Stage 3: Download s6-overlay separately # ============================================ FROM alpine:3.19 AS s6-downloader ARG S6_OVERLAY_VERSION=3.2.0.2 @@ -69,7 +87,7 @@ RUN ARCH="${TARGETARCH}"; \ mv s6-overlay-${ARCH}.tar.xz s6-overlay-arch.tar.xz # ============================================ -# Stage 3: Final runtime image +# Stage 4: Final runtime image # ============================================ FROM mcr.microsoft.com/dotnet/aspnet:9.0-bookworm-slim