Add Protein-Hunter #14
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: Create and publish Docker images | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| container: | |
| description: 'Container to build (e.g., rfdiffusion)' | |
| required: false | |
| type: string | |
| version: | |
| description: 'Version/tag to build (e.g., cuda11)' | |
| required: false | |
| type: string | |
| push: | |
| branches: | |
| - '**' | |
| paths: | |
| - 'dockerfiles/*/*/Dockerfile' | |
| - '.github/workflows/docker-build-push.yml' | |
| env: | |
| REGISTRY: ghcr.io | |
| ORGANIZATION: australian-protein-design-initiative/containers | |
| jobs: | |
| detect-changes: | |
| runs-on: self-hosted | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get changed files | |
| id: changed-files | |
| if: github.event_name == 'push' | |
| uses: tj-actions/changed-files@v42 | |
| with: | |
| files: dockerfiles/*/*/Dockerfile | |
| - id: set-matrix | |
| run: | | |
| generate_container_info() { | |
| local path="$1" | |
| local container=$(echo "$path" | cut -d'/' -f2) | |
| local version=$(echo "$path" | cut -d'/' -f3) | |
| # Default to amd64 only unless specified in Dockerfile | |
| local platforms="linux/amd64" | |
| if grep -q "^LABEL.*org.australian-protein-design-initiative.image.platforms=" "$path/Dockerfile"; then | |
| platforms=$(grep "^LABEL.*org.australian-protein-design-initiative.image.platforms=" "$path/Dockerfile" | sed 's/.*platforms="\(.*\)".*/\1/') | |
| fi | |
| echo "{\"container\":\"$container\",\"version\":\"$version\",\"path\":\"$path\",\"platforms\":\"$platforms\"}" | |
| } | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ inputs.container }}" ]; then | |
| # Manual trigger for specific container | |
| if [ -n "${{ inputs.version }}" ]; then | |
| # Specific version requested | |
| if [ -d "dockerfiles/${{ inputs.container }}/${{ inputs.version }}" ]; then | |
| CONTAINER_INFO=$(generate_container_info "dockerfiles/${{ inputs.container }}/${{ inputs.version }}") | |
| CONTAINERS=$(echo "$CONTAINER_INFO" | jq -c '{include: [.]}') | |
| else | |
| echo "Error: Specified container/version combination does not exist" | |
| exit 1 | |
| fi | |
| else | |
| # All versions of specified container | |
| CONTAINERS_JSON="[]" | |
| while IFS= read -r dir; do | |
| CONTAINER_INFO=$(generate_container_info "$dir") | |
| CONTAINERS_JSON=$(echo "$CONTAINERS_JSON" | jq --arg info "$CONTAINER_INFO" '. += [($info | fromjson)]') | |
| done < <(find dockerfiles/${{ inputs.container }} -mindepth 1 -maxdepth 1 -type d) | |
| CONTAINERS=$(echo "$CONTAINERS_JSON" | jq -c '{include: .}') | |
| fi | |
| else | |
| # Push trigger - use changed files | |
| CONTAINERS_JSON="[]" | |
| for file in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
| dir=$(dirname "$file") | |
| CONTAINER_INFO=$(generate_container_info "$dir") | |
| CONTAINERS_JSON=$(echo "$CONTAINERS_JSON" | jq --arg info "$CONTAINER_INFO" '. += [($info | fromjson)]') | |
| done | |
| if [ -z "$CONTAINERS_JSON" ] || [ "$CONTAINERS_JSON" == "[]" ]; then | |
| echo "matrix={\"include\":[]}" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| CONTAINERS=$(echo "$CONTAINERS_JSON" | jq -c '{include: .}') | |
| fi | |
| echo "matrix=${CONTAINERS}" >> $GITHUB_OUTPUT | |
| build-and-push-image: | |
| needs: detect-changes | |
| if: ${{ fromJson(needs.detect-changes.outputs.matrix).include[0] }} | |
| runs-on: self-hosted | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| strategy: | |
| fail-fast: false | |
| max-parallel: 1 | |
| matrix: ${{fromJson(needs.detect-changes.outputs.matrix)}} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get current date | |
| id: datestamp | |
| run: echo "datestamp=$(date '+%F.%H%M%S')" >> $GITHUB_ENV | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${{ matrix.container }} | |
| labels: | | |
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| push: true | |
| platforms: ${{ matrix.platforms }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| context: ${{ matrix.path }} | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${{ matrix.container }}:${{ matrix.version }} | |
| ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${{ matrix.container }}:${{ matrix.version }}-${{ github.run_number }} | |
| ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${{ matrix.container }}:${{ matrix.version }}-${{ env.datestamp }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| file: ${{ matrix.path }}/Dockerfile | |
| secrets: | | |
| "rosetta_password=${{ secrets.ROSETTA_PASSWORD }}" |