|
| 1 | +name: ci/cd |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + repository_dispatch: |
| 5 | + types: [build] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + timeout-minutes: 360 |
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + platform: |
| 15 | + - linux/amd64 |
| 16 | + #- linux/arm64 |
| 17 | + runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-24.04' || matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' }} |
| 18 | + name: build ${{ matrix.platform }} |
| 19 | + outputs: |
| 20 | + tag: ${{ steps.envvars.outputs.tag }} |
| 21 | + steps: |
| 22 | + - name: checkout |
| 23 | + uses: actions/checkout@v5.0.0 |
| 24 | + |
| 25 | + - name: Prepare env |
| 26 | + id: envvars |
| 27 | + run: | |
| 28 | + platform=${{ matrix.platform }} |
| 29 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 30 | + if [ ${{ github.event.client_payload.tag }} != 'null' ]; then |
| 31 | + echo "tag=${{ github.event.client_payload.tag }}" >> $GITHUB_OUTPUT |
| 32 | + else |
| 33 | + echo "tag=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Metadata |
| 37 | + id: meta |
| 38 | + uses: docker/metadata-action@v5.8.0 |
| 39 | + with: |
| 40 | + images: ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }} |
| 41 | + |
| 42 | + - name: Authenticate with GHCR |
| 43 | + id: auth |
| 44 | + uses: docker/login-action@v3.6.0 |
| 45 | + with: |
| 46 | + registry: ghcr.io |
| 47 | + username: ${{ github.repository_owner }} |
| 48 | + password: ${{ secrets.BUILD_TOKEN }} |
| 49 | + |
| 50 | + - name: Set up Docker Buildx |
| 51 | + id: buildx |
| 52 | + uses: docker/setup-buildx-action@v3.11.1 |
| 53 | + |
| 54 | + - name: Build and push by digest |
| 55 | + id: build |
| 56 | + uses: docker/build-push-action@v6.18.0 |
| 57 | + with: |
| 58 | + file: ./docker/Dockerfile |
| 59 | + platforms: ${{ matrix.platform }} |
| 60 | + labels: ${{ steps.meta.outputs.labels }} |
| 61 | + tags: ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }} |
| 62 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 63 | + |
| 64 | + #- name: Test notebooks |
| 65 | + # shell: bash |
| 66 | + # run: | |
| 67 | + # docker run -t ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}@${{ steps.build.outputs.digest }} bash -c " \ |
| 68 | + # pip install pytest nbmake; \ |
| 69 | + # find ./notebooks -name '*.ipynb' | pytest --nbmake --nbmake-timeout=3600;" |
| 70 | + |
| 71 | + - name: Export digest |
| 72 | + run: | |
| 73 | + mkdir -p ${{ runner.temp }}/digests |
| 74 | + digest="${{ steps.build.outputs.digest }}" |
| 75 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 76 | +
|
| 77 | + - name: Upload digest |
| 78 | + uses: actions/upload-artifact@v4.6.2 |
| 79 | + with: |
| 80 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 81 | + path: ${{ runner.temp }}/digests/* |
| 82 | + if-no-files-found: error |
| 83 | + retention-days: 1 |
| 84 | + |
| 85 | + tags: |
| 86 | + if: github.event_name != 'pull_request' |
| 87 | + runs-on: ubuntu-24.04 |
| 88 | + name: merge and tag |
| 89 | + needs: |
| 90 | + - build |
| 91 | + steps: |
| 92 | + - name: Download digests |
| 93 | + uses: actions/download-artifact@v5.0.0 |
| 94 | + with: |
| 95 | + path: ${{ runner.temp }}/digests |
| 96 | + pattern: digests-* |
| 97 | + merge-multiple: true |
| 98 | + |
| 99 | + - name: Authenticate with GHCR |
| 100 | + id: auth |
| 101 | + uses: docker/login-action@v3.6.0 |
| 102 | + with: |
| 103 | + registry: ghcr.io |
| 104 | + username: ${{ github.repository_owner }} |
| 105 | + password: ${{ secrets.BUILD_TOKEN }} |
| 106 | + |
| 107 | + - name: Set up Docker Buildx |
| 108 | + id: buildx |
| 109 | + uses: docker/setup-buildx-action@v3.11.1 |
| 110 | + |
| 111 | + - name: Metadata |
| 112 | + id: meta |
| 113 | + uses: docker/metadata-action@v5.8.0 |
| 114 | + with: |
| 115 | + images: ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }} |
| 116 | + tags: | |
| 117 | + latest |
| 118 | + ${{ needs.build.outputs.tag }} |
| 119 | +
|
| 120 | + - name: Create manifest list and push |
| 121 | + id: annotate |
| 122 | + continue-on-error: true |
| 123 | + working-directory: ${{ runner.temp }}/digests |
| 124 | + run: | |
| 125 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 126 | + --annotation='index:org.opencontainers.image.description=${{ github.event.repository.description }}' \ |
| 127 | + --annotation='index:org.opencontainers.image.licenses=MIT' \ |
| 128 | + --annotation='index:org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}' \ |
| 129 | + --annotation='index:org.opencontainers.image.url=${{ github.event.repository.url }}' \ |
| 130 | + --annotation='index:org.opencontainers.image.source=${{ github.event.repository.url }}' \ |
| 131 | + $(printf 'ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}@sha256:%s ' *) |
| 132 | +
|
| 133 | + - name: Create manifest list and push without annotations |
| 134 | + if: steps.annotate.outcome == 'failure' |
| 135 | + working-directory: ${{ runner.temp }}/digests |
| 136 | + run: | |
| 137 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 138 | + $(printf 'ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}@sha256:%s ' *) |
| 139 | +
|
| 140 | + - name: Inspect image |
| 141 | + run: | |
| 142 | + docker buildx imagetools inspect ghcr.io/${{ vars.ORG_REPO }}/${{ github.event.repository.name }}:latest |
| 143 | +
|
| 144 | + - name: Post version update to dash |
| 145 | + uses: peter-evans/repository-dispatch@v4.0.0 |
| 146 | + with: |
| 147 | + token: ${{ secrets.BUILD_TOKEN }} |
| 148 | + repository: ccpbiosim/ccpbiosim.github.io |
| 149 | + event-type: build |
| 150 | + client-payload: '{"repo": "${{ github.event.repository.name }}", "tag": "${{ needs.build.outputs.tag }}"}' |
0 commit comments