Set up docker for release + deploy, build front end during pypi #187
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: [pull_request, push] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref }} | |
| cancel-in-progress: true | |
| env: | |
| # https://github.com/pytest-dev/pytest/issues/2042#issuecomment-429289164 | |
| PY_IGNORE_IMPORTMISMATCH: 1 | |
| jobs: | |
| pytest: | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| fail-fast: false | |
| name: ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| defaults: | |
| run: | |
| shell: bash -l {0} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup pixi | |
| uses: prefix-dev/setup-pixi@v0.9.5 | |
| with: | |
| pixi-version: v0.49.0 | |
| cache: false | |
| - name: Install environment | |
| run: | | |
| pixi install | |
| pixi install -e all | |
| - name: Test | |
| run: | | |
| pixi run -e all pytest | |
| dockerize: | |
| name: Build Docker image and push to GHCR | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Build frontend bundle | |
| # Dockerfile copies src/ which must contain the built frontend at | |
| # src/bowser/dist/. That directory is gitignored, so it has to be | |
| # produced on the runner before `docker build` is invoked. | |
| run: | | |
| npm ci | |
| npm run build | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.11' | |
| - name: Compute version from setuptools_scm | |
| run: | | |
| pip install setuptools_scm | |
| version=$(python -m setuptools_scm) | |
| # BOWSER_VERSION stays PEP 440 (keeps '+') — used for the build arg | |
| # so setuptools_scm can read it back inside the image. | |
| # BOWSER_IMAGE_TAG sanitizes '+' to '-' because Docker tags forbid '+'. | |
| echo "BOWSER_VERSION=${version}" >> "$GITHUB_ENV" | |
| echo "BOWSER_IMAGE_TAG=${version//+/-}" >> "$GITHUB_ENV" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build, tag, and push image to GHCR | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| build-args: | | |
| VERSION=${{ env.BOWSER_VERSION }} | |
| tags: | | |
| ghcr.io/${{ github.repository }}:${{ env.BOWSER_IMAGE_TAG }} | |
| labels: | | |
| org.opencontainers.image.version=${{ env.BOWSER_VERSION }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} | |
| # GHA-cache layers across runs — biggest win is the pixi conda solve | |
| # in stage 1, which otherwise re-runs from scratch each build. | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Add develop tag (main branch only) | |
| if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
| uses: akhilerm/tag-push-action@v2.2.0 | |
| with: | |
| src: ghcr.io/${{ github.repository }}:${{ env.BOWSER_IMAGE_TAG }} | |
| dst: ghcr.io/${{ github.repository }}:develop | |
| - name: Add latest tag (release tags only) | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: akhilerm/tag-push-action@v2.2.0 | |
| with: | |
| src: ghcr.io/${{ github.repository }}:${{ env.BOWSER_IMAGE_TAG }} | |
| dst: ghcr.io/${{ github.repository }}:latest |