# PUBLIC DOMAIN - NO LICENSE, NO WARRANTY
# Copyright 2025 TimeHexOn & foxhop & russell@unturf
# https://www.permacomputer.com

FROM erlang:27-alpine as builder

WORKDIR /app

# Install rebar3
RUN apk add --no-cache git && \
    wget https://s3.amazonaws.com/rebar3/rebar3 && \
    chmod +x rebar3

# Copy config and get dependencies
COPY rebar.config .
RUN ./rebar3 get-deps

# Copy source code
COPY src ./src

# Compile
RUN ./rebar3 compile

# Runtime stage
FROM erlang:27-alpine

WORKDIR /app

# Install CA certificates for HTTPS
RUN apk add --no-cache ca-certificates

# Copy compiled application
COPY --from=builder /app/_build /app/_build
COPY --from=builder /app/src /app/src

# Run the application
CMD ["sh", "-c", "erl -pa _build/default/lib/*/ebin -noshell -s uncloseai main -s init stop"]
