2026-01-02 06:18:48 +07:00
|
|
|
FROM python:3.11-slim
|
|
|
|
|
|
2026-01-06 21:38:54 +07:00
|
|
|
# Create a non-root user for security
|
|
|
|
|
RUN useradd --create-home --shell /bin/bash app
|
|
|
|
|
|
|
|
|
|
# Install gcc compiler for C code compilation and other production dependencies
|
2026-01-02 06:18:48 +07:00
|
|
|
RUN apt-get update && \
|
2026-01-06 21:38:54 +07:00
|
|
|
apt-get install -y gcc build-essential curl && \
|
2026-01-02 06:18:48 +07:00
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
# Set working directory
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
feat(assets): optimasi serving gambar (WebP on-the-fly + cache disk)
Arsitektur: upload tetap menyimpan original apa adanya; optimasi terjadi
saat serving — gambar raster di-resize (maks 1600px) + encode WebP
(quality 80), di-generate on-the-fly lalu di-cache di disk.
- config.CACHE_DIR = sibling ASSETS_DIR ('assets-cache'), WAJIB di luar
ASSETS_DIR supaya export_bundle (os.walk tanpa filter) tetap lossless
- services/image_cache.py: varian WebP, cache key path+mtime+size+width,
invalidasi otomatis via mtime, atomic write, fallback original bila gagal
- routes/lessons.py::send_assets: handler (bukan static serve) —
.png/.jpg/.jpeg/.webp/.gif -> varian WebP; .svg & GIF animasi pass-through;
?orig=1 untuk original; ?w= untuk lebar alternatif; ETag + Cache-Control
- Dockerfile: buat /app/assets-cache writable
Test (services/tests/test_asset_cache.py, 20 test): lokasi cache di luar
ASSETS_DIR, cache reuse, invalidasi mtime, passthrough SVG/GIF animasi,
fallback file korup, ETag/304, dan acceptance test — upload -> request ->
export bundle berisi HANYA original tanpa .webp turunan.
2026-10-25 19:19:07 +07:00
|
|
|
# Cache varian WebP asset gambar — WAJIB di luar /app/assets supaya tidak
|
|
|
|
|
# ikut ter-zip saat export bundle (lihat config.py CACHE_DIR).
|
|
|
|
|
RUN mkdir -p /app/assets-cache && chown -R app:app /app/assets-cache
|
|
|
|
|
|
2026-01-02 06:18:48 +07:00
|
|
|
# Copy requirements and install Python dependencies
|
|
|
|
|
COPY requirements.txt .
|
|
|
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
|
2026-09-05 06:55:43 +07:00
|
|
|
# Copy backend application code only with non-root ownership
|
|
|
|
|
COPY --chown=app:app app.py config.py extensions.py gunicorn.conf.py alembic.ini pytest.ini ./
|
|
|
|
|
COPY --chown=app:app routes/ ./routes/
|
|
|
|
|
COPY --chown=app:app services/ ./services/
|
|
|
|
|
COPY --chown=app:app scripts/ ./scripts/
|
|
|
|
|
COPY --chown=app:app migrations/ ./migrations/
|
|
|
|
|
COPY --chown=app:app docs/ ./docs/
|
|
|
|
|
COPY --chown=app:app help/ ./help/
|
|
|
|
|
COPY --chown=app:app compiler/ ./compiler/
|
2026-01-02 06:18:48 +07:00
|
|
|
|
2026-01-06 21:38:54 +07:00
|
|
|
USER app
|
|
|
|
|
|
2026-01-02 06:18:48 +07:00
|
|
|
# Expose port 5000
|
|
|
|
|
EXPOSE 5000
|
|
|
|
|
|
2026-01-06 21:38:54 +07:00
|
|
|
# Run the application with Gunicorn in production mode using config file
|
2026-03-25 09:39:51 +07:00
|
|
|
CMD ["gunicorn", "--config", "gunicorn.conf.py", "app:create_app()"]
|