Skip to content

Move scaling to KTrajectory #2275

Move scaling to KTrajectory

Move scaling to KTrajectory #2275

Workflow file for this run

name: Build and test docker
on:
pull_request:
paths-ignore:
- "**.md"
push:
branches:
- main
jobs:
get_dockerfiles:
name: Get list of Docker files for different containers
runs-on: ubuntu-latest
outputs:
docker_toml: ${{ steps.filter.outputs.docker_toml }}
docker_tasks: ${{ steps.set-matrix.outputs.docker_tasks }}
steps:
- name: Checkout mrpro repo
uses: actions/checkout@v4
- name: Check if files in docker or the toml file has been modified
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
docker_toml:
- 'docker/*'
- '.github/workflows/docker.yml'
- name: Do we need to do something?
run: |
echo "Push to main? ${{ github.event_name }} "
echo "Rebuild containers? ${{ steps.filter.outputs.docker_toml }}"
- name: Define docker image names
id: set-matrix
if: steps.filter.outputs.docker_toml == 'true' || github.event_name == 'push'
run: |
# docker_tasks is a list of pairs (dictionaries) with keys 'filepath' and 'image_name' like:
# [{"filepath": "docker/Dockerfile_x1", "image_name": "ghcr.io/ptb-mr/mrpro_x1"}, ...]
docker_tasks=$(find docker -type f -name 'Dockerfile*' | jq -R -s -c 'split("\n")[:-1]' | \
jq -r -c 'map({filepath: ., image_name: . | sub("docker/Dockerfile"; "ghcr.io\/ptb-mr\/mrpro")})')
echo "docker_tasks: $docker_tasks"
echo "docker_tasks=$docker_tasks" >> $GITHUB_OUTPUT
- name: Dockerfile overview
if: steps.filter.outputs.docker_toml == 'true' || github.event_name == 'push'
run: |
echo "final list of docker_tasks: ${{ steps.set-matrix.outputs.docker_tasks }}"
push_test:
name: Create test images and push to GCR
needs: get_dockerfiles
if: needs.get_dockerfiles.outputs.docker_toml == 'true' || github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
fail-fast: false
matrix:
docker_task: ${{ fromJson(needs.get_dockerfiles.outputs.docker_tasks) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get image basename
id: image_name
run: |
echo "dockerfile_basename=$(basename ${{ matrix.docker_task.filepath }})" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ptb-mr
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
cache-from: type=gha,scope=$${{ steps.image_name.outputs.dockerfile_basename }})
cache-to: type=gha,mode=max,scope=${{ steps.image_name.outputs.dockerfile_basename }}
file: ${{ matrix.docker_task.filepath }}
push: true
tags: ${{ matrix.docker_task.image_name }}:test
test:
name: Test docker containers
needs: [get_dockerfiles, push_test]
if: needs.get_dockerfiles.outputs.docker_toml == 'true' || github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
strategy:
matrix:
docker_task: ${{ fromJson(needs.get_dockerfiles.outputs.docker_tasks) }}
# runs within Docker container
container:
image: ${{ matrix.docker_task.image_name }}:test
options: --user runner
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[test]
- name: Install pytest-github-actions-annotate-failures plugin
run: pip install pytest-github-actions-annotate-failures
- name: Run PyTest
run: |
pytest -n 4 -m "not cuda"
push_latest:
name: Pull latest images and push to GCR with new tag
needs: [get_dockerfiles, test]
if: needs.get_dockerfiles.outputs.docker_toml == 'true' || github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
docker_task: ${{ fromJson(needs.get_dockerfiles.outputs.docker_tasks) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ptb-mr
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull and push Docker image with new tag
run: |
docker pull ${{ matrix.docker_task.image_name }}:test
docker tag ${{ matrix.docker_task.image_name }}:test ${{ matrix.docker_task.image_name }}:latest
docker push ${{ matrix.docker_task.image_name}}:latest