Skip to content

LoFreq dockerfile

LoFreq dockerfile #243

name: Build and Push Script Containers
on:
push:
paths:
- '**/Dockerfile'
- '.github/workflows/build-containers.yml'
pull_request:
paths:
- '**/Dockerfile'
- '.github/workflows/build-containers.yml'
workflow_dispatch:
env:
REGISTRY: ghcr.io
REPO: lcr-bccrc/lcr-scripts
jobs:
discover:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.find.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Find all Dockerfiles
id: find
run: |
matrix=$(find . -name Dockerfile -not -path './.git/*' \
| sed 's|^\./||' \
| jq -R '{dockerfile: .}' \
| jq -sc '{include: .}')
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
build:
needs: discover
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.discover.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Parse script name and version from path
id: meta
run: |
# Expects paths like: augment_manta_vcf/1.1/Dockerfile
SCRIPT=$(echo "${{ matrix.dockerfile }}" | cut -d/ -f1)
VERSION=$(echo "${{ matrix.dockerfile }}" | cut -d/ -f2)
echo "script=$SCRIPT" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "image=${{ env.REGISTRY }}/${{ env.REPO }}/${SCRIPT}:${VERSION}" >> "$GITHUB_OUTPUT"
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.dockerfile }}
push: ${{ github.ref == 'refs/heads/master' }}
load: ${{ github.ref != 'refs/heads/master' }}
tags: ${{ steps.meta.outputs.image }}
cache-from: type=gha,scope=${{ steps.meta.outputs.script }}-${{ steps.meta.outputs.version }}
cache-to: type=gha,mode=max,scope=${{ steps.meta.outputs.script }}-${{ steps.meta.outputs.version }}
- name: Run tests in container
if: github.ref != 'refs/heads/master'
run: |
SCRIPT="${{ steps.meta.outputs.script }}"
VERSION="${{ steps.meta.outputs.version }}"
if [ -f "${SCRIPT}/${VERSION}/run_tests.sh" ]; then
echo "Running tests for ${SCRIPT}/${VERSION}"
docker run --rm \
-v "${{ github.workspace }}:/repo" \
-w "/repo/${SCRIPT}/${VERSION}" \
--user "$(id -u):$(id -g)" \
${{ steps.meta.outputs.image }} \
bash run_tests.sh tests/docker_output
else
echo "No run_tests.sh found for ${SCRIPT}/${VERSION}, skipping."
fi
- name: Compare Docker outputs against golden files
if: github.ref != 'refs/heads/master'
run: |
SCRIPT="${{ steps.meta.outputs.script }}"
VERSION="${{ steps.meta.outputs.version }}"
GOLDEN="${SCRIPT}/${VERSION}/tests/output"
DOCKER="${SCRIPT}/${VERSION}/tests/docker_output"
if [ ! -d "$GOLDEN" ] || [ -z "$(ls -A $GOLDEN 2>/dev/null)" ]; then
echo "No golden files committed yet — skipping comparison."
echo "Generate them by running ./run_tests.sh in the conda environment and committing tests/output/."
exit 0
fi
PASS=true
for golden_file in "$GOLDEN"/*; do
[ -f "$golden_file" ] || continue
name=$(basename "$golden_file")
[[ "$name" == *.log ]] && continue
docker_file="$DOCKER/$name"
if [ ! -f "$docker_file" ]; then
echo "FAIL: $name missing from Docker output"
PASS=false
continue
fi
if diff \
<(grep -v "^##cmdline\|^##regions_bed" "$golden_file") \
<(grep -v "^##cmdline\|^##regions_bed" "$docker_file"); then
echo "PASS: $name"
else
echo "FAIL: $name differs from golden file"
PASS=false
fi
done
$PASS