Build Bioconductor Extension Images #3
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: Build Bioconductor Extension Images | |
on: | |
push: | |
branches: | |
- devel | |
- RELEASE_* | |
paths: | |
- 'extensions/**' | |
workflow_dispatch: | |
inputs: | |
specific_extension: | |
description: 'Build only a specific extension (folder name in extensions/)' | |
required: false | |
type: string | |
schedule: | |
- cron: '0 20 * * 5' # Run every Friday at 8PM UTC | |
jobs: | |
build-extensions: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Free root space | |
uses: almahmoud/free-root-space@main | |
with: | |
verbose: true | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to Dockerhub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Install dependencies | |
run: | | |
# Install yq for YAML parsing | |
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 | |
chmod +x /usr/local/bin/yq | |
- name: Find extensions | |
id: find_extensions | |
run: | | |
if [[ -n "${{ github.event.inputs.specific_extension }}" ]]; then | |
# Check if the specified extension exists | |
if [[ -d "extensions/${{ github.event.inputs.specific_extension }}" ]]; then | |
echo "extensions=$(find extensions/${{ github.event.inputs.specific_extension }} -name 'bioc-extension.yaml')" >> $GITHUB_OUTPUT | |
echo "Building specific extension: ${{ github.event.inputs.specific_extension }}" | |
else | |
echo "::error::Extension directory not found: extensions/${{ github.event.inputs.specific_extension }}" | |
exit 1 | |
fi | |
else | |
# Find all extensions | |
echo "extensions=$(find extensions -name 'bioc-extension.yaml' | sort)" >> $GITHUB_OUTPUT | |
echo "Building all available extensions" | |
fi | |
- name: Process extensions | |
run: | | |
mkdir -p /tmp/extension_builds | |
branch="${GITHUB_REF##*/}" | |
for ext_file in $(echo "${{ steps.find_extensions.outputs.extensions }}"); do | |
ext_dir=$(dirname "$ext_file") | |
ext_name=$(basename "$ext_dir") | |
echo "Processing extension: $ext_name from $ext_file" | |
# Parse YAML directly using yq | |
outname=$(yq '.container.outname' "$ext_file") | |
base_image=$(yq '.container.base.image' "$ext_file") | |
# Handle tags which could be a string, list, or map | |
tags=$(yq -o=json '.container.base.tag' "$ext_file") | |
# Process tags based on their type | |
if [[ "$tags" == "null" ]]; then | |
tags="$branch" | |
elif [[ "$tags" == "{\"*\"}" ]]; then | |
# Handle object format like {"3.21", "devel"} | |
tags=$(echo "$tags" | jq -r 'keys | join(" ")') | |
elif [[ "$tags" == "[*]" ]]; then | |
# Handle array format | |
tags=$(echo "$tags" | jq -r 'join(" ")') | |
fi | |
echo "Building extension $ext_name: $outname from $base_image with tags: $tags" | |
# Process each tag | |
for tag in $tags; do | |
echo "Building for tag: $tag" | |
# Check for Dockerfile in extension directory | |
if [ -f "$ext_dir/Dockerfile" ]; then | |
echo "Using extension Dockerfile at $ext_dir/Dockerfile" | |
docker buildx build --platform linux/amd64 \ | |
-t "ghcr.io/${{ github.repository_owner }}/$outname:$tag" \ | |
-t "docker.io/${{ github.repository_owner }}/$outname:$tag" \ | |
--build-arg BASE_IMAGE=$base_image \ | |
--build-arg TAG=$tag \ | |
--push \ | |
"$ext_dir" | |
echo "Successfully built and pushed $outname:$tag" | |
else | |
echo "No Dockerfile found for extension $ext_name" | |
fi | |
done | |
done |