Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (44 loc) · 1.88 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
ARG GLEAM_VERSION=v1.15.2
# Build stage - compile the application
FROM ghcr.io/gleam-lang/gleam:${GLEAM_VERSION}-erlang AS builder
# Add project code
COPY ./shared /build/shared
COPY ./client /build/client
COPY ./server /build/server
# Install git, just, and wget for resolving dependencies and build tools
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
# Install dependencies for all projects
RUN cd /build/shared && gleam deps download
RUN cd /build/client && gleam deps download
RUN cd /build/server && gleam deps download
# Compile the client code and output to server's static directory
RUN cd /build/client \
&& gleam run -m lustre/dev build app --minify --outdir=/build/server/priv/static
# && gleam run -m lustre/dev build app --outdir=/build/server/priv/static
# Compile the server code
RUN cd /build/server \
&& gleam export erlang-shipment
# Runtime stage - slim image with only what's needed to run
FROM ghcr.io/gleam-lang/gleam:${GLEAM_VERSION}-erlang
# Install runtime dependencies for migrations and build tools
RUN apt-get update && apt-get install -y wget && \
wget -O /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64 && \
chmod +x /usr/local/bin/dbmate && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy the compiled server code from the builder stage
COPY --from=builder /build/server/build/erlang-shipment /app
# Copy the client static assets from the builder stage
COPY --from=builder /build/server/priv/static /app/server/priv/static
# Copy the startup script, justfiles, and database migrations
COPY start.sh /app/start.sh
COPY server/db /app/db
# Set up the entrypoint
WORKDIR /app
RUN chmod +x ./start.sh
# Set environment variables
ENV HOST=0.0.0.0
ENV PORT=8000
# Expose the port the server will run on
EXPOSE 8000
# Run the server
CMD ["./start.sh", "run"]