ARG K3SCTL_ADAPTER_BASE_IMAGE=oven/bun:1-debian
FROM ${K3SCTL_ADAPTER_BASE_IMAGE}

# Never build the adapter FROM a service image: inherited Docker Desktop labels
# can silently republish old Code Queue ports and mounts.
RUN test -z "${CODE_QUEUE_DATA_DIR:-}" && test "${PORT:-}" != "4222"
ENTRYPOINT []

RUN (command -v curl >/dev/null 2>&1 && command -v ssh >/dev/null 2>&1 && command -v ps >/dev/null 2>&1) \
  || (apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates curl openssh-client procps \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*)

WORKDIR /app/src/components/microservices/k3sctl-adapter
COPY src/components/shared /app/src/components/shared
COPY src/components/microservices/k3sctl-adapter/package.json ./package.json
COPY src/components/microservices/k3sctl-adapter/tsconfig.json ./tsconfig.json
COPY src/components/microservices/k3sctl-adapter/entrypoint.sh ./entrypoint.sh
COPY src/components/microservices/k3sctl-adapter/src ./src
COPY src/components/microservices/k3sctl-adapter/k3s ./k3s
RUN chmod 755 ./entrypoint.sh

EXPOSE 4266
ENTRYPOINT ["./entrypoint.sh"]
CMD ["bun", "--smol", "run", "src/index.ts"]
