|
| 1 | +# https://spack.readthedocs.io/en/latest/binary_caches.html#spack-build-cache-for-github-actions |
| 2 | +name: Spack Builds (Ubuntu x86_64 Buildcache) |
| 3 | + |
| 4 | +on: [pull_request] |
| 5 | + |
| 6 | +env: |
| 7 | + SPACK_COLOR: always |
| 8 | + REGISTRY: ghcr.io/llnl |
| 9 | + SPACK_CACHE: /opt/spack-cache |
| 10 | + tempdir: /opt/spack-cache |
| 11 | + TMP: /opt/spack-cache |
| 12 | + TMPDIR: /opt/spack-cache |
| 13 | + # Our repo name contains upper case characters, so we can't use ${{ github.repository }} |
| 14 | + IMAGE_NAME: hiop |
| 15 | + USERNAME: hiop-bot |
| 16 | + BASE_VERSION: ubuntu-24.04-fortran |
| 17 | + |
| 18 | +jobs: |
| 19 | + base_image_build: |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + permissions: |
| 22 | + packages: write |
| 23 | + contents: read |
| 24 | + |
| 25 | + name: Build Custom Base Image |
| 26 | + steps: |
| 27 | + # No GHCR base image with skopeo, so this will do... |
| 28 | + - name: "Set up skopeo" |
| 29 | + |
| 30 | + with: |
| 31 | + version: latest |
| 32 | + |
| 33 | + # Use skopeo to check for image for convenience |
| 34 | + - name: Check for existing base images |
| 35 | + run: | |
| 36 | + set -e |
| 37 | + CONTAINER_TAG=${{ env.BASE_VERSION }} |
| 38 | + OCI_URL="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }}" |
| 39 | + echo Checking for CONTAINER_TAG $CONTAINER_TAG |
| 40 | + skopeo inspect \ |
| 41 | + docker://$OCI_URL \ |
| 42 | + --raw \ |
| 43 | + --creds "${{ env.USERNAME }}:${{ secrets.GITHUB_TOKEN }}" \ |
| 44 | + > /dev/null && echo "Image already exists. Please bump version." && exit 0 |
| 45 | + echo "IMAGE_EXISTS=false" >> $GITHUB_ENV |
| 46 | +
|
| 47 | + # Need to build custom base image with gfortran |
| 48 | + - name: Create Dockerfile heredoc |
| 49 | + if: ${{ env.IMAGE_EXISTS == 'false' }} |
| 50 | + run: | |
| 51 | + cat << EOF > Dockerfile |
| 52 | + FROM ubuntu:24.04 |
| 53 | + RUN apt-get update && \ |
| 54 | + apt-get install -y --no-install-recommends \ |
| 55 | + software-properties-common \ |
| 56 | + gpg-agent \ |
| 57 | + openssh-client \ |
| 58 | + openssh-server \ |
| 59 | + && rm -rf /var/lib/apt/lists/* |
| 60 | + RUN add-apt-repository ppa:ubuntu-toolchain-r/test && \ |
| 61 | + apt-get install -y --no-install-recommends \ |
| 62 | + gfortran \ |
| 63 | + gcc \ |
| 64 | + libstdc++6 \ |
| 65 | + && rm -rf /var/lib/apt/lists/* |
| 66 | + EOF |
| 67 | +
|
| 68 | + # https://docs.github.com/en/actions/publishing-packages/publishing-docker-images |
| 69 | + - name: Log in to the Container registry |
| 70 | + uses: docker/login-action@v3 |
| 71 | + with: |
| 72 | + registry: ${{ env.REGISTRY }} |
| 73 | + username: ${{ env.USERNAME }} |
| 74 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + |
| 76 | + - name: Extract metadata (tags, labels) for Docker |
| 77 | + if: ${{ env.IMAGE_EXISTS == 'false' }} |
| 78 | + id: meta |
| 79 | + uses: docker/metadata-action@v5 |
| 80 | + with: |
| 81 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 82 | + labels: org.opencontainers.image.version=${{ env.BASE_VERSION }} |
| 83 | + |
| 84 | + - name: Build and push Docker base image |
| 85 | + if: ${{ env.IMAGE_EXISTS == 'false' }} |
| 86 | + uses: docker/build-push-action@v5 |
| 87 | + with: |
| 88 | + context: . |
| 89 | + push: true |
| 90 | + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }} |
| 91 | + labels: ${{ steps.meta.outputs.labels }} |
| 92 | + |
| 93 | + hiop_spack_builds: |
| 94 | + needs: base_image_build |
| 95 | + runs-on: ubuntu-22.04 |
| 96 | + permissions: |
| 97 | + packages: write |
| 98 | + contents: read |
| 99 | + strategy: |
| 100 | + matrix: |
| 101 | + spack_spec: |
| 102 | + - hiop@develop+mpi~raja~shared~kron~sparse ^openblas ^openmpi ^libevent~openssl |
| 103 | + - hiop@develop~mpi~raja~shared~kron~sparse ^openblas ^libevent~openssl |
| 104 | + - hiop@develop~mpi+raja~shared~kron~sparse ^openblas ^libevent~openssl |
| 105 | + |
| 106 | + # We will need coinhsl for this, but what are the rules for using |
| 107 | + # a coinhsl tarball? |
| 108 | + # - hiop@develop~mpi~raja~shared~kron+sparse |
| 109 | + |
| 110 | + name: Build HiOp with Spack |
| 111 | + |
| 112 | + steps: |
| 113 | + - name: Checkout |
| 114 | + uses: actions/checkout@v4 |
| 115 | + with: |
| 116 | + # Once we move submodule deps into spack, we can do some more builds |
| 117 | + # Also need to change build script to use spack from base image |
| 118 | + submodules: true |
| 119 | + |
| 120 | + - name: Clone Spack |
| 121 | + run: git clone https://github.com/spack/spack.git |
| 122 | + |
| 123 | + - name: Setup Spack |
| 124 | + run: echo "$PWD/spack/bin" >> "$GITHUB_PATH" |
| 125 | + |
| 126 | + - name: Create heredoc spack.yaml |
| 127 | + run: | |
| 128 | + spack debug report |
| 129 | + cat << EOF > spack.yaml |
| 130 | + spack: |
| 131 | + specs: |
| 132 | + - ${{ matrix.spack_spec }} target=x86_64_v2 |
| 133 | + concretizer: |
| 134 | + reuse: dependencies |
| 135 | + config: |
| 136 | + source_cache: $SPACK_CACHE/source_cache |
| 137 | + misc_cache: $SPACK_CACHE/misc_cache |
| 138 | + build_stage: $SPACK_CACHE/build_stage |
| 139 | + install_tree: |
| 140 | + root: /opt/spack |
| 141 | + padded_length: False |
| 142 | + mirrors: |
| 143 | + local-buildcache: oci://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 144 | + # spack: https://binaries.spack.io/develop |
| 145 | + packages: |
| 146 | + all: |
| 147 | + require: "%gcc" |
| 148 | + EOF |
| 149 | +
|
| 150 | + - name: Configure GHCR mirror |
| 151 | + run: spack -e . mirror set --oci-username ${{ env.USERNAME }} --oci-password "${{ secrets.GITHUB_TOKEN }}" local-buildcache |
| 152 | + |
| 153 | + - name: Trust keys |
| 154 | + run: spack -e . buildcache keys --install --trust |
| 155 | + |
| 156 | + - name: Find external packages |
| 157 | + run: spack -e . external find --all --exclude python --exclude curl --exclude openssl |
| 158 | + |
| 159 | + - name: Spack develop HiOp |
| 160 | + run: spack -e . develop --path=$(pwd) hiop@git."${{ github.head_ref || github.ref_name }}"=develop |
| 161 | + |
| 162 | + - name: Concretize |
| 163 | + run: spack -e . concretize --fresh |
| 164 | + |
| 165 | + - name: Install Dependencies |
| 166 | + run: spack -e . install --no-check-signature --fail-fast --show-log-on-error --verbose --only dependencies |
| 167 | + |
| 168 | + - name: Install HiOp |
| 169 | + run: | |
| 170 | + ls -al |
| 171 | + spack -d -e . install --keep-stage --verbose --show-log-on-error --only package --no-cache |
| 172 | +
|
| 173 | + - name: Test Build |
| 174 | + run: | |
| 175 | + # Not all pipelines have `+mpi`, so this command might fail |
| 176 | + # Command also only prints shell commands, need to source |
| 177 | + spack -e . load --sh openmpi > env.txt || [ rm env.txt || true ] |
| 178 | + source env.txt || true |
| 179 | + cd $(spack -e . location --build-dir hiop@develop) |
| 180 | + ctest -VV |
| 181 | +
|
| 182 | + - name: Push binaries to buildcache |
| 183 | + run: | |
| 184 | + spack -e . buildcache push --force --base-image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }} --unsigned --update-index local-buildcache |
| 185 | + if: ${{ !cancelled() }} |
0 commit comments