ARG dartversion=3.11.2-sdk

# Use latest stable channel SDK.
FROM dart:$dartversion AS build

WORKDIR /app

# Copy app source code (except anything in .dockerignore) and AOT compile app.
COPY ./packages .
RUN ls -laRt
WORKDIR /app/lista_de_la_compra_server
RUN ls -laRt
RUN dart pub get
RUN dart build cli bin/server.dart --output bin/server_out

# Build minimal serving image from AOT-compiled `/server`
# and the pre-built AOT-runtime in the `/runtime/` directory of the base image.
FROM dart:$dartversion

RUN apt-get update
RUN apt-get install -y libsqlite3-dev

COPY --from=build /app/lista_de_la_compra_server/bin/server_out/bundle/bin/server /app/bin/
COPY --from=build /app/lista_de_la_compra_server/bin/server_out/bundle/lib/libsqlite3.so /app/lib/

ENV LD_LIBRARY_PATH=/app/lib

# Start server.
EXPOSE 4545
CMD ["/app/bin/server"]
