hyakvnc-vncserver-ubuntu22.04:latest #65
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Singularity Build | |
on: | |
push: | |
tags: | |
- sif-* | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
name: Build Apptainer image | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Check out code for the container build | |
uses: actions/checkout@v4 | |
- name: Cache CURL downloads | |
uses: actions/cache@v3 | |
with: | |
path: .setup-downloads | |
key: ${{ runner.os }} | |
- name: Get container name | |
run: | | |
set -eux | |
[ -n "${BASH_VERSION:-}" ] && set -o pipefail | |
# Get container name from tag | |
IMAGE_NAME="$(echo "${GITHUB_REF_NAME:-}" | sed -E 's/^sif-//; s/@.*$//')" | |
echo "Container name is ${IMAGE_NAME:-}" | |
[ -f "${IMAGE_NAME:-}/Singularity" ] || { echo "No container named ${IMAGE_NAME:-} found."; exit 1; } | |
echo "IMAGE_NAME="${IMAGE_NAME}"" >> $GITHUB_ENV | |
# # Get tag of container from git tag (after #) | |
# Get the git tag | |
ref_name="${{ github.ref_name }}" | |
echo "ref_name is ${ref_name}." | |
# Get the image tag: the part after the @ in the git tag | |
IMAGE_TAG="$(echo "${ref_name:-}" | sed -E '/.*@.*/!d; s/(.*)@(.+$)/\2/;1q')" | |
IMAGE_TAG="${IMAGE_TAG:-}" | |
echo "IMAGE_TAG is ${IMAGE_TAG}." | |
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV | |
# Get the base image name and tag from the container | |
if grep -q 'From:.*hyakvnc-.*' "${IMAGE_NAME:-}"/Singularity; then | |
BASE_IMAGE_NAME="$(sed -E '/^\s*From:.*(hyakvnc-.*)/!d; s/.*(hyakvnc-[.A-Za-z0-9_-]+).*/\1/;1q' "${IMAGE_NAME}/Singularity")" | |
echo "Base image name is ${BASE_IMAGE_NAME}" | |
echo "BASE_IMAGE_NAME=\"${BASE_IMAGE_NAME}\"" >> $GITHUB_ENV | |
BASE_IMAGE_TAG="$(git tag --sort=-"creatordate:iso" --list '*'"${BASE_IMAGE_NAME:-}"'*' | sed -E '/.*@.*/!d; s/(.*)@(.+$)/\2/;1q')" | |
BASE_IMAGE_TAG="${BASE_IMAGE_TAG:-latest}" | |
echo "Base image tag is ${BASE_IMAGE_TAG}" && echo "BASE_IMAGE_TAG=\"${BASE_IMAGE_TAG}\"" >> $GITHUB_ENV | |
fi | |
# Get build-arg-file contents | |
git tag -l --format='%(contents)' "${ref_name}" | sed -E '/^.+=.*$/!d'>> ./defs/${IMAGE_NAME}/.build-arg-file | |
# Add bootstrap args for derived containers | |
echo "BOOTSTRAP_SOURCE=oras" >> .build-arg-file | |
echo "BOOTSTRAP_FROM_REPO=ghcr.io/${{ github.repository }}" >> ./defs/${IMAGE_NAME}/.build-arg-file | |
echo "BOOTSTRAP_FROM_SUFFIX=:${BASE_IMAGE_TAG:-latest}" >> ./defs/${IMAGE_NAME}/.build-arg-file | |
echo ".build-arg-file contents:" | |
cat ./defs/${IMAGE_NAME}/.build-arg-file 2>/dev/null || echo "No build-arg-file found." | |
- name: Delete GitHub AGENT_TOOLSDIRECTORY to free space | |
run: | | |
echo "Disk space before:" && df -h | |
sudo rm -rf /opt/hostedtoolcache; echo "Done removing /opt/hostedtoolcache" | |
- name: Delete .NET, Android, Haskell tools to free space | |
run: | | |
echo "Disk space before:" && df -h | |
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android && echo "Done removing .NET, Android, and Haskell tools." | |
- name: Install Apptainer | |
uses: maouw/github-action-apptainer-install@v1 | |
- name: Build Container | |
run: | | |
set -eux | |
[ -n "${BASH_VERSION:-}" ] && set -o pipefail | |
export APPCONTAINER_CACHE_DIR=".setup-downloads/apptainer-cache" | |
pushd "${IMAGE_NAME}" | |
echo "Building ${IMAGE_NAME}.sif" | |
touch .build-arg-file | |
apptainer build --warn-unused-build-args --fix-perms --force --build-arg-file .build-arg-file ../../sifs/"${IMAGE_NAME}.sif" Singularity || { echo "Failed to build ${IMAGE_NAME}.sif"; exit 1; } | |
echo "Built ${IMAGE_NAME}.sif" | |
popd | |
- name: Login and Deploy Container | |
run: | | |
set -eux | |
[ -n "${BASH_VERSION:-}" ] && set -o pipefail | |
[ -r "sifs/${IMAGE_NAME:-}.sif" ] || { echo "No container named sifs/${IMAGE_NAME:-}.sif found."; exit 1; } | |
echo "Container size:" | |
du -h "sifs/${IMAGE_NAME}.sif" | |
echo "Disk usage:" | |
df -h | |
echo "Pushing sifs/${IMAGE_NAME}.sif to ghcr.io/${{ github.repository }}/${IMAGE_NAME}:${IMAGE_TAG}" | |
apptainer remote login -u ${{ github.actor }} -p ${{ secrets.TOKEN }} oras://ghcr.io | |
apptainer push -U "sifs/${IMAGE_NAME}.sif" oras://ghcr.io/${{ github.repository }}/${IMAGE_NAME}:${IMAGE_TAG} || { echo "Failed to push sifs/${IMAGE_NAME}.sif to ghcr.io/${{ github.repository }}/${IMAGE_NAME}:${IMAGE_TAG}"; exit 1; } | |
echo "Pushed sifs/${IMAGE_NAME}.sif to ghcr.io/${{ github.repository }}/${IMAGE_NAME}:${IMAGE_TAG}" | |