80 lines
2.2 KiB
Docker
80 lines
2.2 KiB
Docker
# ---- Stage 1: Build frontend and wokwi-libs ----
|
|
FROM node:20 AS frontend-builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package.json for metadata generation
|
|
COPY package.json .
|
|
RUN npm install --ignore-scripts
|
|
|
|
# Build avr8js
|
|
COPY wokwi-libs/avr8js/ wokwi-libs/avr8js/
|
|
WORKDIR /app/wokwi-libs/avr8js
|
|
RUN npm install --ignore-scripts && npm run build
|
|
|
|
# Build rp2040js
|
|
COPY wokwi-libs/rp2040js/ wokwi-libs/rp2040js/
|
|
WORKDIR /app/wokwi-libs/rp2040js
|
|
RUN npm install --ignore-scripts && npm run build
|
|
|
|
# Build wokwi-elements
|
|
COPY wokwi-libs/wokwi-elements/ wokwi-libs/wokwi-elements/
|
|
WORKDIR /app/wokwi-libs/wokwi-elements
|
|
RUN npm install --ignore-scripts && npm run build
|
|
|
|
# Build frontend and generate metadata
|
|
WORKDIR /app
|
|
COPY frontend/ frontend/
|
|
COPY scripts/ scripts/
|
|
WORKDIR /app/frontend
|
|
# We need tsx available in the path for the metadata script
|
|
RUN npm install --ignore-scripts
|
|
# The metadata script uses eval so we must ensure it can run
|
|
RUN npm run build
|
|
|
|
|
|
# ---- Stage 2: Final Production Image ----
|
|
FROM python:3.12-slim
|
|
|
|
# Install system dependencies, arduino-cli, and nginx
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
curl \
|
|
ca-certificates \
|
|
nginx \
|
|
&& curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh \
|
|
&& mv bin/arduino-cli /usr/local/bin/ \
|
|
&& rm -rf bin \
|
|
&& apt-get purge -y curl \
|
|
&& apt-get autoremove -y \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Initialize arduino-cli and install AVR & RP2040 cores
|
|
RUN arduino-cli core update-index \
|
|
&& arduino-cli core install arduino:avr \
|
|
&& arduino-cli core install rp2040:rp2040
|
|
|
|
WORKDIR /app
|
|
|
|
# Install Python backend dependencies
|
|
COPY backend/requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy backend application code
|
|
COPY backend/app/ ./app/
|
|
|
|
# Setup Nginx configuration
|
|
COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
# Copy built frontend assets from builder stage
|
|
COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html
|
|
|
|
# Copy and configure entrypoint script
|
|
COPY deploy/entrypoint.sh /app/entrypoint.sh
|
|
RUN chmod +x /app/entrypoint.sh
|
|
|
|
# Expose port 80 for the unified web server
|
|
EXPOSE 80
|
|
|
|
CMD ["/app/entrypoint.sh"]
|