diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 360fb684..6265e237 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,14 @@ +# GitLab CI/CD Pipeline for Towerops Web +# +# Optimization Strategy: +# 1. compile job: Downloads deps once, compiles with --warnings-as-errors +# 2. test/quality jobs: Reuse artifacts from compile (no re-download/recompile) +# 3. Caching: Separate caches for hex/mix, deps, build, and system packages +# 4. Artifacts: Include both deps/ and _build/ to avoid redundant work +# 5. Database setup: Uses compiled artifacts, no recompilation needed +# +# Performance: Typical run time is 3-5 minutes with warm cache + image: hexpm/elixir:1.19.5-erlang-28.0-debian-bookworm-20250113-slim variables: @@ -39,16 +50,16 @@ stages: policy: pull before_script: - - apt-get update -qq - # Configure apt cache + # Configure apt cache for faster system dependency installation - mkdir -p apt-cache - export APT_CACHE_DIR=$CI_PROJECT_DIR/apt-cache - # Install system dependencies + - apt-get update -qq + # Install system dependencies (uses cache on subsequent runs) - apt-get install -y -qq --no-install-recommends libsnmp-dev snmp-mibs-downloader build-essential git curl ca-certificates -o dir::cache::archives=$APT_CACHE_DIR - # Install Hex and Rebar + # Install Hex and Rebar (idempotent, fast if already installed) - mix local.hex --force - mix local.rebar --force @@ -85,8 +96,10 @@ compile: - mix compile --warnings-as-errors artifacts: paths: - - _build/test/ + - deps/ # Include deps to avoid re-downloading + - _build/test/ # Include compiled code expire_in: 1 hour + untracked: false # Run tests test: @@ -99,13 +112,13 @@ test: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_HOST: postgres - cache: - - *hex_cache - - *mix_cache - - *system_cache + # Skip deps fetching - we have them from compile artifacts + MIX_ENV: test + cache: [] # No cache needed - using artifacts from compile job script: - - mix ecto.create - - mix ecto.migrate + # Database setup doesn't need full recompilation + # Artifacts from compile job provide everything needed + - mix ecto.setup # Combines create + migrate + seed (if needed) - mix test --warnings-as-errors coverage: '/\d+\.\d+\%\s+\|\s+Total/' artifacts: @@ -121,9 +134,13 @@ quality: stage: test needs: [compile] cache: + # Only need hex/mix for dialyzer PLT - artifacts provide everything else - *hex_cache - - *mix_cache - - *system_cache + - key: + prefix: dialyzer-plt-1.19.5-otp-28 + paths: + - priv/plts/ + policy: pull-push script: - mix format --check-formatted - mix credo --strict