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

9 env based single model dockerfile #46

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 3 additions & 4 deletions .github/workflows/build-and-push-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ jobs:
version: "2021.1.2",
},
]
uses: access-nri/build-ci/.github/workflows/build-and-push-image.yml@main

uses: access-nri/build-ci/.github/workflows/build-and-push-spack-release@main
with:
container-registry: ghcr.io
container-name: access-nri/build-${{ matrix.package }}-${{ matrix.compiler.name }}${{ matrix.compiler.version }}-${{ github.event.inputs.spack-packages-version }}
dockerfile-directory: containers
dockerfile-name: Dockerfile.build
package-name: ${{ matrix.package }}
build-args: |
# TODO: Probably shouldn't hard code base image path
"BASE_IMAGE=ghcr.io/access-nri/base-spack-${{ github.event.inputs.spack-packages-version }}:latest"
"PACKAGE=${{ matrix.package }}"
"COMPILER_NAME=${{ matrix.compiler.name}}"
"COMPILER_PACKAGE=${{ matrix.compiler.package}}"
"COMPILER_VERSION=${{ matrix.compiler.version}}"
permissions:
contents: read
packages: write
87 changes: 87 additions & 0 deletions .github/workflows/build-and-push-spack-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build and Push Image as Spack Release
on:
workflow_call:
inputs:
container-registry:
required: true
type: string
container-name:
required: true
type: string
dockerfile-directory:
required: true
type: string
dockerfile-name:
required: true
type: string
build-args:
required: false
type: string
default: ""
package-name:
required: true
type: string
secrets:
build-secrets:
required: false
jobs:
build-and-push-image-as-release:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

# Buildx is currently required to use a subdirectory w/ build-push-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to container registry
uses: docker/login-action@v2
with:
registry: ${{ inputs.container-registry }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ inputs.container-registry }}/${{ inputs.container-name }}
flavor: |
latest=true

- name: Build Docker image
id: build-push-image
uses: docker/build-push-action@v3
with:
context: "{{defaultContext}}:${{ inputs.dockerfile-directory }}"
build-args: ${{ inputs.build-args }}
secrets: ${{ secrets.build-secrets }}
file: ${{ inputs.dockerfile-name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
load: true

- name: Get Spack Environment Info From Docker Image
id: spackenv
run: docker run --rm ${{ steps.build-push-image.outputs.imageid }} -v environment:/opt/spack/var/spack/environments/${{ inputs.package-name }}

- name: Push Docker Image As Package
uses: docker/build-push-action@v3
with:
context: "{{defaultContext}}:${{ inputs.dockerfile-directory }}"
build-args: ${{ inputs.build-args }}
secrets: ${{ secrets.build-secrets }}
file: ${{ inputs.dockerfile-name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true

- name: Push Spack Env as Release
uses: ncipollo/release-action@v1.12.0
with:
artifacts: "environment/spack.*"
20 changes: 11 additions & 9 deletions containers/Dockerfile.base-spack
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ FROM rockylinux:8.7
SHELL ["/bin/bash", "-c"]

ENV SPACK_ROOT=/opt/spack
ENV SPACK_PACKAGES_ROOT=/opt/spack_packages
ENV SPACK_PACKAGES_REPO_ROOT=/opt/spack_packages
ENV GNUPGHOME=$SPACK_ROOT/opt/spack/gpg

ARG SPACK_PACKAGES_VERSION
ARG SPACK_PACKAGES_REPO_VERSION

RUN dnf -y group install "Development Tools"

RUN dnf -y install \
# csh currently required for some build scripts e.g. MOM5
RUN dnf -y group install "Development Tools" \
&& dnf -y install \
csh \
gcc-gfortran \
git \
jq \
python3 \
python3-pip \
# csh currently required for some build scripts e.g. MOM5
csh
&& dnf clean all \
&& rm -rf /var/cache/yum

# Install spack
RUN git clone -c feature.manyFiles=true https://github.com/spack/spack.git $SPACK_ROOT --branch v0.20.1 --single-branch --depth=1
Expand All @@ -40,13 +42,13 @@ SHELL ["docker-shell"]
RUN spack bootstrap now

# Set up ACCESS Spack package repo
RUN git clone -b ${SPACK_PACKAGES_VERSION} https://github.com/ACCESS-NRI/spack_packages.git ${SPACK_PACKAGES_ROOT}
RUN git clone --depth=1 -b ${SPACK_PACKAGES_REPO_VERSION} https://github.com/ACCESS-NRI/spack_packages.git ${SPACK_PACKAGES_REPO_ROOT}
COPY repos.yaml $SPACK_ROOT/etc/spack/repos.yaml

# TODO
# Think about setting up spack S3 build cache for CI here
# Set up ACCESS Spack buildcache
RUN pip3 install boto3
RUN pip3 install --no-cache-dir boto3
RUN spack gpg init

# Add buildcache mirror
Expand Down
20 changes: 8 additions & 12 deletions containers/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ ARG COMPILER_VERSION
# Use Spack shell environment for subsequent RUN steps
SHELL ["docker-shell"]

# Install required compiler
RUN spack -d install ${COMPILER_PACKAGE}@${COMPILER_VERSION}

# Load required compiler and generate site-wide compilers.yaml
RUN spack load ${COMPILER_PACKAGE}@${COMPILER_VERSION} && \
spack compiler find --scope site

# Build and install package dependencies
RUN spack -d install --only dependencies ${PACKAGE}%${COMPILER_NAME}@${COMPILER_VERSION}
# create environment for package, install and load compiler, install only package dependencies
RUN spack env create ${PACKAGE} \
&& spack env activate ${PACKAGE} \
&& spack -d install --fail-fast --add ${COMPILER_PACKAGE}@${COMPILER_VERSION} \
&& spack load ${COMPILER_PACKAGE}@${COMPILER_VERSION} \
&& spack compiler find --scope env:${PACKAGE} \
&& spack -d install --fail-fast --add --only dependencies ${PACKAGE}%${COMPILER_NAME}@${COMPILER_VERSION} \
&& spack gc -y

# Push any uncached binaries to buildcache
# `spack find --json | jq .[].name`
# This returns all currently installed spec names
RUN dnf -y install jq
RUN spack -d buildcache create -a -m s3_buildcache `spack find --json | jq --raw-output .[].name`