Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions .github/workflows/spack_default_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# https://spack.readthedocs.io/en/latest/binary_caches.html#spack-build-cache-for-github-actions
name: Spack Ubunutu x86_64 Buildcache

env:
SPACK_COLOR: always
REGISTRY: ghcr.io/ornl
# Our repo name contains upper case characters, so we can't use ${{ github.repository }}
IMAGE_NAME: gridkit
USERNAME: gridkit-bot
BASE_VERSION: ubuntu-22.04-fortran-v0.1.0

# Until we remove the need to clone submodules to build, this should on be in PRs
on: [pull_request]

jobs:
base_image_build:
name: Build base image
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
# No GHCR base image with skopeo, so this will do...
- name: "Set up skopeo"
uses: warjiang/setup-skopeo@v0.1.3
with:
version: latest

# Use skopeo to check for image for convenience
- name: Check for existing base images
run: |
set -e
CONTAINER_TAG=${{ env.BASE_VERSION }}
OCI_URL="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }}"
echo Checking for CONTAINER_TAG $CONTAINER_TAG
skopeo inspect \
docker://$OCI_URL \
--raw \
--creds "${{ env.USERNAME }}:${{ secrets.GITHUB_TOKEN }}" \
> /dev/null && echo "Image already exists. Please bump version." && exit 0
echo "IMAGE_EXISTS=false" >> $GITHUB_ENV

# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}

# Need to build custom base image with gfortran
- name: Create Dockerfile heredoc
if: ${{ env.IMAGE_EXISTS == 'false' }}
run: |
cat << EOF > Dockerfile
FROM ubuntu:22.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
software-properties-common \
gpg-agent \
openssh-client \
openssh-server \
&& rm -rf /var/lib/apt/lists/*
RUN add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get install -y --no-install-recommends \
gcc \
libstdc++6 \
&& rm -rf /var/lib/apt/lists/*
EOF

- name: Extract metadata (tags, labels) for Docker
if: ${{ env.IMAGE_EXISTS == 'false' }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: org.opencontainers.image.version=${{ env.BASE_VERSION }}

- name: Build and push Docker base image
if: ${{ env.IMAGE_EXISTS == 'false' }}
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }}
labels: ${{ steps.meta.outputs.labels }}

gridkit_spack_builds:
needs: base_image_build
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read

strategy:
matrix:
# Minimal Build(s) - GHCR mirror speeds these up a lot!
spack_spec:
- gridkit@develop

name: Build gridkit with Spack
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Once we move submodule deps into spack, we can do some more builds
# Also need to change build script to use spack from base image
submodules: true

- name: Setup Spack
run: echo "$PWD/Buildsystem/spack/spack/bin" >> "$GITHUB_PATH"

- name: Create heredoc spack.yaml
run: |
cat << EOF > spack.yaml
spack:
specs:
- ${{ matrix.spack_spec }} target=x86_64_v2
concretizer:
reuse: dependencies
config:
install_tree:
root: /opt/spack
padded_length: 128
mirrors:
local-buildcache: oci://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
spack: https://binaries.spack.io/develop
EOF

- name: Configure GHCR mirror
run: spack -e . mirror set --oci-username ${{ env.USERNAME }} --oci-password "${{ secrets.GITHUB_TOKEN }}" local-buildcache

- name: Trust keys
run: spack -e . buildcache keys --install --trust

- name: Find external packages
run: spack -e . external find --all

- name: Spack develop gridkit
run: spack -e . develop --path=$(pwd) gridkit@develop

- name: Concretize
run: spack -e . concretize

- name: Install dependencies
run: spack -e . install --no-check-signature --only dependencies

- name: Install package
run: spack -e . install --keep-stage --no-check-signature --no-cache --fresh

- name: Test Build
run: cd $(spack -e . location --build-dir gridkit@develop) && ctest -VV

# Push with force to override existing binaries...
- name: Push to binaries to buildcache
run: |
spack -e . buildcache push --force --base-image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BASE_VERSION }} --unsigned --update-index local-buildcache
if: ${{ !cancelled() }}
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "Buildsystem/spack/spack"]
path = Buildsystem/spack/spack
url = https://github.com/nkoukpaizan/spack.git
branch = Gridkit-package-dev
1 change: 1 addition & 0 deletions Buildsystem/spack/spack
Submodule spack added at bb4ca5
2 changes: 1 addition & 1 deletion Examples/ScaleMicrogrid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ target_link_libraries(scalemicrogrid GRIDKIT::powerelec_disgen
GRIDKIT::solvers_dyn
GRIDKIT::powerelec_mircobusdq)

add_test(NAME ScaleMicrogrid COMMAND $<TARGET_FILE:scalemicrogrid>)
#add_test(NAME ScaleMicrogrid COMMAND $<TARGET_FILE:scalemicrogrid>)
install(TARGETS scalemicrogrid RUNTIME DESTINATION bin)