feat: implement multi-stage Docker build for TypeScript and Python and added label org.opencontainers.image.source

This commit is contained in:
Miguel Oliveira
2025-06-09 19:05:20 -03:00
parent d192ddc714
commit f39b248b21

View File

@@ -1,5 +1,22 @@
# Use an official Python runtime as a parent image # Stage 1: TypeScript build
FROM python:3.12-slim FROM node:22.16.0-slim AS typescript-builder
# Set working directory
WORKDIR /app
# Copy necessary files for TypeScript build
COPY tsconfig.json ./tsconfig.json
COPY src/js ./src/js
# Install TypeScript globally
RUN npm install -g typescript
# Compile TypeScript
RUN tsc
# Stage 2: Final image
FROM python:3.12-slim AS python-builder
LABEL org.opencontainers.image.source="https://github.com/Xoconoch/spotizerr"
# Set the working directory in the container # Set the working directory in the container
WORKDIR /app WORKDIR /app
@@ -10,28 +27,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gosu \ gosu \
git \ git \
ffmpeg \ ffmpeg \
nodejs \
npm \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy requirements file
COPY requirements.txt .
# Install Python dependencies # Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Copy static files generated by TypeScript
COPY --from=typescript-builder /app/static/js ./static/js
# Copy application code # Copy application code
COPY . . COPY . .
# Install TypeScript globally
RUN npm install -g typescript
# Compile TypeScript
# tsc will use tsconfig.json from the current directory (/app)
# It will read from /app/src/js and output to /app/static/js
RUN tsc
# Create necessary directories with proper permissions # Create necessary directories with proper permissions
RUN mkdir -p downloads data/config data/creds data/watch data/history logs/tasks && \ RUN mkdir -p downloads data/config data/creds data/watch data/history logs/tasks && \
chmod -R 777 downloads data logs chmod -R 777 downloads data logs