Skip to content

feat: container-aware setup-environment with lean container variant - #17

Merged
mmcky merged 18 commits into
mainfrom
feat/container-aware-setup-environment
Feb 4, 2026
Merged

mmcky merged 18 commits into
mainfrom
feat/container-aware-setup-environment

Conversation

@mmcky

@mmcky mmcky commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes setup-environment automatically detect when running inside QuantEcon containers and optimize accordingly. Also introduces a new lean container (quantecon-build) that is ~60% smaller for faster CI builds.

Changes

New: Lean Container (quantecon-build)

  • Image: ghcr.io/quantecon/quantecon-build:latest
  • Size: ~3GB (vs ~8GB for full container)
  • Contents: Miniconda + explicit package list + minimal TexLive
  • Best for: CI/CD pipelines, faster image pulls

setup-environment/action.yml

  • Container mode: Detects /etc/quantecon-container marker, runs conda env update for delta packages only
  • Standard mode: Full Conda + LaTeX installation (backwards compatible)
  • New outputs: container-mode, conda-cache-hit

Container Dockerfiles

  • Both containers now include marker file at /etc/quantecon-container
  • Full container (quantecon): Added marker + documented Anaconda metapackage
  • Lean container (quantecon-build): New Dockerfile with minimal TexLive

Build Infrastructure

  • .github/workflows/build-containers.yml: Builds both containers, workflow_dispatch input to select container
  • .github/workflows/test-container.yml: Tests both containers after build

Documentation Updates

  • README.md: Added container examples
  • setup-environment/README.md: Full rewrite with container mode docs
  • docs/QUICK-REFERENCE.md: Updated quick start
  • containers/README.md: New container comparison guide

Performance Results

Mode Setup Time Notes
Full container (quantecon) 2m 45s All packages pre-installed
Lean container (quantecon-build) 3m 24s Smaller image, fast pull
Standard mode (ubuntu-latest) 4m 06s Conda cache hit

Container Comparison

quantecon quantecon-build
Size ~8GB ~3GB
Python Anaconda 2025.12 Miniconda + explicit
Packages ~450 ~100
TexLive Full Minimal (XeLaTeX)
Best for Development CI builds

Usage

Recommended: Lean Container for CI

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/quantecon/quantecon-build:latest
    steps:
      - uses: actions/checkout@v4
      - uses: quantecon/actions/setup-environment@v1
        with:
          environment-file: 'environment.yml'  # Adds lecture-specific packages
      - uses: quantecon/actions/build-lectures@v1

Standard Mode (No Container)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: quantecon/actions/setup-environment@v1
        with:
          python-version: '3.13'
          environment-file: 'environment.yml'
          install-latex: 'true'
      - uses: quantecon/actions/build-lectures@v1

Testing

  • Container detection working (marker file)
  • Full container builds successfully
  • Lean container builds successfully
  • Test workflow passes all scenarios
  • Standard mode backwards compatible
  • Documentation updated

Files Changed

  • containers/quantecon/Dockerfile - Added marker file
  • containers/quantecon-build/ - NEW lean container
  • containers/README.md - NEW comparison guide
  • setup-environment/action.yml - Container-aware rewrite
  • setup-environment/README.md - Updated docs
  • .github/workflows/build-containers.yml - Builds both containers
  • .github/workflows/test-container.yml - Tests both containers
  • README.md, docs/QUICK-REFERENCE.md - Updated examples

mmcky added 6 commits February 4, 2026 11:05
- Add container detection via /etc/quantecon-container marker file
- In container mode: only install delta packages via conda env update
- In standard mode: full installation (backwards compatible)
- Add new outputs: container-mode, conda-cache-hit
- Update Dockerfile to create marker file during build
- Update all documentation to reflect new behavior

Performance improvement:
- Container mode: ~1-2 min setup (vs ~8-10 min standard)
- Auto-detects environment, no workflow changes needed
- Skip environment processing entirely when environment-file is empty
- Use direct pip install for faster package installation
- Avoid slow conda env update --prune
- Add 'Container (Pure)' test for fastest path
- Parse environment.yml for both conda and pip dependencies
- Install conda packages with 'conda install -y -q'
- Install pip packages with 'pip install --quiet'
- Skip 'pip' itself as a dependency
The --prune flag causes a full environment solve which is slow.
Without --prune, conda env update just adds missing packages.
Two container variants:
- quantecon (full): ~8GB with Anaconda 2025.12 + full TexLive
- quantecon-build (lean): ~3GB with explicit packages + minimal TexLive

The lean container includes superset of packages used across:
- lecture-python-intro
- lecture-python.myst
- lecture-python-advanced.myst
- lecture-python-programming.myst

Lecture-specific packages (quantecon, wbgapi, jax, etc.) are installed
from each lecture's environment.yml at build time.

Also:
- Updated build workflow to build both containers
- Updated test workflow to test both containers
- Added containers/README.md documenting the variants
- Document both quantecon (full) and quantecon-build (lean) containers
- Add examples for container mode with/without environment.yml
- Add example for standard mode (no container) with full environment.yml
- Clarify that standard mode continues to work for custom environments
@mmcky mmcky changed the title feat: make setup-environment container-aware feat: container-aware setup-environment with lean container variant Feb 4, 2026
@mmcky
mmcky requested a review from Copilot February 4, 2026 01:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds container-aware behavior to the setup-environment composite action and introduces a new lean quantecon-build container image to speed up CI by reducing image size and redundant installs.

Changes:

  • Updated setup-environment to detect QuantEcon containers via /etc/quantecon-container and follow a fast-path install strategy.
  • Added new containers/quantecon-build (lean image) alongside updates to the existing full quantecon container for marker-based detection.
  • Expanded build/test workflows and documentation to cover both container variants and the new action outputs.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
