ARG GLEAM_VERSION=v1.15.4 ARG OTP_VERSION=28 # Build stage ------------------------------------------------------------------- FROM ghcr.io/gleam-lang/gleam:${GLEAM_VERSION}-erlang-alpine AS builder # Add missing packages RUN apk update && apk upgrade RUN apk add git # since there is still a git dep on gcourier RUN apk add build-base # because sqlight uses a NIF # Add project code COPY ./ /build/server WORKDIR /build/server # Download dependencies RUN gleam deps download # Compile the server code RUN gleam export erlang-shipment # Runtime stage ----------------------------------------------------------------- FROM docker.io/library/erlang:${OTP_VERSION}-alpine # Copy the compiled server code from the builder stage COPY --from=builder /build/server/build/erlang-shipment /app COPY --from=ghcr.io/amacneil/dbmate:latest /usr/local/bin/dbmate /usr/local/bin/dbmate COPY ./db/migrations/ /app/migrations # Make sure these directories exist RUN mkdir /data # Set up the entrypoint WORKDIR /app # Set environment variables ENV PORT=3000 ENV DATABASE_URL=sqlite:/data/database.sqlite3 RUN echo '#!/bin/sh' > /app/entrypoint_.sh && \ echo 'dbmate --url $DATABASE_URL --migrations-dir "/app/migrations" up' >> /app/entrypoint_.sh && \ echo '/app/entrypoint.sh run' >> /app/entrypoint_.sh && \ chmod +x /app/entrypoint_.sh VOLUME /data ENTRYPOINT ["/app/entrypoint_.sh"]