Giter VIP home page Giter VIP logo

github-ci's Introduction

Singularity Builder GitHub CI

img/sregistry-github-small.png

This is a simple example of how you can achieve:

  • version control of your recipes
  • build of associated container and
  • push to a storage endpoint

for a reproducible build workflow! By default, we will build on all pull requests and deploy on push to main. The containers will go to an enabled GitHub package registry thanks to the Singularity oras endpoint.

updated August 2021, we can now push containers to the GitHub package registry! Woohoo!

There are three workflows configured as examples to build and deploy Singularity containers:

  1. native install discovers Singularity* changed files, and builds Singularity 3.x (with GoLang) natively, deploys to GitHub packages.
  2. docker image discovers Singularity* changed files, and builds in a docker image, also deploys to GitHub packages.
  3. manual deploy takes a list of manually specified Singularity recipes (that aren't required to be changed), builds Singularity 3.x natively, and deploys to GitHub packages.

While the "build in a container" option is faster to complete and a more simple workflow, it should be noted that docker runs with --privileged which may lead to issues with the resulting container in a non privileged situation. Also note that you are free to mix and match the above recipes to your liking, or open an issue if you want to ask for help!

Why should this be managed via Github?

Github, by way of easy integration with native continuous integration, is an easy way to have a workflow set up where multiple people can collaborate on a container recipe, the recipe can be tested (with whatever testing you need), discussed in pull requests, and tested on merge to master. Further, now with GitHub packages we can push our containers directly to the GitHub package registry!

Why should I use this instead of a service?

You could use a remote builder, but if you do the build in a continuous integration service you get complete control over it. This means everything from the version of Singularity to use, to the tests that you run for your container. You have a lot more freedom in the rate of building, and organization of your repository, because it's you that writes the configuration.

Quick Start

1. Enable Packages

If you want to use the GitHub package registry you'll need to follow the instructions there to enable packages for your organization, specifically "public" and "internal" packages should be allowed to be created. You'll also want to add a username associated with your GitHub organization to the repository secret GHCR_USERNAME. If a package already exists for your repository, you may need to follow instructions to update a package from using personal access tokens to the safer GITHUB_TOKEN. This means that:

  1. If you want to be able to push to the package registry without extra work, don't push a container to the same package namespace that matches the repository before (e.g., from the command line).
  2. If you have already pushed a container to the repository package namespace, or you want to test and don't mind making the manual changes, you will need to follow these instructions to associate the package with your repository.

2. Add Your Recipes

Add your Singularity recipes to this repository, which should be named Singularity.<tag> or just Singularity to follow the previously published convention. You can then choose your file in .github/workflows. If you choose the manual-deploy.yml you can manually specify recipes in the matrix variable "recipe." If you choose either of the other two workflows, changed files that start with Singularity.* will be automatically detected and built.

3. Test your Container

Importantly, we suggest that you add some steps to test your container! Whether that's running it, exec'ing a custom command, or invoking the test command, there is more than one way to eat a reeses:

    - name: Test Container
      run: |
        singularity exec smokey.sif python run_tests.py
        singularity test smokey.sif
        singularity run toasty.sif

This step is not provided in the workflows, but it's recommended that you think about it and add if necessary.

4. Check Triggers

The workflow files each have a section at the top that indicates when the workflow will trigger. By default, we will do builds on pull requests, and deploys on pushes to a main branch. If you want to change this logic, edit the top of the recipe files.

5. Push to a registry

If you are good with GitHub packages, then you are good to go! Otherwise, if you want to push to other kinds of storage, you can install the Singularity Registry Client and push to your cloud storage of choice! You will want to add python and python-dev to the dependency install:

    - name: Install Dependencies
      run: |
        sudo apt-get update && sudo apt-get install -y \
          build-essential \
          libssl-dev \
          uuid-dev \
          libgpgme11-dev \
          squashfs-tools \
          libseccomp-dev \
          pkg-config \
          python-dev python python3-pip

And then install and use sregistry client. Here are many examples:

    - name: Deploy Container
      run: |
        sudo pip3 install sregistry
        SREGISTRY_CLIENT=google-storage sregistry push --name username/reponame smokey.sif
        SREGISTRY_CLIENT=s3 sregistry push --name username/reponame smokey.sif
        SREGISTRY_CLIENT=registry sregistry push --name username/reponame smokey.sif
        SREGISTRY_CLIENT=dropbox sregistry push --name username/reponame smokey.sif

See the clients page for all the options. If you want to change the recipe triggers, see here for getting started with GitHub actions, and please open an issue if you need any help.

6. Pull Your Container!

The example container here is published to singularithub/github-ci and can be pulled as follows:

$ singularity pull oras://ghcr.io/singularityhub/github-ci:latest
INFO:    Downloading oras image
$ ls
github-ci_latest.sif  img  README.md  Singularity

$ ./github-ci_latest.sif 
Hold me closer... tiny container :) :D

Other Options

You can customize this base recipe in so many ways! For example:

  • If you want to build a Docker container and pull down to Singularity, that's a good approach too! We have a container-builder-template to help you authenticate with several popular registries.
  • The action matrix can be extended to run builds on multiple platforms.
  • You can also do the same, but test multiple versions of Singularity.

Have fun!

github-ci's People

Contributors

adelavega avatar jennyfothergill avatar kiwiroy avatar truatpasteurdotfr avatar vsoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

github-ci's Issues

github token not working

Thank for this awesome example.

I've got this working on my project here: neuroscout/neuroscout-cli#136
I set it up to build based on Docker Hub builds using the same meta-data.

