|
1 |
| -name: gridkit-bot pre-commit |
| 1 | +# https://spack.readthedocs.io/en/latest/binary_caches.html#spack-build-cache-for-github-actions |
| 2 | +name: Spack Ubunutu x86_64 Buildcache |
2 | 3 |
|
3 |
| -# Won't run on develop/main directly |
| 4 | +env: |
| 5 | + SPACK_COLOR: always |
| 6 | + REGISTRY: ghcr.io/ornl |
| 7 | + # Our repo name contains upper case characters, so we can't use ${{ github.repository }} |
| 8 | + IMAGE_NAME: gridkit |
| 9 | + USERNAME: gridkit-bot |
| 10 | + BASE_VERSION: ubuntu-24.04-fortran-v0.2.2 |
| 11 | + |
| 12 | +# Until we remove the need to clone submodules to build, this should on be in PRs |
4 | 13 | on: [pull_request]
|
5 | 14 |
|
6 | 15 | jobs:
|
7 |
| - pre-commit: |
8 |
| - runs-on: ubuntu-latest |
| 16 | + base_image_build: |
| 17 | + name: Build base image |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
9 | 22 | steps:
|
10 |
| - - uses: actions/checkout@v3 |
11 |
| - with: |
12 |
| - ref: ${{ github.event.pull_request.head.ref }} |
13 |
| - |
14 |
| - - uses: pre-commit/[email protected] |
15 |
| - |
16 |
| - # Only need to try and commit if the action failed |
17 |
| - if: failure() |
18 |
| - with: |
19 |
| - fetch: false |
20 |
| - committer_name: GitHub Actions |
21 |
| - committer_email: [email protected] |
22 |
| - message: Apply pre-commmit fixes |
23 |
| - |
| 23 | + # No GHCR base image with skopeo, so this will do... |
| 24 | + - name: "Set up skopeo" |
| 25 | + |
| 26 | + with: |
| 27 | + version: latest |
| 28 | + |
| 29 | + # Use skopeo to check for image for convenience |
| 30 | + - name: Check for existing base images |
| 31 | + run: | |
| 32 | + set -e |
| 33 | + CONTAINER_TAG=${{ env.BASE_VERSION }} |
| 34 | + OCI_URL="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }}" |
| 35 | + echo Checking for CONTAINER_TAG $CONTAINER_TAG |
| 36 | + skopeo inspect \ |
| 37 | + docker://$OCI_URL \ |
| 38 | + --raw \ |
| 39 | + --creds "${{ env.USERNAME }}:${{ secrets.GITHUB_TOKEN }}" \ |
| 40 | + > /dev/null && echo "Image already exists. Please bump version." && exit 0 |
| 41 | + echo "IMAGE_EXISTS=false" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + # https://docs.github.com/en/actions/publishing-packages/publishing-docker-images |
| 44 | + - name: Log in to the Container registry |
| 45 | + uses: docker/login-action@v3 |
| 46 | + with: |
| 47 | + registry: ${{ env.REGISTRY }} |
| 48 | + username: ${{ env.USERNAME }} |
| 49 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + |
| 51 | + # Need to build custom base image with gfortran |
| 52 | + - name: Create Dockerfile heredoc |
| 53 | + if: ${{ env.IMAGE_EXISTS == 'false' }} |
| 54 | + run: | |
| 55 | + cat << EOF > Dockerfile |
| 56 | + FROM ubuntu:24.04 |
| 57 | + RUN apt-get update && \ |
| 58 | + apt-get install -y --no-install-recommends \ |
| 59 | + software-properties-common \ |
| 60 | + gpg-agent \ |
| 61 | + openssh-client \ |
| 62 | + openssh-server \ |
| 63 | + && rm -rf /var/lib/apt/lists/* |
| 64 | + RUN add-apt-repository ppa:ubuntu-toolchain-r/test && \ |
| 65 | + apt-get install -y --no-install-recommends \ |
| 66 | + gcc \ |
| 67 | + libstdc++6 \ |
| 68 | + && rm -rf /var/lib/apt/lists/* |
| 69 | + EOF |
| 70 | +
|
| 71 | + - name: Extract metadata (tags, labels) for Docker |
| 72 | + if: ${{ env.IMAGE_EXISTS == 'false' }} |
| 73 | + id: meta |
| 74 | + uses: docker/metadata-action@v5 |
| 75 | + with: |
| 76 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 77 | + labels: org.opencontainers.image.version=${{ env.BASE_VERSION }} |
| 78 | + |
| 79 | + - name: Build and push Docker base image |
| 80 | + if: ${{ env.IMAGE_EXISTS == 'false' }} |
| 81 | + uses: docker/build-push-action@v5 |
| 82 | + with: |
| 83 | + context: . |
| 84 | + push: true |
| 85 | + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }} |
| 86 | + labels: ${{ steps.meta.outputs.labels }} |
| 87 | + |
| 88 | + gridkit_spack_builds: |
| 89 | + needs: base_image_build |
| 90 | + runs-on: ubuntu-24.04 |
| 91 | + permissions: |
| 92 | + packages: write |
| 93 | + contents: read |
| 94 | + timeout-minutes: 30 |
| 95 | + |
| 96 | + strategy: |
| 97 | + matrix: |
| 98 | + # Minimal Build(s) - GHCR mirror speeds these up a lot! |
| 99 | + spack_spec: |
| 100 | + - gridkit@develop +enzyme |
| 101 | + |
| 102 | + name: Build gridkit with Spack |
| 103 | + steps: |
| 104 | + - name: Checkout |
| 105 | + uses: actions/checkout@v4 |
| 106 | + with: |
| 107 | + # Once we move submodule deps into spack, we can do some more builds |
| 108 | + # Also need to change build script to use spack from base image |
| 109 | + submodules: true |
| 110 | + |
| 111 | + - name: Setup Spack |
| 112 | + run: echo "$PWD/buildsystem/spack/spack/bin" >> "$GITHUB_PATH" |
| 113 | + |
| 114 | + - name: Create heredoc spack.yaml |
| 115 | + run: | |
| 116 | + cat << EOF > spack.yaml |
| 117 | + spack: |
| 118 | + specs: |
| 119 | + - ${{ matrix.spack_spec }} target=x86_64_v2 |
| 120 | + concretizer: |
| 121 | + reuse: dependencies |
| 122 | + config: |
| 123 | + install_tree: |
| 124 | + root: /opt/spack |
| 125 | + padded_length: 128 |
| 126 | + mirrors: |
| 127 | + local-buildcache: oci://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 128 | + spack: https://binaries.spack.io/develop |
| 129 | + packages: |
| 130 | + llvm: |
| 131 | + externals: |
| 132 | + - spec: llvm@16 |
| 133 | + prefix: /usr/lib/llvm-16 |
| 134 | + EOF |
| 135 | +
|
| 136 | + - name: Configure GHCR mirror |
| 137 | + run: spack -e . mirror set --oci-username ${{ env.USERNAME }} --oci-password "${{ secrets.GITHUB_TOKEN }}" local-buildcache |
| 138 | + |
| 139 | + - name: Trust keys |
| 140 | + run: spack -e . buildcache keys --install --trust |
| 141 | + |
| 142 | + - name: Find external packages |
| 143 | + run: spack -e . external find --all --exclude llvm |
| 144 | + |
| 145 | + - name: Spack develop gridkit |
| 146 | + run: spack -e . develop --path=$(pwd) gridkit@develop |
| 147 | + |
| 148 | + - name: List working directory |
| 149 | + run: ls -ltrh $(pwd)/*/*/ |
| 150 | + |
| 151 | + - name: Concretize |
| 152 | + run: spack -e . concretize |
| 153 | + |
| 154 | + - name: Install dependencies |
| 155 | + run: spack -e . install --no-check-signature --only dependencies |
| 156 | + |
| 157 | + - name: Install package |
| 158 | + run: spack -e . install --keep-stage --no-check-signature --no-cache --fresh |
| 159 | + |
| 160 | + - name: Test Build |
| 161 | + run: cd $(spack -e . location --build-dir gridkit@develop) && ctest -VV |
| 162 | + |
| 163 | + # Push with force to override existing binaries... |
| 164 | + - name: Push to binaries to buildcache |
| 165 | + run: | |
| 166 | + spack -e . buildcache push --force --base-image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }} --unsigned --update-index local-buildcache |
| 167 | + if: ${{ !cancelled() }} |
0 commit comments