Commit 6b0d6620 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Rewrite CI test job around a pre-baked Docker Hub image

Every push was paying apt-get + pip install + ffmpeg-download cost fresh,
even with caching helping at the margins. Complete rewrite: Dockerfile.ci
now bakes ffmpeg, libsndfile1, and the full requirements.txt into one image,
built and pushed to Docker Hub by the manual build_ci_image job. The test
job itself no longer does apt-get, pip install, or any download at all - it
just pulls that image and runs pytest directly.

Verified before pushing (no docker available locally to build-test with):
every requirements.txt package that could plausibly need compilation
(tgcrypto, pedalboard, pyrogram, shazamio/shazamio-core) has a prebuilt
manylinux2014_x86_64/cp310 wheel, so no gcc/build-essential is needed in
the image.

Needs DOCKERHUB_USER + DOCKERHUB_TOKEN as CI/CD variables before
build_ci_image can push anywhere - GitLab's own Container Registry isn't
available on this instance (confirmed earlier), Docker Hub is (this runner
already pulls python:3.10-slim from it successfully).
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 4fc454ba
Pipeline #1022 failed with stages
in 1 minute and 7 seconds
stages: stages:
- build
- test - test
- deploy - deploy
variables: variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" CI_TEST_IMAGE: "$DOCKERHUB_USER/stax-ci-test:latest"
FFMPEG_CACHE_DIR: "$CI_PROJECT_DIR/.cache/ffmpeg-static"
cache: # Manual only - builds Dockerfile.ci (system packages + all of requirements.txt already
key: ${CI_COMMIT_REF_SLUG} # installed) and pushes it to Docker Hub. Run this by hand (Build > Pipelines > this pipeline
paths: # > play button on build_ci_image) the first time, and again whenever requirements.txt or
- .cache/pip/ # Dockerfile.ci's system deps change. The test job below pulls whatever this last pushed -
- .cache/ffmpeg-static/ # nothing else in this pipeline rebuilds it automatically.
#
# Needs DOCKERHUB_USER and DOCKERHUB_TOKEN as CI/CD variables (Settings > CI/CD > Variables) -
# DOCKERHUB_TOKEN should be a Docker Hub access token (hub.docker.com > Account Settings >
# Security > New Access Token), not your account password.
build_ci_image:
stage: build
image: docker:24.0
services:
- docker:24.0-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin
script:
- docker build -t "$CI_TEST_IMAGE" -f Dockerfile.ci .
- docker push "$CI_TEST_IMAGE"
when: manual
only:
- dev
- main
# Runs on every push to dev or main. No deploy here - just fast feedback while you're # Runs on every push to dev or main. Pulls the pre-baked image built above and just runs
# developing on dev, and a second confirmation right before deploy_prod fires on main. # pytest - no apt-get, no pip install, no ffmpeg download here anymore. All of that cost was
# moved into build_ci_image, which only runs when someone triggers it, not on every push.
test: test:
stage: test stage: test
image: python:3.10-slim image: "$CI_TEST_IMAGE"
before_script:
# apt's `ffmpeg` package drags in ~185 packages (video codecs, X11/Mesa, fonts, speech
# recognition libs) that took ~3min to unpack/configure on this runner, for functionality
# this project never uses (audio-only). A static, dependency-free ffmpeg build sidesteps
# apt/dpkg entirely - cached across runs so even the download only happens once. git isn't
# needed here at all (GitLab's own checkout doesn't use the job container's git).
- apt-get update -qq && apt-get install -y -qq --no-install-recommends libsndfile1 curl ca-certificates xz-utils
- |
if [ ! -x "$FFMPEG_CACHE_DIR/ffmpeg" ]; then
mkdir -p "$FFMPEG_CACHE_DIR"
curl -sL https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz -o /tmp/ffmpeg.tar.xz
tar -xf /tmp/ffmpeg.tar.xz -C /tmp
cp /tmp/ffmpeg-*-amd64-static/ffmpeg /tmp/ffmpeg-*-amd64-static/ffprobe "$FFMPEG_CACHE_DIR/"
fi
cp "$FFMPEG_CACHE_DIR/ffmpeg" "$FFMPEG_CACHE_DIR/ffprobe" /usr/local/bin/
# No torch/demucs here on purpose - requirements-remix.txt (the heavy stem-separation
# model) is prod-only. Nothing in the test suite needs the real separator; see
# remix_engine.py's _get_separator() and requirements-remix.txt for why that's safe.
- pip install --prefer-binary -q -r requirements.txt
script: script:
- PYTHONPATH=. pytest tests/ -v - PYTHONPATH=. pytest tests/ -v
only: only:
......
# Pre-baked CI test image - system packages AND all of requirements.txt already installed,
# so the test job in .gitlab-ci.yml does nothing but pull this image and run pytest. Every
# apt-get/pip cost that used to happen on every single push happens once here instead, when
# this image gets rebuilt (manually, via the build_ci_image job, whenever requirements.txt or
# these system deps change).
#
# Deliberately excludes requirements-remix.txt (torch/demucs) - nothing in the test suite
# needs the real stem-separation model, see remix_engine.py's _get_separator(). Keeping this
# image to only what tests actually need is what keeps it (and every pull of it) small.
FROM python:3.10-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg libsndfile1 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir --prefer-binary -r /tmp/requirements.txt
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment