fix(docker): Build Tailwind CSS in Docker image
The /style.css route 500'd in production because style.css is gitignored and the Dockerfile never produced it: only main.py and templates/ were copied into the image. Mirror the myice Dockerfile by building the CSS in the builder stage: copy the tailwind input files, download the standalone Tailwind CLI (arch-aware for x64/arm64), and compile style.css. The artifact is then copied into the runtime stage. build-css.sh is kept for local dev but not used in Docker because its #!/bin/bash shebang and pipefail are incompatible with alpine's sh.
This commit is contained in:
+13
@@ -23,6 +23,18 @@ RUN apk add --no-cache gcc musl-dev libffi-dev openssl-dev
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Build Tailwind CSS
|
||||
COPY templates/index.html templates/index.html
|
||||
COPY style-input.css tailwind.config.js ./
|
||||
RUN case "$(uname -m)" in \
|
||||
x86_64) arch="x64" ;; \
|
||||
aarch64|arm64) arch="arm64" ;; \
|
||||
*) echo "Unsupported architecture: $(uname -m)"; exit 1 ;; \
|
||||
esac \
|
||||
&& curl -sL "https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.17/tailwindcss-linux-${arch}" -o tailwindcss \
|
||||
&& chmod +x tailwindcss \
|
||||
&& ./tailwindcss -i ./style-input.css -o ./style.css --minify
|
||||
|
||||
#############################################
|
||||
# Final stage
|
||||
#############################################
|
||||
@@ -35,6 +47,7 @@ COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
# Copy application files
|
||||
COPY main.py .
|
||||
COPY templates/ templates/
|
||||
COPY --from=builder /app/style.css ./style.css
|
||||
|
||||
# Change ownership to non-root user
|
||||
RUN chown -R app:app /app
|
||||
|
||||
Reference in New Issue
Block a user