From a5af8b646373756d0fe411e425638a41d6e9c70b Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 13:24:59 +0200 Subject: [PATCH 01/27] chore: let code check workflow run only on pull request --- .github/workflows/code_check.yml | 7 +------ .github/workflows/container_build.yml | 1 + 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code_check.yml b/.github/workflows/code_check.yml index 2e2c3819..fa02d3d4 100644 --- a/.github/workflows/code_check.yml +++ b/.github/workflows/code_check.yml @@ -1,11 +1,6 @@ name: Code Checking -on: - push: - branches-ignore: - - master - paths: - - '**/*.py' +on: pull_request: branches: - master diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 87365049..1372b3b6 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -13,6 +13,7 @@ on: - master paths: - 'resources/retinal-rl.def' + workflow_dispatch: jobs: singularity-build: From 397b0458bce2a3e63c916170a61f89dcaa546416 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 14:27:02 +0200 Subject: [PATCH 02/27] feat: add new workflow to update the cache in the main branch --- .github/workflows/container_build.yml | 1 + .github/workflows/update_cache.yml | 39 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .github/workflows/update_cache.yml diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 87365049..e675c05a 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -13,6 +13,7 @@ on: - master paths: - 'resources/retinal-rl.def' + workflow_call: jobs: singularity-build: diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml new file mode 100644 index 00000000..1c8d96bc --- /dev/null +++ b/.github/workflows/update_cache.yml @@ -0,0 +1,39 @@ +name: Build & Cache Singularity Container + +on: + workflow_dispatch: + push: + # branches: + # - master + # paths: + # - 'resources/retinal-rl.def' + +env: + singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest + sif_file: retinal-rl_singularity-image-latest.sif + +jobs: + singularity-build: + uses: ./.github/workflows/container_build.yml + update-cache: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Apptainer + uses: eWaterCycle/setup-apptainer@v2 + with: + apptainer-version: 1.3.0 + - name: Cache Singularity Image + id: cache-singularity + uses: actions/cache@v3 + with: + path: ${{ env.sif_file }} + key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + restore-keys: | + ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + ${{ runner.os }}-singularity- + - name: Pull Singularity container + if: steps.cache-singularity.outputs.cache-hit != 'true' + run: | + singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io + singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} From 9c99b1a834c873a4bf96fdd04d6fa2dc6159a93f Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 14:55:10 +0200 Subject: [PATCH 03/27] fix: make workflow run only on pushes to master with changes of def file --- .github/workflows/update_cache.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index 1c8d96bc..083450b2 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -1,21 +1,22 @@ -name: Build & Cache Singularity Container +name: Update Master Cache on: workflow_dispatch: push: - # branches: - # - master - # paths: - # - 'resources/retinal-rl.def' + branches: + - master + paths: + - 'resources/retinal-rl.def' env: singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest sif_file: retinal-rl_singularity-image-latest.sif jobs: - singularity-build: + container-build: uses: ./.github/workflows/container_build.yml update-cache: + needs: container-build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 60e7e00bf96b2a2990818befae99b713f492e1f7 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 15:37:30 +0200 Subject: [PATCH 04/27] chore: bump cache action version to 4 --- .github/workflows/code_check.yml | 2 +- .github/workflows/config_scan.yml | 2 +- .github/workflows/update_cache.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code_check.yml b/.github/workflows/code_check.yml index fa02d3d4..73621833 100644 --- a/.github/workflows/code_check.yml +++ b/.github/workflows/code_check.yml @@ -28,7 +28,7 @@ jobs: apptainer-version: 1.3.0 - name: Cache Singularity Image id: cache-singularity - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.sif_file }} key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} diff --git a/.github/workflows/config_scan.yml b/.github/workflows/config_scan.yml index cc7206de..dddfa40c 100644 --- a/.github/workflows/config_scan.yml +++ b/.github/workflows/config_scan.yml @@ -16,7 +16,7 @@ jobs: apptainer-version: 1.3.0 - name: Cache Singularity Image id: cache-singularity - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.sif_file }} key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index 083450b2..d77d6030 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -26,7 +26,7 @@ jobs: apptainer-version: 1.3.0 - name: Cache Singularity Image id: cache-singularity - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.sif_file }} key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} From 6a85273a04fdfab7f8d83208bd7dfd362a00cc39 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 16:19:33 +0200 Subject: [PATCH 05/27] test: workflow with inputs --- .github/workflows/container_build.yml | 62 +++++++++++++++++++++------ .github/workflows/update_cache.yml | 57 ++++++++++++------------ 2 files changed, 78 insertions(+), 41 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index f5b1f038..515d5584 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -4,17 +4,27 @@ on: schedule: - cron: '0 2 1 * *' push: - branches-ignore: - - master - paths: - - 'resources/retinal-rl.def' + # branches-ignore: + # - master + # paths: + # - 'resources/retinal-rl.def' pull_request: branches: - master paths: - 'resources/retinal-rl.def' workflow_call: + inputs: + deploy: + type: boolean + required: false + default: true workflow_dispatch: + inputs: + deploy: + type: boolean + required: false + default: true jobs: singularity-build: @@ -24,16 +34,40 @@ jobs: - uses: eWaterCycle/setup-apptainer@v2 with: apptainer-version: 1.3.0 + + - name: Determine trigger type and set input + id: setup + run: | + if [[ "${{ github.event_name }}" == "workflow_call" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then + echo "deploy=${{ github.event.inputs.deploy }}" >> $GITHUB_OUTPUT + else + echo "deploy=false" >> $GITHUB_OUTPUT + fi + + - name: Test input + run: | + if ${{ steps.setup.outputs.deploy }}"; then + echo "yes" + else + echo "no" + fi - - name: Build Singularity container - run: apptainer build retinal-rl.sif resources/retinal-rl.def + - name: Test input again + if: steps.setup.outputs.deploy + run: + echo "yes" - - name: Scan classification config / ensure minimal functionality - run: | - cp -r resources/config_templates/* config/ - singularity exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu + # - name: Build Singularity container + # run: apptainer build retinal-rl.sif resources/retinal-rl.def - - name: Push to ghcr.io - run: | - singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - singularity push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest + # - name: Scan classification config / ensure minimal functionality + # run: | + # cp -r resources/config_templates/* config/ + # singularity exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu + + # - name: Push to ghcr.io + # run: | + # if ${{ steps.setup.outputs.deploy }}"; then + # singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io + # singularity push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest + # fi diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index d77d6030..5cd2ae1a 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -3,10 +3,10 @@ name: Update Master Cache on: workflow_dispatch: push: - branches: - - master - paths: - - 'resources/retinal-rl.def' + # branches: + # - master + # paths: + # - 'resources/retinal-rl.def' env: singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest @@ -15,26 +15,29 @@ env: jobs: container-build: uses: ./.github/workflows/container_build.yml - update-cache: - needs: container-build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup Apptainer - uses: eWaterCycle/setup-apptainer@v2 - with: - apptainer-version: 1.3.0 - - name: Cache Singularity Image - id: cache-singularity - uses: actions/cache@v4 - with: - path: ${{ env.sif_file }} - key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - restore-keys: | - ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - ${{ runner.os }}-singularity- - - name: Pull Singularity container - if: steps.cache-singularity.outputs.cache-hit != 'true' - run: | - singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} + with: + deploy: true + + # update-cache: + # needs: container-build + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Setup Apptainer + # uses: eWaterCycle/setup-apptainer@v2 + # with: + # apptainer-version: 1.3.0 + # - name: Cache Singularity Image + # id: cache-singularity + # uses: actions/cache@v4 + # with: + # path: ${{ env.sif_file }} + # key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + # restore-keys: | + # ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + # ${{ runner.os }}-singularity- + # - name: Pull Singularity container + # if: steps.cache-singularity.outputs.cache-hit != 'true' + # run: | + # singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io + # singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} From bf6ed57551c4333d066ab1be920ca5ebe790c01e Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 16:28:09 +0200 Subject: [PATCH 06/27] fix(?): input processing for action --- .github/workflows/container_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 515d5584..c01d9b7d 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -38,7 +38,7 @@ jobs: - name: Determine trigger type and set input id: setup run: | - if [[ "${{ github.event_name }}" == "workflow_call" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then + if [[ "${{ github.event.inputs.deploy }}" != "" ]]; then echo "deploy=${{ github.event.inputs.deploy }}" >> $GITHUB_OUTPUT else echo "deploy=false" >> $GITHUB_OUTPUT From 2cdbf18772c0fd3d57ef4012288a9d522ddb21e5 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 16:36:03 +0200 Subject: [PATCH 07/27] further try getting the input stuff running --- .github/workflows/container_build.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index c01d9b7d..f7f78c5f 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -38,24 +38,29 @@ jobs: - name: Determine trigger type and set input id: setup run: | - if [[ "${{ github.event.inputs.deploy }}" != "" ]]; then - echo "deploy=${{ github.event.inputs.deploy }}" >> $GITHUB_OUTPUT + if [[ "${{ inputs.deploy }}" != "" ]]; then + echo "deploy=${{ inputs.deploy }}" >> $GITHUB_OUTPUT else echo "deploy=false" >> $GITHUB_OUTPUT fi - name: Test input run: | - if ${{ steps.setup.outputs.deploy }}"; then + if ${{ steps.setup.outputs.deploy }}; then echo "yes" else echo "no" fi - - name: Test input again + - name: Test input TRUE if: steps.setup.outputs.deploy run: echo "yes" + + - name: Test input FALSE + if: ! steps.setup.outputs.deploy + run: + echo "no" # - name: Build Singularity container # run: apptainer build retinal-rl.sif resources/retinal-rl.def From 9ecab0a033a48e306b78fff4a358f02b2a4df7b5 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 16:37:36 +0200 Subject: [PATCH 08/27] try getting it running, fix if not action --- .github/workflows/container_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index f7f78c5f..159f9828 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -53,12 +53,12 @@ jobs: fi - name: Test input TRUE - if: steps.setup.outputs.deploy + if: ${{steps.setup.outputs.deploy}} run: echo "yes" - name: Test input FALSE - if: ! steps.setup.outputs.deploy + if: ${{! steps.setup.outputs.deploy}} run: echo "no" From c317c3c5935e2ee5d12cb783d606b3a81aa0977a Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 16:41:25 +0200 Subject: [PATCH 09/27] working, testing more concise syntax --- .github/workflows/container_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 159f9828..488f24db 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -53,12 +53,12 @@ jobs: fi - name: Test input TRUE - if: ${{steps.setup.outputs.deploy}} + if: ${{steps.setup.outputs.deploy==true}} run: echo "yes" - name: Test input FALSE - if: ${{! steps.setup.outputs.deploy}} + if: ${{steps.setup.outputs.deploy==false}} run: echo "no" From 104d9bf368c7f2ce767f96ff3eb6dd5ecddc5bec Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 16:44:05 +0200 Subject: [PATCH 10/27] further syntax test --- .github/workflows/container_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 488f24db..daf414c8 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -53,12 +53,12 @@ jobs: fi - name: Test input TRUE - if: ${{steps.setup.outputs.deploy==true}} + if: steps.setup.outputs.deploy run: echo "yes" - name: Test input FALSE - if: ${{steps.setup.outputs.deploy==false}} + if: steps.setup.outputs.deploy==false run: echo "no" From a8fe832b90df5f5738abb84cbc138146ee923bf6 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 16:46:44 +0200 Subject: [PATCH 11/27] hopefully last test --- .github/workflows/container_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index daf414c8..662c60a9 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -53,12 +53,12 @@ jobs: fi - name: Test input TRUE - if: steps.setup.outputs.deploy + if: steps.setup.outputs.deploy == 'true' run: echo "yes" - name: Test input FALSE - if: steps.setup.outputs.deploy==false + if: steps.setup.outputs.deploy == 'false' run: echo "no" From ccb9229191529818f780396b4c70ebeba15b6af5 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 17:07:09 +0200 Subject: [PATCH 12/27] test even more concise syntax --- .github/workflows/container_build.yml | 58 +++++++++++---------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 662c60a9..ab7fb8c3 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -30,37 +30,26 @@ jobs: singularity-build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: eWaterCycle/setup-apptainer@v2 - with: - apptainer-version: 1.3.0 + - name: test yes + if: inputs.deploy == 'true' + run: echo "yes" + + - name: test no + if: inputs.deploy != 'true' + run: echo "no" + # - uses: actions/checkout@v4 + # - uses: eWaterCycle/setup-apptainer@v2 + # with: + # apptainer-version: 1.3.0 - - name: Determine trigger type and set input - id: setup - run: | - if [[ "${{ inputs.deploy }}" != "" ]]; then - echo "deploy=${{ inputs.deploy }}" >> $GITHUB_OUTPUT - else - echo "deploy=false" >> $GITHUB_OUTPUT - fi - - - name: Test input - run: | - if ${{ steps.setup.outputs.deploy }}; then - echo "yes" - else - echo "no" - fi - - - name: Test input TRUE - if: steps.setup.outputs.deploy == 'true' - run: - echo "yes" - - - name: Test input FALSE - if: steps.setup.outputs.deploy == 'false' - run: - echo "no" + # - name: Evaluate whether build should be deployed + # id: setup + # run: | + # if [[ "${{ inputs.deploy }}" != "" ]]; then + # echo "deploy=${{ inputs.deploy }}" >> $GITHUB_OUTPUT + # else + # echo "deploy=false" >> $GITHUB_OUTPUT + # fi # - name: Build Singularity container # run: apptainer build retinal-rl.sif resources/retinal-rl.def @@ -70,9 +59,8 @@ jobs: # cp -r resources/config_templates/* config/ # singularity exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu - # - name: Push to ghcr.io + # - name: Deployment / Push to ghcr.io + # if: steps.setup.outputs.deploy == 'true' # run: | - # if ${{ steps.setup.outputs.deploy }}"; then - # singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - # singularity push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest - # fi + # singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io + # singularity push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest From 3ecfa13ea1fcc494623d9775cf396797d170d42f Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Wed, 16 Oct 2024 17:10:02 +0200 Subject: [PATCH 13/27] fix: build workflow does not automatically deploy --- .github/workflows/container_build.yml | 61 ++++++++++++--------------- .github/workflows/update_cache.yml | 54 ++++++++++++------------ 2 files changed, 54 insertions(+), 61 deletions(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index ab7fb8c3..d33ffb57 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -4,10 +4,10 @@ on: schedule: - cron: '0 2 1 * *' push: - # branches-ignore: - # - master - # paths: - # - 'resources/retinal-rl.def' + branches-ignore: + - master + paths: + - 'resources/retinal-rl.def' pull_request: branches: - master @@ -30,37 +30,30 @@ jobs: singularity-build: runs-on: ubuntu-latest steps: - - name: test yes - if: inputs.deploy == 'true' - run: echo "yes" - - - name: test no - if: inputs.deploy != 'true' - run: echo "no" - # - uses: actions/checkout@v4 - # - uses: eWaterCycle/setup-apptainer@v2 - # with: - # apptainer-version: 1.3.0 + - uses: actions/checkout@v4 + - uses: eWaterCycle/setup-apptainer@v2 + with: + apptainer-version: 1.3.0 - # - name: Evaluate whether build should be deployed - # id: setup - # run: | - # if [[ "${{ inputs.deploy }}" != "" ]]; then - # echo "deploy=${{ inputs.deploy }}" >> $GITHUB_OUTPUT - # else - # echo "deploy=false" >> $GITHUB_OUTPUT - # fi + - name: Evaluate whether build should be deployed + id: setup + run: | + if [[ "${{ inputs.deploy }}" != "" ]]; then + echo "deploy=${{ inputs.deploy }}" >> $GITHUB_OUTPUT + else + echo "deploy=false" >> $GITHUB_OUTPUT + fi - # - name: Build Singularity container - # run: apptainer build retinal-rl.sif resources/retinal-rl.def + - name: Build Singularity container + run: apptainer build retinal-rl.sif resources/retinal-rl.def - # - name: Scan classification config / ensure minimal functionality - # run: | - # cp -r resources/config_templates/* config/ - # singularity exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu + - name: Scan classification config / ensure minimal functionality + run: | + cp -r resources/config_templates/* config/ + singularity exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu - # - name: Deployment / Push to ghcr.io - # if: steps.setup.outputs.deploy == 'true' - # run: | - # singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - # singularity push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest + - name: Deployment / Push to ghcr.io + if: steps.setup.outputs.deploy == 'true' + run: | + singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io + singularity push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index 5cd2ae1a..3dd59368 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -3,10 +3,10 @@ name: Update Master Cache on: workflow_dispatch: push: - # branches: - # - master - # paths: - # - 'resources/retinal-rl.def' + branches: + - master + paths: + - 'resources/retinal-rl.def' env: singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest @@ -18,26 +18,26 @@ jobs: with: deploy: true - # update-cache: - # needs: container-build - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - name: Setup Apptainer - # uses: eWaterCycle/setup-apptainer@v2 - # with: - # apptainer-version: 1.3.0 - # - name: Cache Singularity Image - # id: cache-singularity - # uses: actions/cache@v4 - # with: - # path: ${{ env.sif_file }} - # key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - # restore-keys: | - # ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - # ${{ runner.os }}-singularity- - # - name: Pull Singularity container - # if: steps.cache-singularity.outputs.cache-hit != 'true' - # run: | - # singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - # singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} + update-cache: + needs: container-build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Apptainer + uses: eWaterCycle/setup-apptainer@v2 + with: + apptainer-version: 1.3.0 + - name: Cache Singularity Image + id: cache-singularity + uses: actions/cache@v4 + with: + path: ${{ env.sif_file }} + key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + restore-keys: | + ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + ${{ runner.os }}-singularity- + - name: Pull Singularity container + if: steps.cache-singularity.outputs.cache-hit != 'true' + run: | + singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io + singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} From 4f6d525273274e3412fcf5aed9a847adfdce83bb Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 11:03:01 +0200 Subject: [PATCH 14/27] fix: no more login needed to pull sif container remove singularity pull commands --- .github/workflows/config_scan.yml | 4 +--- .github/workflows/update_cache.yml | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/config_scan.yml b/.github/workflows/config_scan.yml index dddfa40c..fb0a33c6 100644 --- a/.github/workflows/config_scan.yml +++ b/.github/workflows/config_scan.yml @@ -25,9 +25,7 @@ jobs: ${{ runner.os }}-singularity- - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' - run: | - singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} + run: singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} - name: Prepare experiment files run: | diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index 3dd59368..f72d29a3 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -38,6 +38,4 @@ jobs: ${{ runner.os }}-singularity- - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' - run: | - singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} + run: singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} From 38bc90abc48dbcc1c43dfb8fb5c756f9489ad7ff Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 11:06:13 +0200 Subject: [PATCH 15/27] chore: replace singularity commands with apptainer --- .github/workflows/code_check.yml | 6 ++---- .github/workflows/config_scan.yml | 4 ++-- .github/workflows/container_build.yml | 6 +++--- .github/workflows/update_cache.yml | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/code_check.yml b/.github/workflows/code_check.yml index 73621833..eee28cb6 100644 --- a/.github/workflows/code_check.yml +++ b/.github/workflows/code_check.yml @@ -37,11 +37,9 @@ jobs: ${{ runner.os }}-singularity- - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' - run: | - singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} + run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} - name: Run Pylint run: | - singularity exec ${{ env.sif_file }} \ + apptainer exec ${{ env.sif_file }} \ pylint $(git diff --name-only origin/master...HEAD -- '*.py') diff --git a/.github/workflows/config_scan.yml b/.github/workflows/config_scan.yml index fb0a33c6..5d9caa61 100644 --- a/.github/workflows/config_scan.yml +++ b/.github/workflows/config_scan.yml @@ -25,7 +25,7 @@ jobs: ${{ runner.os }}-singularity- - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' - run: singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} + run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} - name: Prepare experiment files run: | @@ -38,6 +38,6 @@ jobs: - name: Scan classification configs run: | while IFS= read -r experiment; do - singularity exec ${{ env.sif_file }} \ + apptainer exec ${{ env.sif_file }} \ python main.py +experiment="$experiment" command=scan system.device=cpu done < experiments.txt diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index d33ffb57..18d0e775 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -50,10 +50,10 @@ jobs: - name: Scan classification config / ensure minimal functionality run: | cp -r resources/config_templates/* config/ - singularity exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu + apptainer exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu - name: Deployment / Push to ghcr.io if: steps.setup.outputs.deploy == 'true' run: | - singularity registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - singularity push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest + apptainer registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io + apptainer push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index f72d29a3..be27ae52 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -38,4 +38,4 @@ jobs: ${{ runner.os }}-singularity- - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' - run: singularity pull ${{ env.sif_file }} ${{ env.singularity_image }} + run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} From 14a578154fd38a94c663ce7716ef5d9407648dfa Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 14:23:30 +0200 Subject: [PATCH 16/27] chore: make container name simpler --- .github/workflows/code_check.yml | 5 ++--- .github/workflows/config_scan.yml | 7 +++---- .github/workflows/container_build.yml | 12 +++++++----- .github/workflows/update_cache.yml | 18 +++++++++--------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/code_check.yml b/.github/workflows/code_check.yml index eee28cb6..216ea67e 100644 --- a/.github/workflows/code_check.yml +++ b/.github/workflows/code_check.yml @@ -8,8 +8,8 @@ on: - '**/*.py' env: - singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest - sif_file: retinal-rl_singularity-image-latest.sif + singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image + sif_file: retinal-rl_singularity-image.sif jobs: check: @@ -34,7 +34,6 @@ jobs: key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} restore-keys: | ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - ${{ runner.os }}-singularity- - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} diff --git a/.github/workflows/config_scan.yml b/.github/workflows/config_scan.yml index 5d9caa61..252a77ba 100644 --- a/.github/workflows/config_scan.yml +++ b/.github/workflows/config_scan.yml @@ -1,9 +1,9 @@ name: Scan Configs -on: [pull_request,workflow_dispatch] +on: [pull_request,workflow_call] env: - singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest - sif_file: retinal-rl_singularity-image-latest.sif + singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image + sif_file: retinal-rl_singularity-image.sif jobs: scan: @@ -22,7 +22,6 @@ jobs: key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} restore-keys: | ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - ${{ runner.os }}-singularity- - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 18d0e775..0257020f 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -1,8 +1,6 @@ name: Build Singularity Container on: - schedule: - - cron: '0 2 1 * *' push: branches-ignore: - master @@ -26,6 +24,10 @@ on: required: false default: true +env: + singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image + sif_file: retinal-rl_singularity-image.sif + jobs: singularity-build: runs-on: ubuntu-latest @@ -45,15 +47,15 @@ jobs: fi - name: Build Singularity container - run: apptainer build retinal-rl.sif resources/retinal-rl.def + run: apptainer build ${{ env.sif_file }} resources/retinal-rl.def - name: Scan classification config / ensure minimal functionality run: | cp -r resources/config_templates/* config/ - apptainer exec retinal-rl.sif python main.py -m +experiment=classification command=scan system.device=cpu + apptainer exec ${{ env.sif_file }} python main.py -m +experiment=classification command=scan system.device=cpu - name: Deployment / Push to ghcr.io if: steps.setup.outputs.deploy == 'true' run: | apptainer registry login --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} oras://ghcr.io - apptainer push retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest + apptainer push ${{ env.sif_file }} oras://ghcr.io/berenslab/retinal-rl:singularity-image diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index be27ae52..6f6bb150 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -1,25 +1,22 @@ name: Update Master Cache on: + schedule: + - cron: '0 2 * * 0' # As cache is emptied if not accessed for 7 days, check after 7 days whether container has changed workflow_dispatch: push: branches: - master paths: - 'resources/retinal-rl.def' + workflow_call: env: - singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image-latest - sif_file: retinal-rl_singularity-image-latest.sif + singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image + sif_file: retinal-rl_singularity-image.sif jobs: - container-build: - uses: ./.github/workflows/container_build.yml - with: - deploy: true - update-cache: - needs: container-build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -35,7 +32,10 @@ jobs: key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} restore-keys: | ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - ${{ runner.os }}-singularity- + - uses: ./.github/workflows/container_build.yml + if: github.event_name != 'schedule' && steps.cache-singularity.outputs.cache-hit != 'true' + with: + deploy: true - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} From 86743c6d78c7b74bcda09969564b7c0708d638aa Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 15:37:12 +0200 Subject: [PATCH 17/27] fix: scan/codecheck not run if def file changed, move core tests to bashscripts --- .github/workflows/code_check.yml | 9 +++------ .github/workflows/config_scan.yml | 24 ++++++++---------------- .github/workflows/container_build.yml | 24 ++++++++++++++++-------- tests/ci/copy_configs.sh | 3 +++ tests/ci/pylint.sh | 8 ++++++++ tests/ci/scan_configs.sh | 8 ++++++++ 6 files changed, 46 insertions(+), 30 deletions(-) create mode 100755 tests/ci/copy_configs.sh create mode 100644 tests/ci/pylint.sh create mode 100755 tests/ci/scan_configs.sh diff --git a/.github/workflows/code_check.yml b/.github/workflows/code_check.yml index 216ea67e..c8fae9ec 100644 --- a/.github/workflows/code_check.yml +++ b/.github/workflows/code_check.yml @@ -26,6 +26,7 @@ jobs: uses: eWaterCycle/setup-apptainer@v2 with: apptainer-version: 1.3.0 + - name: Cache Singularity Image id: cache-singularity uses: actions/cache@v4 @@ -34,11 +35,7 @@ jobs: key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} restore-keys: | ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - - name: Pull Singularity container - if: steps.cache-singularity.outputs.cache-hit != 'true' - run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} - name: Run Pylint - run: | - apptainer exec ${{ env.sif_file }} \ - pylint $(git diff --name-only origin/master...HEAD -- '*.py') + if: steps.cache-singularity.outputs.cache-hit == 'true' + run: bash tests/ci/pylint.sh ${{ env.sif_file }} diff --git a/.github/workflows/config_scan.yml b/.github/workflows/config_scan.yml index 252a77ba..56ea4047 100644 --- a/.github/workflows/config_scan.yml +++ b/.github/workflows/config_scan.yml @@ -1,5 +1,7 @@ name: Scan Configs -on: [pull_request,workflow_call] +on: + pull_request: + push: env: singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image @@ -22,21 +24,11 @@ jobs: key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} restore-keys: | ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - - name: Pull Singularity container - if: steps.cache-singularity.outputs.cache-hit != 'true' - run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} - name: Prepare experiment files - run: | - cp -r resources/config_templates/* config/ - for file in config/user/experiment/*.yaml; do - filename=$(basename "$file" .yaml) - echo "$filename" >> experiments.txt - done + if: steps.cache-singularity.outputs.cache-hit == 'true' + run: bash tests/ci/copy_configs.sh ${{ env.sif_file }} - - name: Scan classification configs - run: | - while IFS= read -r experiment; do - apptainer exec ${{ env.sif_file }} \ - python main.py +experiment="$experiment" command=scan system.device=cpu - done < experiments.txt + - name: Scan configs + if: steps.cache-singularity.outputs.cache-hit == 'true' + run: bash tests/ci/scan_configs.sh ${{ env.sif_file }} diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 0257020f..7d92564f 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -1,11 +1,6 @@ name: Build Singularity Container on: - push: - branches-ignore: - - master - paths: - - 'resources/retinal-rl.def' pull_request: branches: - master @@ -46,13 +41,26 @@ jobs: echo "deploy=false" >> $GITHUB_OUTPUT fi + - name: Cache Singularity Image + id: cache-singularity + uses: actions/cache@v4 + with: + path: ${{ env.sif_file }} + key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + restore-keys: | + ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} + - name: Build Singularity container + if: steps.cache-singularity.outputs.cache-hit != 'true' run: apptainer build ${{ env.sif_file }} resources/retinal-rl.def - - name: Scan classification config / ensure minimal functionality + - name: Scan configs run: | - cp -r resources/config_templates/* config/ - apptainer exec ${{ env.sif_file }} python main.py -m +experiment=classification command=scan system.device=cpu + bash tests/ci/copy_configs.sh ${{ env.sif_file }} + bash tests/ci/scan_configs.sh ${{ env.sif_file }} + + - name: Run code check + run: bash tests/ci/pylint.sh ${{ env.sif_file }} - name: Deployment / Push to ghcr.io if: steps.setup.outputs.deploy == 'true' diff --git a/tests/ci/copy_configs.sh b/tests/ci/copy_configs.sh new file mode 100755 index 00000000..c75a15f5 --- /dev/null +++ b/tests/ci/copy_configs.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cp -r resources/config_templates/* config/ \ No newline at end of file diff --git a/tests/ci/pylint.sh b/tests/ci/pylint.sh new file mode 100644 index 00000000..3fe94995 --- /dev/null +++ b/tests/ci/pylint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# $1 choses the sif container, $2 defines whether pylint is run on all or only the changed files + +if [ "$2" = "--all" ]; then + apptainer exec "$1" pylint . +else + apptainer exec "$1" pylint $(git diff --name-only origin/master...HEAD -- '*.py') +fi \ No newline at end of file diff --git a/tests/ci/scan_configs.sh b/tests/ci/scan_configs.sh new file mode 100755 index 00000000..b6979c8b --- /dev/null +++ b/tests/ci/scan_configs.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# first argument denotes container + +for file in config/user/experiment/*.yaml; do + experiment=$(basename "$file" .yaml) + apptainer exec "$1" \ + python main.py +experiment="$experiment" command=scan system.device=cpu +done \ No newline at end of file From 77fd85a9fd493b8b1b0978c72f1f4af5f5499b67 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 15:50:15 +0200 Subject: [PATCH 18/27] fix: conditional build has to be own job --- .github/workflows/update_cache.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index 6f6bb150..686babca 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -16,7 +16,12 @@ env: sif_file: retinal-rl_singularity-image.sif jobs: + conditional-build: + uses: ./.github/workflows/container_build.yml + with: + deploy: github.event_name != 'schedule' update-cache: + needs: conditional-build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -32,10 +37,6 @@ jobs: key: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} restore-keys: | ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - - uses: ./.github/workflows/container_build.yml - if: github.event_name != 'schedule' && steps.cache-singularity.outputs.cache-hit != 'true' - with: - deploy: true - name: Pull Singularity container if: steps.cache-singularity.outputs.cache-hit != 'true' run: apptainer pull ${{ env.sif_file }} ${{ env.singularity_image }} From 51144c9e1340898b13e016b061fedb4f3bc4c123 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 15:51:19 +0200 Subject: [PATCH 19/27] feat: make all workflows dispatch callable --- .github/workflows/code_check.yml | 1 + .github/workflows/config_scan.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code_check.yml b/.github/workflows/code_check.yml index c8fae9ec..e7fc03b5 100644 --- a/.github/workflows/code_check.yml +++ b/.github/workflows/code_check.yml @@ -6,6 +6,7 @@ on: - master paths: - '**/*.py' + workflow_dispatch: env: singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image diff --git a/.github/workflows/config_scan.yml b/.github/workflows/config_scan.yml index 56ea4047..ef85ae0f 100644 --- a/.github/workflows/config_scan.yml +++ b/.github/workflows/config_scan.yml @@ -1,7 +1,7 @@ name: Scan Configs on: pull_request: - push: + workflow_dispatch: env: singularity_image: oras://ghcr.io/berenslab/retinal-rl:singularity-image From c12bdd997a75e0242aab223dcde5732be32db1cf Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 15:53:22 +0200 Subject: [PATCH 20/27] fix: evaluation of trigger for conditional build --- .github/workflows/update_cache.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index 686babca..eb152613 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -19,7 +19,7 @@ jobs: conditional-build: uses: ./.github/workflows/container_build.yml with: - deploy: github.event_name != 'schedule' + deploy: ${{ github.event_name != 'schedule' }} update-cache: needs: conditional-build runs-on: ubuntu-latest From 3219e4fdbd12d7c03363ce216cb9fd9ba2b7df40 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 16:03:25 +0200 Subject: [PATCH 21/27] fix: container build also needs to fetch master for code check --- .github/workflows/container_build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml index 7d92564f..50ffa3ad 100644 --- a/.github/workflows/container_build.yml +++ b/.github/workflows/container_build.yml @@ -27,7 +27,12 @@ jobs: singularity-build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Fetch all branches + run: git fetch --all - uses: eWaterCycle/setup-apptainer@v2 with: apptainer-version: 1.3.0 From b60a6f26eb2dffa611f7bf1ca336d838e3a5654a Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 16:20:52 +0200 Subject: [PATCH 22/27] fix: make pylint run only if files changed --- tests/ci/pylint.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/ci/pylint.sh b/tests/ci/pylint.sh index 3fe94995..00b21098 100644 --- a/tests/ci/pylint.sh +++ b/tests/ci/pylint.sh @@ -4,5 +4,10 @@ if [ "$2" = "--all" ]; then apptainer exec "$1" pylint . else - apptainer exec "$1" pylint $(git diff --name-only origin/master...HEAD -- '*.py') + changed_files=$(git diff --name-only origin/master...HEAD -- '*.py') + if [ -n "$changed_files" ]; then + apptainer exec "$1" pylint $(git diff --name-only origin/master...HEAD -- '*.py') + else + echo "No .py files changed" + fi fi \ No newline at end of file From 07e2f4563620072d932fdf04c9f9a1ceb84f97a4 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 16:30:47 +0200 Subject: [PATCH 23/27] refactor: make scan/check not run if def file changed --- .github/workflows/code_check.yml | 2 +- .github/workflows/config_scan.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code_check.yml b/.github/workflows/code_check.yml index e7fc03b5..af8ca6a8 100644 --- a/.github/workflows/code_check.yml +++ b/.github/workflows/code_check.yml @@ -5,6 +5,7 @@ on: branches: - master paths: + - ! 'resources/retinal-rl.def' - '**/*.py' workflow_dispatch: @@ -38,5 +39,4 @@ jobs: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - name: Run Pylint - if: steps.cache-singularity.outputs.cache-hit == 'true' run: bash tests/ci/pylint.sh ${{ env.sif_file }} diff --git a/.github/workflows/config_scan.yml b/.github/workflows/config_scan.yml index ef85ae0f..81a22cf8 100644 --- a/.github/workflows/config_scan.yml +++ b/.github/workflows/config_scan.yml @@ -1,6 +1,8 @@ name: Scan Configs on: pull_request: + paths-ignore: + - 'resources/retinal-rl.def' workflow_dispatch: env: @@ -26,9 +28,7 @@ jobs: ${{ runner.os }}-singularity-${{ hashFiles('~/resources/retinal-rl.def') }} - name: Prepare experiment files - if: steps.cache-singularity.outputs.cache-hit == 'true' run: bash tests/ci/copy_configs.sh ${{ env.sif_file }} - name: Scan configs - if: steps.cache-singularity.outputs.cache-hit == 'true' run: bash tests/ci/scan_configs.sh ${{ env.sif_file }} From b3aaee005a74f31d9e47a07c64de8390d03346a3 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 16:48:26 +0200 Subject: [PATCH 24/27] change: only publish sif file on pushes with def changes --- .github/workflows/update_cache.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update_cache.yml b/.github/workflows/update_cache.yml index eb152613..f8da1ce4 100644 --- a/.github/workflows/update_cache.yml +++ b/.github/workflows/update_cache.yml @@ -19,7 +19,7 @@ jobs: conditional-build: uses: ./.github/workflows/container_build.yml with: - deploy: ${{ github.event_name != 'schedule' }} + deploy: ${{ github.event_name == 'push' }} update-cache: needs: conditional-build runs-on: ubuntu-latest From d2ca35a59c7db1f2f18ace46184bf0ce544311ca Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Thu, 17 Oct 2024 17:10:55 +0200 Subject: [PATCH 25/27] change: remove necessity for docstrings --- .pylintrc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 8f1de749..6e84e736 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,15 @@ [MASTER] -init-hook='import sys; sys.path.append(".")' \ No newline at end of file +init-hook='import sys; sys.path.append(".")' + +[MESSAGES CONTROL] + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time. +#enable= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). +disable=missing-function-docstring,missing-module-docstring \ No newline at end of file From 4bce56d3c0a3565dcb3bd7c29b331dda4dc3bc66 Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Fri, 18 Oct 2024 10:40:42 +0200 Subject: [PATCH 26/27] doc: add documentation to bashscripts in tests/ci --- tests/ci/copy_configs.sh | 9 +++++++++ tests/ci/pylint.sh | 18 +++++++++++++++++- tests/ci/scan_configs.sh | 16 +++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/ci/copy_configs.sh b/tests/ci/copy_configs.sh index c75a15f5..df34ccb0 100755 --- a/tests/ci/copy_configs.sh +++ b/tests/ci/copy_configs.sh @@ -1,3 +1,12 @@ #!/bin/bash +#=============================================================================== +# Description: Copies the config files from the resources dir to the config dir. +# Thus creates the basic structure needed to setup or run +# experiments. +# +# Usage: +# tests/ci/copy_configs.sh +# (run from top level directory!) +#=============================================================================== cp -r resources/config_templates/* config/ \ No newline at end of file diff --git a/tests/ci/pylint.sh b/tests/ci/pylint.sh index 00b21098..9fbe97e8 100644 --- a/tests/ci/pylint.sh +++ b/tests/ci/pylint.sh @@ -1,5 +1,21 @@ #!/bin/bash -# $1 choses the sif container, $2 defines whether pylint is run on all or only the changed files +#=============================================================================== +# Description: Runs pylint either on all Python files or only on changed files +# compared to master branch using a specified Singularity container +# +# Arguments: +# $1 - Path to Singularity (.sif) container +# $2 - Optional: "--all" to run on all files, otherwise runs only on changed files +# +# Usage: +# tests/ci/run_pylint.sh container.sif # Lint only changed Python files +# tests/ci/run_pylint.sh container.sif --all # Lint all Python files +# (run from top level directory!) +# +# Dependencies: +# - Singularity/Apptainer +# - Container must have pylint installed +#=============================================================================== if [ "$2" = "--all" ]; then apptainer exec "$1" pylint . diff --git a/tests/ci/scan_configs.sh b/tests/ci/scan_configs.sh index b6979c8b..2d08c588 100755 --- a/tests/ci/scan_configs.sh +++ b/tests/ci/scan_configs.sh @@ -1,5 +1,19 @@ #!/bin/bash -# first argument denotes container +#=============================================================================== +# Description: "Scans" all experiments, that means tries to read the config and +# build the model, than prints the summary. +# +# Arguments: +# $1 - Path to Singularity (.sif) container +# +# Usage: +# tests/ci/run_experiments.sh container.sif +# (run from top level directory!) +# +# Dependencies: +# - Singularity/Apptainer + container +# - YAML configuration files in correct directory +#=============================================================================== for file in config/user/experiment/*.yaml; do experiment=$(basename "$file" .yaml) From d9e4b71e9797589f94b6a50cf069f8a0a676db0a Mon Sep 17 00:00:00 2001 From: Fabio Seel Date: Fri, 18 Oct 2024 11:16:49 +0200 Subject: [PATCH 27/27] doc: update setup part in Readme, mark running simulations as deprecated --- README.md | 66 +++++++++++++++++++++------------------------- tests/ci/pylint.sh | 2 +- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index cd318581..3e45ac65 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,54 @@ +# Retinal RL + ## Setting up the development environment -Unfortunately, putting together a unified build scheme has proven challenging, because our different compute resources rely on different containerization schemes (i.e. bespoke docker vs apptainer), and subtle bugs have emerged that only effect one build system or the other. We maintain a `Dockerfile` for building the docker image and the `retinal_rl.def` file to build the `apptainer` image, and we've also had success building with `conda` on bare metal. +We provide a singularity / apptainer container which should always be up to date and allow to run the code immediately. You do not need to build it yourself (but can, of course), you can just pull it! -### Apptainer +### Install Singularity / Apptainer -The `apptainer` image is self-contained, and building it should immediately allow running the relevant scripts in `retinal-rl`, by prefixing them with `apptainer exec [image]`. The versions of most pip packages are floating, but we have an `environment.yaml` file from a working `apptainer` build. +First you need to install [apptainer](https://github.com/apptainer/apptainer/) (or singularity) in order to run code. -### Conda +### Get the container -Here are the steps to get a `retinal-rl` environment setup in `conda`, which should work on bare metal. First [install anaconda or miniconda](https://docs.anaconda.com/anaconda/install/index.html), and then create the environment -``` bash -conda create --name retinal-rl pip -conda activate retinal-rl -``` -I'm using `miniconda`, so some of the following commands might be redundant if you're using `anaconda`. +Once you have apptainer installed, you can simply pull the container -Next, we install `pytorch` -```bash -conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge -``` -and then install `sample-factory` and `vizdoom` ```bash -pip install sample-factory -pip install vizdoom +apptainer pull retinal-rl.sif oras://ghcr.io/berenslab/retinal-rl:singularity-image ``` -Note, you may require `sample-factory=1.121.4` on a server. You may also want to downgrade the `gym` library with `pip install gym==0.25.2` -For `vizdoom`, `pip install` can sometimes fail when run inside a `conda` environment. In this case the solution is to build `vizdoom` directly by running -```bash -conda install -c conda-forge boost cmake gtk2 sdl2 -git clone https://github.com/mwydmuch/ViZDoom.git --recurse-submodules -cd ViZDoom -python setup.py build && python setup.py install -``` +or try to build it on your own (no advantages of doing that, except you want to change some dependency in the .def file): -We'll also need some other tools and libraries ```bash -conda install -c conda-forge matplotlib pyglet imageio -pip install pygifsicle -pip install openTSNE +apptainer build retinal-rl.sif resources/retinal-rl.def ``` -IPython might also be necessary: + +### Prepare config directory for experiments + +The repository comes with some example configuration files, which you find under 'resources/config_templates'. For running experiments however, they need to be in 'config'. +You can either copy them there by hand or run the following script from the top-level directory: + ```bash -conda install -c conda-forge ipython +bash tests/ci/copy_configs.sh ``` -### Docker +### Test basic functionality -The `Dockerfile` is a thin wrapper around the berenslab `Dockerfile` for the berenslab cluster, but may still serve as a basis for developing a `docker` container for other systems. Regardless, after building the image we then create the `conda` environment as above. +Now you are basically ready to run experiments! +To test that everything is working fine, you can run: -## Running retinal RL simulations +```bash +bash tests/ci/scan_configs.sh +``` + +The script loops over all experiments defined in config/experiment and runs a "scan" on them. +If instead you want to run a single experiment file, run: -Now that we have a (hopefully) working environment, we clone the repo ```bash -https://github.com/berenslab/retinal-rl.git +apptainer exec retinal-rl.sif python main.py +experiment="$experiment" command=scan system.device=cpu ``` + +## Running retinal RL simulations [DEPRECATED] + There are three main scripts for working with `retinal-rl`: - `train.py`: Train a model. diff --git a/tests/ci/pylint.sh b/tests/ci/pylint.sh index 9fbe97e8..efad868a 100644 --- a/tests/ci/pylint.sh +++ b/tests/ci/pylint.sh @@ -13,7 +13,7 @@ # (run from top level directory!) # # Dependencies: -# - Singularity/Apptainer +# - Singularity/Apptainer + container # - Container must have pylint installed #===============================================================================