FROM ghcr.io/gleam-lang/gleam:v1.14.0-erlang-alpine

RUN apk add --no-cache elixir git libstdc++ openssl

WORKDIR /app

COPY gleam.toml manifest.toml ./
COPY src/ ./src/

RUN gleam deps download && \
    gleam build --target erlang && \
    adduser -D -H spasteg && \
    chown -R spasteg:spasteg /app

EXPOSE 3000

USER spasteg

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1

ENTRYPOINT ["gleam", "run", "--target", "erlang", "--", "--no-halt"]
