Skip to content

Merge pull request #111 from dirkjanvw/update_ntsynt_visualisation #41

Merge pull request #111 from dirkjanvw/update_ntsynt_visualisation

Merge pull request #111 from dirkjanvw/update_ntsynt_visualisation #41

name: Build and Push Singularity Containers
on:
push:
paths:
- "MoGAAAP/workflow/singularity/**"
- ".github/workflows/push_containers.yml"
permissions:
contents: read
packages: write
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
changed-def-files: ${{ steps.changes.outputs.changed-def-files }}
workflow-changed: ${{ steps.changes.outputs.workflow-changed }}
steps:
- name: Checkout the code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Detect changes
id: changes
run: |
# Check if workflow file changed
if git diff --name-only HEAD~1 HEAD | grep -q "^\.github/workflows/push_containers\.yml$"; then
echo "workflow-changed=true" >> $GITHUB_OUTPUT
echo "Workflow changed - will build all containers"
else
echo "workflow-changed=false" >> $GITHUB_OUTPUT
fi
# Get changed .def files
changed_def_files=$(git diff --name-only HEAD~1 HEAD | grep "^MoGAAAP/workflow/singularity/.*\.def$" | tr '\n' ' ' | sed 's/ $//')
echo "changed-def-files=${changed_def_files}" >> $GITHUB_OUTPUT
echo "Changed .def files: ${changed_def_files}"
build-and-push:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.changed-def-files != '' || needs.detect-changes.outputs.workflow-changed == 'true'
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Set up Singularity
run: sudo apt-get update && sudo apt-get install -y singularity-container
- name: Install ORAS
run: |
VERSION="1.2.2"
curl -LO "https://github.com/oras-project/oras/releases/download/v${VERSION}/oras_${VERSION}_linux_amd64.tar.gz"
mkdir -p oras-install/
tar -zxf oras_${VERSION}_*.tar.gz -C oras-install/
sudo mv oras-install/oras /usr/local/bin/
rm -rf oras_${VERSION}_*.tar.gz oras-install/
- name: Login to GHCR with ORAS
run: |
echo ${{ secrets.GITHUB_TOKEN }} | oras login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and Push Singularity Containers
run: |
repo_name=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
cd MoGAAAP/workflow/singularity
echo '{"type":"container"}' > config.json
# Determine which files to process
if [ "${{ needs.detect-changes.outputs.workflow-changed }}" = "true" ]; then
echo "Workflow changed - building all containers"
def_files=$(find . -name "*.def" -type f)
else
echo "Building only changed containers"
def_files="${{ needs.detect-changes.outputs.changed-def-files }}"
def_files=$(echo "$def_files" | sed 's|MoGAAAP/workflow/singularity/||g')
fi
# Build and push containers
for def_file in $def_files; do
if [ -f "$def_file" ]; then
echo "Processing: $def_file"
container_name=$(basename "${def_file}" .def | tr '[:upper:]' '[:lower:]')
sudo singularity build "${container_name}.sif" "${def_file}"
oras push --artifact-type application/vnd.sylabs.sif.layer.v1.sif --config config.json:application/vnd.sylabs.sif.config.v1+json ghcr.io/${repo_name}/${container_name}:latest "${container_name}.sif:application/vnd.sylabs.sif.layer.v1.sif"
fi
done