Build container images on Github Actions and push to multiple registries (#26247)

Modifications:
- Modify the workflow to build container images without pushing when the workflow file itself is modified
- Strip the leading ghcr.io/spack/ from env.container env.versioned to prepare pushing to multiple registries
- Fixed CentOS 7 and Amazon Linux builds
- Login and push to Docker Hub as well as Github Action
- Add a badge to README.md with the status of docker images
This commit is contained in:
Massimiliano Culpo 2021-09-30 23:34:47 +02:00 committed by GitHub
parent 7bda430de0
commit 8ade8a77dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 39 deletions

View file

@ -1,8 +1,16 @@
name: Build & Deploy Docker Containers name: Containers
on: on:
# This Workflow can be triggered manually
workflow_dispatch:
# Build new Spack develop containers nightly. # Build new Spack develop containers nightly.
schedule: schedule:
- cron: '34 0 * * *' - cron: '34 0 * * *'
# Run on pull requests that modify this file
pull_request:
branches:
- develop
paths:
- '.github/workflows/build-containers.yml'
# Let's also build & tag Spack containers on releases. # Let's also build & tag Spack containers on releases.
release: release:
types: [published] types: [published]
@ -29,7 +37,7 @@ jobs:
- name: Set Container Tag Normal (Nightly) - name: Set Container Tag Normal (Nightly)
run: | run: |
container="ghcr.io/spack/${{ matrix.dockerfile[0]}}:latest" container="${{ matrix.dockerfile[0] }}:latest"
echo "container=${container}" >> $GITHUB_ENV echo "container=${container}" >> $GITHUB_ENV
echo "versioned=${container}" >> $GITHUB_ENV echo "versioned=${container}" >> $GITHUB_ENV
@ -37,7 +45,7 @@ jobs:
- name: Set Container Tag on Release - name: Set Container Tag on Release
if: github.event_name == 'release' if: github.event_name == 'release'
run: | run: |
versioned="ghcr.io/spack/${{matrix.dockerfile[0]}}:${GITHUB_REF##*/}" versioned="${{matrix.dockerfile[0]}}:${GITHUB_REF##*/}"
echo "versioned=${versioned}" >> $GITHUB_ENV echo "versioned=${versioned}" >> $GITHUB_ENV
- name: Check ${{ matrix.dockerfile[1] }} Exists - name: Check ${{ matrix.dockerfile[1] }} Exists
@ -48,6 +56,12 @@ jobs:
exit 1; exit 1;
fi fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to GitHub Container Registry - name: Log in to GitHub Container Registry
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with:
@ -55,18 +69,20 @@ jobs:
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU - name: Log in to DockerHub
uses: docker/setup-qemu-action@v1 uses: docker/login-action@v1
with:
- name: Set up Docker Buildx username: ${{ secrets.DOCKERHUB_USERNAME }}
uses: docker/setup-buildx-action@v1 password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Deploy ${{ matrix.dockerfile[1] }} - name: Build & Deploy ${{ matrix.dockerfile[1] }}
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
file: share/spack/docker/${{matrix.dockerfile[1]}} file: share/spack/docker/${{matrix.dockerfile[1]}}
platforms: ${{ matrix.dockerfile[2] }} platforms: ${{ matrix.dockerfile[2] }}
push: true push: ${{ github.event_name != 'pull_request' }}
tags: | tags: |
${{ env.container }} spack/${{ env.container }}
${{ env.versioned }} spack/${{ env.versioned }}
ghcr.io/spack/${{ env.container }}
ghcr.io/spack/${{ env.versioned }}

View file

@ -4,6 +4,7 @@
[![Bootstrapping](https://github.com/spack/spack/actions/workflows/bootstrap.yml/badge.svg)](https://github.com/spack/spack/actions/workflows/bootstrap.yml) [![Bootstrapping](https://github.com/spack/spack/actions/workflows/bootstrap.yml/badge.svg)](https://github.com/spack/spack/actions/workflows/bootstrap.yml)
[![macOS Builds (nightly)](https://github.com/spack/spack/workflows/macOS%20builds%20nightly/badge.svg?branch=develop)](https://github.com/spack/spack/actions?query=workflow%3A%22macOS+builds+nightly%22) [![macOS Builds (nightly)](https://github.com/spack/spack/workflows/macOS%20builds%20nightly/badge.svg?branch=develop)](https://github.com/spack/spack/actions?query=workflow%3A%22macOS+builds+nightly%22)
[![codecov](https://codecov.io/gh/spack/spack/branch/develop/graph/badge.svg)](https://codecov.io/gh/spack/spack) [![codecov](https://codecov.io/gh/spack/spack/branch/develop/graph/badge.svg)](https://codecov.io/gh/spack/spack)
[![Containers](https://github.com/spack/spack/actions/workflows/build-containers.yml/badge.svg)](https://github.com/spack/spack/actions/workflows/build-containers.yml)
[![Read the Docs](https://readthedocs.org/projects/spack/badge/?version=latest)](https://spack.readthedocs.io) [![Read the Docs](https://readthedocs.org/projects/spack/badge/?version=latest)](https://spack.readthedocs.io)
[![Slack](https://slack.spack.io/badge.svg)](https://slack.spack.io) [![Slack](https://slack.spack.io/badge.svg)](https://slack.spack.io)

View file

@ -21,16 +21,15 @@ RUN yum update -y \
gnupg2 \ gnupg2 \
hostname \ hostname \
iproute \ iproute \
Lmod \
make \ make \
patch \ patch \
python \ python3 \
python-pip \ python3-pip \
python-setuptools \ python3-setuptools \
tcl \ tcl \
unzip \ unzip \
which \ which \
&& pip install boto3 \ && pip3 install boto3 \
&& rm -rf /var/cache/yum \ && rm -rf /var/cache/yum \
&& yum clean all && yum clean all
@ -64,6 +63,7 @@ WORKDIR /root
SHELL ["docker-shell"] SHELL ["docker-shell"]
# TODO: add a command to Spack that (re)creates the package cache # TODO: add a command to Spack that (re)creates the package cache
RUN spack bootstrap untrust spack-install
RUN spack spec hdf5+mpi RUN spack spec hdf5+mpi
ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"] ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"]

View file

@ -23,16 +23,16 @@ RUN yum update -y \
gnupg2 \ gnupg2 \
hostname \ hostname \
iproute \ iproute \
Lmod \
make \ make \
patch \ patch \
python \ patchelf \
python-pip \ python3 \
python-setuptools \ python3-pip \
python3-setuptools \
tcl \ tcl \
unzip \ unzip \
which \ which \
&& pip install boto3 \ && pip3 install boto3 \
&& rm -rf /var/cache/yum \ && rm -rf /var/cache/yum \
&& yum clean all && yum clean all
@ -66,6 +66,7 @@ WORKDIR /root
SHELL ["docker-shell"] SHELL ["docker-shell"]
# TODO: add a command to Spack that (re)creates the package cache # TODO: add a command to Spack that (re)creates the package cache
RUN spack bootstrap untrust spack-install
RUN spack spec hdf5+mpi RUN spack spec hdf5+mpi
ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"] ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"]

View file

@ -1,20 +1,20 @@
FROM opensuse/leap:15.2 FROM opensuse/leap:15.3
MAINTAINER Christian Goll <cgoll@suse.com> MAINTAINER Christian Goll <cgoll@suse.com>
ENV DOCKERFILE_BASE=opensuse \ ENV DOCKERFILE_BASE=opensuse \
DOCKERFILE_DISTRO=opensuse_leap \ DOCKERFILE_DISTRO=opensuse_leap \
DOCKERFILE_DISTRO_VERSION=15.2 \ DOCKERFILE_DISTRO_VERSION=15.3 \
SPACK_ROOT=/opt/spack \ SPACK_ROOT=/opt/spack \
DEBIAN_FRONTEND=noninteractive \ DEBIAN_FRONTEND=noninteractive \
CURRENTLY_BUILDING_DOCKER_IMAGE=1 \ CURRENTLY_BUILDING_DOCKER_IMAGE=1 \
container=docker container=docker
RUN zypper ref && \ RUN zypper ref && \
zypper up -y && \ zypper up -y && \
zypper in -y python3-base python3-boto3\ zypper in -y python3-base python3-boto3 \
xz gzip tar bzip2 curl patch \ xz gzip tar bzip2 curl patch patchelf file \
gcc-c++ gcc-fortran make cmake automake &&\ gcc-c++ gcc-fortran make cmake automake && \
zypper clean zypper clean
# clean up manpages # clean up manpages
RUN rm -rf /var/cache/zypp/* \ RUN rm -rf /var/cache/zypp/* \
@ -51,8 +51,8 @@ RUN [ -f ~/.profile ] \
WORKDIR /root WORKDIR /root
SHELL ["docker-shell"] SHELL ["docker-shell"]
# Find tools which are in distro # Disable bootstrapping from sources
RUN ${SPACK_ROOT}/bin/spack external find --scope system RUN ${SPACK_ROOT}/bin/spack bootstrap untrust spack-install
# TODO: add a command to Spack that (re)creates the package cache # TODO: add a command to Spack that (re)creates the package cache
RUN ${SPACK_ROOT}/bin/spack spec hdf5+mpi RUN ${SPACK_ROOT}/bin/spack spec hdf5+mpi

View file

@ -21,9 +21,7 @@ RUN apt-get -yqq update \
git \ git \
gnupg2 \ gnupg2 \
iproute2 \ iproute2 \
lmod \
locales \ locales \
lua-posix \
make \ make \
python3 \ python3 \
python3-pip \ python3-pip \
@ -69,6 +67,7 @@ WORKDIR /root
SHELL ["docker-shell"] SHELL ["docker-shell"]
# TODO: add a command to Spack that (re)creates the package cache # TODO: add a command to Spack that (re)creates the package cache
RUN spack bootstrap untrust spack-install
RUN spack spec hdf5+mpi RUN spack spec hdf5+mpi
ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"] ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"]

View file

@ -21,9 +21,7 @@ RUN apt-get -yqq update \
git \ git \
gnupg2 \ gnupg2 \
iproute2 \ iproute2 \
lmod \
locales \ locales \
lua-posix \
make \ make \
python3 \ python3 \
python3-pip \ python3-pip \
@ -65,14 +63,11 @@ RUN [ -f ~/.profile ] \
&& sed -i 's/mesg n/( tty -s \&\& mesg n || true )/g' ~/.profile \ && sed -i 's/mesg n/( tty -s \&\& mesg n || true )/g' ~/.profile \
|| true || true
# [WORKAROUND]
# https://bugs.launchpad.net/ubuntu/+source/lua-posix/+bug/1752082
RUN ln -s posix_c.so /usr/lib/$(uname -m)-linux-gnu/lua/5.2/posix.so
WORKDIR /root WORKDIR /root
SHELL ["docker-shell"] SHELL ["docker-shell"]
# TODO: add a command to Spack that (re)creates the package cache # TODO: add a command to Spack that (re)creates the package cache
RUN spack bootstrap untrust spack-install
RUN spack spec hdf5+mpi RUN spack spec hdf5+mpi
ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"] ENTRYPOINT ["/bin/bash", "/opt/spack/share/spack/docker/entrypoint.bash"]