Skip to content

Commit

Permalink
Use Github Actions to automatically build and deploy container (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
arisp99 authored Oct 15, 2021
1 parent 69d1041 commit e1267f8
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Singularity Build
on:
# Manually run workflow
workflow_dispatch:
inputs:
tag:
description: "Tag for the built container"
required: true
default: "dev"

# Trigger on push
push:
branches: [main, master]

# Trigger on PR
pull_request: []

# Trigger on published release
release:
types: [published]

jobs:
build-test-containers:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
recipe: ["MIPTools.def"]

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

- name: Check Out Code for the Container Build
uses: actions/checkout@v2

- name: Continue if Singularity Recipe Exists
run: |
if [[ -f "${{ matrix.recipe }}" ]]; then
echo "keepgoing=true" >> $GITHUB_ENV
fi
- name: Set up Go 1.13
if: ${{ env.keepgoing == 'true' }}
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Install Dependencies
if: ${{ env.keepgoing == 'true' }}
run: |
sudo apt-get update && sudo apt-get install -y \
build-essential \
libssl-dev \
uuid-dev \
libgpgme11-dev \
squashfs-tools \
libseccomp-dev \
pkg-config
- name: Install Singularity
if: ${{ env.keepgoing == 'true' }}
env:
SINGULARITY_VERSION: 3.8.3
GOPATH: /tmp/go

run: |
mkdir -p $GOPATH
sudo mkdir -p /usr/local/var/singularity/mnt && \
mkdir -p $GOPATH/src/github.com/sylabs && \
cd $GOPATH/src/github.com/sylabs && \
wget -qO- https://github.com/sylabs/singularity/releases/download/v${SINGULARITY_VERSION}/singularity-ce-${SINGULARITY_VERSION}.tar.gz | \
tar xzv && \
cd singularity-ce-${SINGULARITY_VERSION} && \
./mconfig -p /usr/local && \
make -C builddir && \
sudo make -C builddir install
- 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 }}
else
echo "${{ matrix.recipe }} is not found."
echo "Present working directory: $PWD"
ls
fi
- name: Generate Tag
run: |
# If triggered manually, use tag provided by user (or default)
# If triggered by release, tag with release tag
# if triggered otherwise, tag as dev
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
tag=${{ github.event.inputs.tag }}
elif [[ "${{ github.event_name }}" == "release" ]]; then
tag=${{ github.ref }}
tag=${tag##*/}
else
tag=dev
fi
# Name the tag
echo "Tag is $tag."
echo "tag=$tag" >> $GITHUB_ENV
- 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}:${{ env.tag }}
fi

0 comments on commit e1267f8

Please sign in to comment.