# dev build
FROM ghcr.io/immich-app/base-server-dev:202606161235@sha256:9f88b07acc8b7bf37a1dd3d5a19193f664443eaaab4e08e9f9341414c5e4b23f AS dev


COPY --from=ghcr.io/jdx/mise:2026.6.10@sha256:f57ac375a262f52f8ac3f9101348dbff2187d5e4b59612154f2f2808dbe46ef6 /usr/local/bin/mise /usr/local/bin/mise

RUN echo "devdir=/buildcache/node-gyp" >> /usr/local/etc/npmrc && \
  echo "store-dir=/buildcache/pnpm-store" >> /usr/local/etc/npmrc && \
  echo "cache-dir=/buildcache/pnpm-cache" >> /usr/local/etc/npmrc && \
  echo "# Retry configuration - default is 2" >> /usr/local/etc/npmrc && \
  echo "fetch-retries=5" >> /usr/local/etc/npmrc && \
  mkdir -p /buildcache/pnpm-store /buildcache/pnpm-cache /buildcache/node-gyp && \
  chmod -R o+rw /buildcache

ENV CI=1
ENV PNPM_HOME=/buildcache/pnpm-store
ENV MISE_DATA_DIR=/buildcache/mise
ENV MISE_TRUSTED_CONFIG_PATHS=/usr/src/app/mise.toml
ENV PATH="${MISE_DATA_DIR}/shims:${PATH}:/usr/src/app/server/bin:/usr/src/app/web/bin"
ENV IMMICH_ENV=development
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV NVIDIA_VISIBLE_DEVICES=all

WORKDIR /usr/src/app

ENTRYPOINT ["tini", "--", "/bin/bash", "-c"]

FROM dev AS dev-container-server

RUN apt-get update --allow-releaseinfo-change && \
  apt-get install inetutils-ping openjdk-21-jre-headless \
  vim nano curl \
  -y --no-install-recommends --fix-missing

RUN mkdir -p /workspaces && \
  ln -s /usr/src/app /workspaces/immich

COPY --chmod=755 ../.devcontainer/server/*.sh /immich-devcontainer/

WORKDIR /workspaces/immich

FROM dev-container-server AS dev-container-mobile
USER root
# Enable multiarch for arm64 if necessary
RUN if [ "$(dpkg --print-architecture)" = "arm64" ]; then \
  dpkg --add-architecture amd64 && \
  apt-get update && \
  apt-get install -y --no-install-recommends \
  gnupg \
  qemu-user-static \
  libc6:amd64 \
  libstdc++6:amd64 \
  libgcc1:amd64; \
  else \
  apt-get update && \
  apt-get install -y --no-install-recommends \
  gnupg; \
  fi

# Flutter SDK
# https://flutter.dev/docs/development/tools/sdk/releases?tab=linux
ENV FLUTTER_CHANNEL="stable"
ENV FLUTTER_VERSION="3.35.7"
ENV FLUTTER_HOME=/flutter
ENV PATH=${PATH}:${FLUTTER_HOME}/bin

# Flutter SDK
RUN mkdir -p ${FLUTTER_HOME} \
  && curl -C - --output flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/${FLUTTER_CHANNEL}/linux/flutter_linux_${FLUTTER_VERSION}-${FLUTTER_CHANNEL}.tar.xz \
  && tar -xf flutter.tar.xz --strip-components=1 -C ${FLUTTER_HOME} \
  && rm flutter.tar.xz \
  && chown -R node ${FLUTTER_HOME} \
  && git config --global --add safe.directory ${FLUTTER_HOME}


RUN wget -qO- https://dcm.dev/pgp-key.public | gpg --dearmor -o /usr/share/keyrings/dcm.gpg \
  && echo 'deb [signed-by=/usr/share/keyrings/dcm.gpg arch=amd64] https://dcm.dev/debian stable main' | tee /etc/apt/sources.list.d/dart_stable.list \
  && apt-get update \
  && apt-get install dcm -y

RUN dart --disable-analytics
