Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buildcache #14

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3


- uses: docker/setup-buildx-action@v1

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
Expand All @@ -77,7 +80,7 @@ jobs:
tags: |
type=raw, ${{ github.event.inputs.tag_name }}
type=raw, ${{ github.event.inputs.tag_name }}-{{date 'YYYYMMDD'}}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
Expand All @@ -91,3 +94,5 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
secrets: |
"signingkey=${{ secrets.BUILDCACHE_PRIVATE_KEY }}"
71 changes: 47 additions & 24 deletions spack/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
ARG BASEIMAGE=ecpe4s/rhel8-runner-x86_64
# syntax=docker/dockerfile:1.3
ARG BASEIMAGE=ubuntu:22.04

FROM $BASEIMAGE
FROM $BASEIMAGE AS base

ARG SPACK_VERSION=0.19.0
ARG RECIPES_BRANCH=main

ARG UID=1000
ARG GID=100

RUN ( ( getent group $GID ) || groupadd --gid $GID user ) \
&&( ( getent passwd $UID ) || useradd --gid $GID --uid $UID user )

RUN mkdir -p /spack /recipes /home/user && useradd spack && chown -R user: /spack /recipes /home/user

ADD install_spack_deps.sh /tmp/

RUN bash /tmp/install_spack_deps.sh

USER user
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked bash /tmp/install_spack_deps.sh

SHELL ["/bin/bash", "-c"]

# Download last release of spack
RUN curl -L https://github.com/spack/spack/releases/download/v${SPACK_VERSION}/spack-${SPACK_VERSION}.tar.gz | tar xz -C /spack --strip-components=1 && \
RUN mkdir -p /spack && \
curl -L https://github.com/spack/spack/releases/download/v${SPACK_VERSION}/spack-${SPACK_VERSION}.tar.gz | tar xz -C /spack --strip-components=1 && \
source /spack/share/spack/setup-env.sh && \
spack config --scope site add 'packages:all:target:[x86_64]' && \
spack compiler find

# Get arcane recipes
RUN curl -L https://github.com/arcaneframework/spack_recipes/archive/refs/heads/${RECIPES_BRANCH}.tar.gz | tar xz -C /recipes --strip-components 1

# setup our recipes
RUN source /spack/share/spack/setup-env.sh && \
RUN mkdir -p recipes && \
curl -L https://github.com/arcaneframework/spack_recipes/archive/refs/heads/${RECIPES_BRANCH}.tar.gz | tar xz -C /recipes --strip-components 1 && \
source /spack/share/spack/setup-env.sh && \
spack repo add --scope site /recipes

ADD import_signing_key.sh /tmp

RUN --mount=type=secret,id=signingkey /tmp/import_signing_key.sh /run/secrets/signingkey

FROM base AS builder

RUN --mount=type=cache,target=/buildcache source /spack/share/spack/setup-env.sh && \
spack mirror add cache /buildcache && \
spack buildcache update-index -d /buildcache && \
spack buildcache list --allarch

# Populate cache with build tools
# Uninstall to avoid bad reuse
RUN --mount=type=cache,target=/buildcache source /spack/share/spack/setup-env.sh && \
spack env create tools --without-view && \
spack env activate tools && \
spack add cmake meson m4 pkgconf autoconf automake libtool && \
spack concretize -f && (spack install --fail-fast ; \
spack buildcache create -a -m cache) && \
spack uninstall -y --all

# Define and compile an alien environment
RUN source /spack/share/spack/setup-env.sh && \
RUN --mount=type=cache,target=/buildcache source /spack/share/spack/setup-env.sh && \
spack buildcache update-index -d /buildcache && \
spack env create alien --without-view && \
spack env activate alien && \
spack add alien +hypre+petsc+xml+hdf5+move+ref ginkgo=omp trilinos=omp && \
spack concretize -f && spack install --fail-fast
spack add alien +hypre+petsc+xml+hdf5+move+ref ginkgo=omp trilinos=omp ^trilinos~explicit_template_instantiation && \
spack concretize -f && (spack install --fail-fast; \
spack buildcache create -a -m cache)

# # Define and compile an arcane environment
# RUN source /spack/share/spack/setup-env.sh && \
Expand All @@ -56,7 +71,15 @@ RUN source /spack/share/spack/setup-env.sh && \
# spack add arcane ~wrapper~monoembed && \
# spack concretize -f && spack install --fail-fast

RUN source /spack/share/spack/setup-env.sh && \
spack clean -a
# RUN source /spack/share/spack/setup-env.sh && \
# spack clean -a

# Strip all the binaries
RUN find -L /spack/opt/* -type f -exec readlink -f '{}' \; | \
xargs file -i | \
grep 'charset=binary' | \
grep 'x-executable\|x-archive\|x-sharedlib' | \
awk -F: '{print $1}' | xargs strip -s

RUN rm -rf /tmp/* || true
FROM base AS final
COPY --from=builder /spack/opt/ /spack/
13 changes: 13 additions & 0 deletions spack/import_signing_key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /usr/bin/bash

SPACKHOME=/spack
export GNUPGHOME=${SPACKHOME}/opt/spack/gpg

. ${SPACKHOME}/share/spack/setup-env.sh
spack gpg init
spack gpg list 2> /dev/null

gpg --import "$1"
for fpr in $(gpg --no-tty --list-keys --with-colons | awk -F: '/fpr:/ {print $10}' | sort -u); do
echo -e "5\ny\n" | gpg --no-tty --command-fd 0 --expert --edit-key $fpr trust;
done
12 changes: 7 additions & 5 deletions spack/install_spack_deps.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#! /usr/bin/bash

# debian like
install_apt() {
export DEBIAN_FRONTEND=noninteractive
apt update
apt install -y build-essential ca-certificates coreutils curl environment-modules gfortran git gpg lsb-release python3 python3-distutils python3-venv unzip zip curl
apt clean
rm -rf /var/lib/apt/lists/*
export DEBIAN_FRONTEND=noninteractive
apt update
apt install -y build-essential ca-certificates coreutils curl environment-modules gfortran git gpg lsb-release python3 python3-distutils python3-venv unzip zip curl file
# apt clean
# rm -rf /var/lib/apt/lists/*
}

# RedHat like
install_dnf()
{
dnf -y update
Expand Down