# Stage 1: Build the application
FROM rust:latest as builder
# Set the working directory
WORKDIR /app
# Create a new empty shell project to cache dependencies
RUN cargo new --bin goalaim
WORKDIR /app/goalaim
# Copy the source code
COPY src ./src
COPY migrations ./migrations
COPY Cargo.toml ./
COPY Cargo.lock ./
# Build the project in release mode
RUN cargo build --release
# Stage 2: Create the runtime image
FROM ubuntu:latest
# Install necessary packages
RUN apt-get update && apt-get install -y \
ca-certificates \
libpq-dev \
libssl-dev
# Copy the compiled binary from the builder stage
COPY --from=builder /app/goalaim/target/release/goalaim /usr/local/bin/goalaim
# Expose the port specified by the environment variable
ENV PORT 8080
EXPOSE ${PORT}
# Set the binary as the entry point
CMD ["goalaim"]