One thing I noticed is that for some reason, using {{ secrets.GITHUB_TOKEN }} did not work for me. Instead, I had to create a personal token from my account, and add it to the repository secrets.

If so, it may be worth updating the example.

Bootstrap from Singularity image on GHCR?

I was wondering if it is in any way possible to use a singularity image that was pushed to ghcr.io with this workflow as the source for bootstrapping in a new singularity definition?

test identicalness before deploying

If deploying an image to an existing tag, it would be nice if this workflow only deployed .sif files that are actually different from the currently hosted image. That way the timestamp of a tag doesn't change, for example, when a readme change is pushed to main. Any thoughts on how best to test identicalness?

public pulling

Another question:

Is public pulling without auth on the client possible?

When I try to pull the container associated with this repo I get this error:

FATAL:   While pulling image from oci registry: error fetching image to cache: failed to get checksum for oras://ghcr.io/singularityhub/github-ci:latest: while resolving reference: failed to authorize: failed to fetch oauth token: unexpected status: 403 Forbidden

If I login to to github using a PAK, it works.

Cannot push to Github Container Registry

Hi, I'm trying to build a Singularity and push it to Github Container Registry using one of the Github Actions workflow provided in this repo as a template.

I run a modified version of the "Docker" workflow, where I skip the step that checks whether the Singularity recipe has been changed in order to build the image at every push. Here is the content of the .yaml file for this workflow.

name: Singularity Build (docker)
on: 
  push:

    # Edit the branches here if you want to change deploy behavior
    branches:
      - main
      - master

  # Do the builds on all pull requests (to test them)
  # pull_request: []

jobs:
  build-test-containers:
    runs-on: ubuntu-latest
    strategy:
      # Keep going on other deployments if anything bloops
      fail-fast: false
      matrix:
        singularity_version:
        - '3.8.1'
        recipe: ["Singularity"]


    container:
      image: quay.io/singularity/singularity:v${{ matrix.singularity_version }}
      options: --privileged

    name: Check ${{ matrix.recipe }}
    steps:

      - name: Check out code for the container builds
        uses: actions/checkout@v2

      - name: Continue if Singularity Recipe Exists
        run: |
          if [[ -f "${{ matrix.recipe }}" ]]; then
            echo "keepgoing=true" >> $GITHUB_ENV
          fi        
      - name: Build Container
        if: ${{ env.keepgoing == 'true' }}
        env:
          recipe: ${{ matrix.recipe }}
        run: |
         ls 
         if [ -f "${{ matrix.recipe }}" ]; then
            sudo -E singularity build container.sif ${{ matrix.recipe }}
            tag=$(echo "${recipe/Singularity\./}")
            if [ "$tag" == "Singularity" ]; then
                tag=latest
            fi
            # Build the container and name by tag
            echo "Tag is $tag."
            echo "tag=$tag" >> $GITHUB_ENV
         else
           echo "${{ matrix.recipe }} is not found."
           echo "Present working directory: $PWD"
           ls
         fi
      - name: Login and Deploy Container
        if: (github.event_name != 'pull_request')
        env:
          keepgoing: ${{ env.keepgoing }}
        run: |         
            if [[ "${keepgoing}" == "true" ]]; then
                echo ${{ secrets.GITHUB_TOKEN }} | singularity remote login -u ${{ secrets.GHCR_USERNAME }} --password-stdin oras://ghcr.io
                singularity push container.sif oras://ghcr.io/${GITHUB_REPOSITORY}:${tag}
            fi

The container is built without error but it fails on the Login and Deploy Container step with a 404 error:

Password (or token when username is empty): 
INFO:    Token stored in /root/.singularity/remote.yaml
FATAL:   Unable to push image to oci registry: unable to push: unexpected status: 404 Not Found
Error: Process completed with exit code 255.

One of the failed runs

Am I doing something wrong?
Thanks,
Gianluca

Cannot run manual deploy workflow

Hi @vsoch ,
I've tried the manual deploy workflow for the attached recipe.
It fails with following error:

ERROR  : Failed to create user namespace: user namespace requires to set /proc/sys/kernel/unprivileged_userns_clone to 1
FATAL:   While performing build: while running engine: exit status 1
Error: Process completed with exit code 255.

I guess this has something to do with the quay.io/singularity/singularity:v3.8.3 image?

Best, C.

recipe.txt

Is it possible to view singularity images as oras://ghcr.io/ in github packages

Hi,
following your GREAT workflow I've managed to create a singularity image for my project and upload it to ghcr.io.
I still have some issues:

  • it seems that the package is advertised as a "docker image" in my project package page from github:

Install from the command line:
Learn more
$ docker pull ghcr.io/feelpp/salome.docker:latest

How can I tell github to display a more appropriate message like: singularity pull oras://....

  • Next as my project is private I need to pass some credentials to pull the singularity image. How can do that?

Thanks for your help

Typo in a link in README

I believe there are some links in the README aimed at a URL containing 'workfolws'.
I think it should be 'workflows' ?

Thanks for writeup/template!

using a pre-installed docker image with singularity installed?

Hi

Thanks for this nifty actions :P they are really a nice alternative to rebuild locally and provide a nice source of container images.

Would it be possible to use a prebuilt docker image with aingularity installed instead of rebuilding it every time?
Or is that limited by the docker image that one can use in the actions workflow?

I wanted to used the docker image at ghcr.io/truatpasteurdotfr/docker-c7-singularity-builder:latest instead of ubuntu-latest + installing from source singularity by just replacing:
runs-on: ubuntu-latest -> runs-on: ghcr.io/truatpasteurdotfr/docker-c7-singularity-builder
But of course that didn't ended well!

Does that make sense?

Tru

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.