# Please use this Dockerfile only if
# you want to build an image from source without
# pnpm and Go installed on your dev machine.

# You can build КуСфера using this Dockerfile
# by running following command:
# `docker build -t qsfera/qsfera:custom .`

# In most other cases you might want to run the
# following command instead:
# `make -C qsfera dev-docker`
# It will build a `qsfera/qsfera:dev` image for you
# and use your local pnpm and Go caches and therefore
# is a lot faster than the build steps below.


FROM node:24-alpine AS generate
RUN apk add --no-cache bash make git curl tar && \
	corepack enable && \
	corepack prepare pnpm@9.15.4 --activate

COPY ./ /qsfera/

WORKDIR /qsfera
RUN make node-generate-prod

FROM golang:1.25-alpine AS build
ARG TARGETARCH=arm64
RUN apk add bash make git curl gcc musl-dev libc-dev binutils-gold inotify-tools vips-dev

COPY --from=generate /qsfera /qsfera

WORKDIR /qsfera/qsfera
RUN make release-linux-docker-${TARGETARCH} ENABLE_VIPS=true DIST=/dist

FROM alpine:3.23
ARG TARGETARCH=arm64

RUN apk add --no-cache attr ca-certificates curl mailcap tree vips && \
	echo 'hosts: files dns' >| /etc/nsswitch.conf

LABEL maintainer="QSfera" \
        org.opencontainers.image.title="КуСфера" \
        org.opencontainers.image.vendor="QSfera" \
        org.opencontainers.image.authors="QSfera" \
        org.opencontainers.image.description="КуСфера file-sync and share platform" \
        org.opencontainers.image.licenses="Apache-2.0" \
        org.opencontainers.image.documentation="" \
        org.opencontainers.image.source=""

ENTRYPOINT ["/usr/bin/qsfera"]
CMD ["server"]

COPY --from=build /dist/binaries/qsfera-linux-${TARGETARCH} /usr/bin/qsfera
