formies/Dockerfile

52 lines
1.2 KiB
Docker
Raw Normal View History

2024-12-27 14:05:56 +01:00
# Stage 1: Build Frontend
FROM node:18 as frontend-builder
WORKDIR /frontend
# Copy frontend package files
COPY frontend/package.json frontend/package-lock.json ./
RUN npm install
# Copy the rest of the frontend source code
COPY frontend ./
# Build the frontend
RUN npm run build
# Stage 2: Build Backend
FROM rust:1.72 as backend-builder
WORKDIR /backend
# Copy backend files
COPY backend/Cargo.toml backend/Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
# Copy the actual backend source code
COPY backend/src ./src
RUN cargo build --release
# Stage 3: Combine and Serve
FROM debian:bullseye-slim
# Install dependencies for running Rust binaries
RUN apt-get update && apt-get install -y libssl-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy backend binary
COPY --from=backend-builder /backend/target/release/backend .
# Copy frontend static files
COPY --from=frontend-builder /frontend/public ./frontend/public
# Expose port
EXPOSE 8080
# Run the backend (serving static files and API)
CMD ["./backend"]
#docker build -t your-dockerhub-username/formies-combined .
#docker push your-dockerhub-username/formies-combined:latest