setup-environment/action.yml Adds container detection, container-mode caching/install logic, new outputs, and summary reporting.
setup-environment/README.md Rewritten docs describing container vs standard mode usage, cache strategy, and outputs.
docs/QUICK-REFERENCE.md Adds recommended container-based CI workflow and updated cache key guidance.
containers/quantecon/environment.yml Clarifies “full” container intent and Anaconda metapackage usage.
containers/quantecon/Dockerfile Adds /etc/quantecon-container marker for action auto-detection.
containers/quantecon-build/environment.yml New lean conda environment spec for build-focused container.
containers/quantecon-build/Dockerfile New lean container build with Miniconda + minimal TeXLive + marker file.
containers/quantecon-build/README.md New documentation for lean container usage and comparison.
containers/README.md New container comparison/selection guide and detection description.
.github/workflows/build-containers.yml Builds and pushes both images; adds workflow_dispatch input to select images.
.github/workflows/test-container.yml Tests both images with HTML/PDF/XeLaTeX checks and artifact upload.
README.md Updates top-level usage examples to highlight container-based setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Resolved
Comment thread setup-environment/action.yml Resolved
Comment thread .github/workflows/test-container.yml Resolved
Comment thread .github/workflows/test-container.yml Resolved
Comment thread .github/workflows/build-containers.yml Resolved
Comment thread setup-environment/action.yml Resolved
Comment thread setup-environment/action.yml Resolved
Comment thread .github/workflows/test-container.yml Resolved
Comment thread .github/workflows/build-containers.yml Resolved
Comment thread containers/quantecon-build/Dockerfile Resolved
- Fix build-containers.yml job conditions for push/schedule events
- Fix test-container.yml ls paths after cd commands
- Pin Miniconda version with SHA256 checksum for supply-chain security
- Improve setup-environment summary to show actual container image
- Add error exit when environment file specified but missing
- Restore bash -l {0} for ML libs to ensure conda activation
- Cache full conda env prefix instead of just site-packages
- Only run conda env update on cache miss to avoid inconsistent state
- Handle 'no environment file' case in summary output

Note: Keeping @main references for now; will update to @v1 at release time.
@mmcky

mmcky commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

Review Feedback Addressed ✅

Thanks for the thorough review! I've addressed all comments:

Fixed

Comment Fix
Build workflow if: breaks on push/schedule Added github.event_name != 'workflow_dispatch' check
Wrong ls paths after cd Fixed all 3 occurrences in test-container.yml
Pin Miniconda with checksum Pinned to py313_25.1.1-2 with SHA256 verification
Hardcoded container image in summary Now parses /etc/quantecon-container for actual image
Should fail if env file missing Added exit 1 with error annotation
Needs bash -l {0} for ML libs Restored login shell for conda activation
Caching only site-packages inconsistent Now caches full /opt/conda/envs/{name} + /opt/conda/pkgs
Summary misleading with no env file Added branch for "no environment file" case

Note on @main vs @v1

Keeping @main in examples for now since v1 hasn't been released yet. Will update all references to @v1 as part of the release process.


Ready for re-review!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread setup-environment/action.yml Resolved
Comment thread setup-environment/README.md Resolved
Comment thread docs/QUICK-REFERENCE.md Resolved
Comment thread setup-environment/action.yml Resolved
Comment thread setup-environment/action.yml Resolved
Comment thread containers/quantecon-build/Dockerfile Resolved
Comment thread README.md Resolved
- Remove container mode caching (actions/cache runs on host, not in container)
- Update docs to reflect no caching in container mode
- Fix conda-cache-hit output description
- Use bash -l {0} for Display Environment Info step
- Change chmod 777 to chmod 755 for fontconfig cache (security)
- Update cache key documentation to match implementation

Created issue #18 to track future caching improvements.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/test-container.yml Resolved
Comment thread docs/QUICK-REFERENCE.md Resolved
Comment thread setup-environment/action.yml Resolved
Comment thread setup-environment/README.md Resolved
mmcky added 2 commits February 4, 2026 13:25
- Remove full container size comparison (not pulled in lean job)
- Remove asterisk from 'No caching' in cache table (no footnote)
- Clarify caching comment: conda env paths outside workspace mount
- Update README: remove mention of caching in container mode
GitHub Copilot automatically reads instructions from .github/copilot-instructions.md

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread setup-environment/action.yml Resolved
Comment thread setup-environment/action.yml Resolved
mmcky added 5 commits February 4, 2026 13:41
- Remove -n flag from conda env update to use env name from file
  (works regardless of environment-name input, more flexible)
- Use plain bash instead of login shell for Display Environment Info
  (avoids PATH reset in containers where /etc/profile drops conda)
- Create separate test-xelatex.tex for quantecon-build using FreeSerif
  (lean container has FreeFont, not DejaVu)
- Update test-container.yml to use correct test paths
- Fix artifact upload path for lean container tests
- Add fonts-dejavu to quantecon-build Dockerfile (same as full container)
- Both containers now use the same test file (containers/quantecon/tests/)
- Remove separate test file that was created for lean container
Version py313_25.1.1-2 does not exist on Anaconda servers.
Updated to latest available Python 3.13 Miniconda (December 2025).
mmcky added 3 commits February 4, 2026 14:07
- Lean container (quantecon-build)
- Container-aware setup-environment
- Container test workflow
- DejaVu font fixes
@mmcky
mmcky merged commit f8ae3bf into main Feb 4, 2026
@mmcky
mmcky deleted the feat/container-aware-setup-environment branch August 7, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants