# === Build ===
FROM node:lts AS builder

WORKDIR /app

COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn ./.yarn

RUN yarn install --immutable
COPY . .

ARG COMMIT_SHA=unknown
ARG API_BASE_URL
ARG TAURI_SIGNING_PRIVATE_KEY

ENV COMMIT_SHA=$COMMIT_SHA \
    API_BASE_URL=$API_BASE_URL \
    TAURI_SIGNING_PRIVATE_KEY=$TAURI_SIGNING_PRIVATE_KEY \
    TAURI_SIGNING_PRIVATE_KEY_PASSWORD=

RUN apt update && apt install -y --no-install-recommends \
    nsis \
    clang \
    lld \
    llvm \
    && rm -rf /var/lib/apt/lists/*

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

ENV PATH=/root/.cargo/bin:$PATH

RUN rustup target add x86_64-pc-windows-msvc

RUN cargo install --locked cargo-xwin

RUN yarn tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc

RUN node scripts/generate-updater.mjs

# === Artifacts ===
FROM scratch AS artifacts

COPY --from=builder /app/updater.json ./artifacts
COPY --from=builder /app/src-tauri/target/x86_64-pc-windows-msvc/release/bundle/nsis/ ./artifacts

CMD ["true"]
