Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gpelouze committed Feb 8, 2024
0 parents commit efbc01a
Show file tree
Hide file tree
Showing 17 changed files with 736 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build image

on:
workflow_call:
inputs:
dockerfile:
description: 'Docker file'
type: string
required: true
flavor_dir:
description: 'Flavor directory'
type: string
required: true
image_name:
description: 'Docker image name'
type: string
required: true
image_repo:
description: 'Docker image repo'
type: string
required: true
image_version:
description: 'Docker image version'
type: string
required: true
naavre_version:
description: 'NaaVRE base image version'
type: string
required: false

jobs:
build:
name: Build ${{ inputs.image_name }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- id: find-dockerfile
name: Find Dockerfile
run: |
# Choose the {inputs.flavor_dir}/{inputs.dockerfile} if it exists,
# otherwise fall-back to docker/{inputs.dockerfile}
dockerfile="${{ inputs.flavor_dir }}/${{ inputs.dockerfile }}"
[ -f "$dockerfile" ] || dockerfile="./docker/${{ inputs.dockerfile }}"
echo "dockerfile=$dockerfile" | tee -a $GITHUB_OUTPUT
- name: Build docker
uses: docker/build-push-action@v5
with:
context: .
file: ${{ steps.find-dockerfile.outputs.dockerfile }}
build-args: |
CONDA_ENV_FILE=${{ inputs.flavor_dir }}/environment.yaml
NAAVRE_VERSION=${{ inputs.naavre_version }}
tags: ${{ inputs.image_repo }}/${{ inputs.image_name }}:${{ inputs.image_version }},${{ inputs.image_repo }}/${{ inputs.image_name }}:latest
cache-from: type=gha
cache-to: type=gha,mode=min
outputs: type=docker,dest=/tmp/${{ inputs.image_name }}.tar

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.image_name }}
path: /tmp/${{ inputs.image_name }}.tar
retention-days: 1
65 changes: 65 additions & 0 deletions .github/workflows/make-flavor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Make flavor

on:
workflow_call:
inputs:
flavor_name:
description: 'NaaVRE flavor name'
type: string
required: true
image_repo:
description: 'Docker image repo'
type: string
required: true
image_version:
description: 'Docker image version'
type: string
required: true
naavre_version:
description: 'NaaVRE base image version'
type: string
required: true

jobs:
build-naavre-cell:
uses: ./.github/workflows/build-image.yaml
with:
dockerfile: naavre-cell.Dockerfile
flavor_dir: './flavors/${{ inputs.flavor_name }}'
image_name: naavre-cell-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
image_version: ${{ inputs.image_version }}

build-naavre-jupyter:
uses: ./.github/workflows/build-image.yaml
with:
dockerfile: naavre-jupyter.Dockerfile
flavor_dir: './flavors/${{ inputs.flavor_name }}'
image_name: naavre-jupyter-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
image_version: ${{ inputs.naavre_version }}-${{ inputs.image_version }}
naavre_version: ${{ inputs.naavre_version }}

test:
uses: ./.github/workflows/test-naavre-cell.yaml
needs: [build-naavre-cell]
with:
image_name: naavre-cell-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
tests_dir: './flavors/${{ inputs.flavor_name }}/tests/'

push-naavre-cell:
uses: ./.github/workflows/push-image.yaml
needs: [build-naavre-cell, test]
with:
image_name: naavre-cell-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
if: ${{ github.event_name == 'release' }}

push-naavre-jupyter:
uses: ./.github/workflows/push-image.yaml
needs: [build-naavre-jupyter, test]
with:
image_name: naavre-jupyter-${{ inputs.flavor_name }}
image_repo: ${{ inputs.image_repo }}
if: ${{ github.event_name == 'release' }}
39 changes: 39 additions & 0 deletions .github/workflows/make.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Make

on:
release:
types: [published]
push:
branches:
- '**'
tags-ignore:
- '**'
schedule:
- cron: '0 4 5,25 * *'

jobs:
list-flavors:
name: List flavors
runs-on: ubuntu-latest
outputs:
flavors: ${{ steps.list-flavors.outputs.flavors }}
steps:
- uses: actions/checkout@v4
- id: list-flavors
name: List flavors
run: |
flavors=$(find ./flavors -mindepth 1 -maxdepth 1 -type d | jq -Rsc 'split("\n")[:-1] | map(split("/")[-1])')
echo "flavors=$flavors" | tee -a $GITHUB_OUTPUT
flavors:
name: Flavor ${{ matrix.flavor_name }}
uses: ./.github/workflows/make-flavor.yaml
needs: [list-flavors]
with:
flavor_name: ${{ matrix.flavor_name }}
image_repo: 'ghcr.io/qcdis/n-a-a-vre'
image_version: ${{ github.ref_type == 'tag' && github.ref_name || github.sha }}
naavre_version: 'v2.3.3-beta'
strategy:
matrix:
flavor_name: ${{ fromJson(needs.list-flavors.outputs.flavors) }}
44 changes: 44 additions & 0 deletions .github/workflows/push-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Push image

on:
workflow_call:
inputs:
image_name:
description: 'Docker image name'
type: string
required: true
image_repo:
description: 'Docker image repo'
type: string
required: true

jobs:
push:
name: Push ${{ inputs.image_name }}
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.image_name }}
path: /tmp

- name: Load image
run: |
docker load --input /tmp/${{ inputs.image_name }}.tar
docker image ls -a
- name: Login to container registry
uses: docker/login-action@v3
env:
REGISTRY_NAME: ${{ vars.REGISTRY_NAME || 'ghcr.io' }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME || github.actor }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }}
with:
registry: ${{ env.REGISTRY_NAME }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}

- name: Push image
run: |
docker push ${{ inputs.image_repo }}/${{ inputs.image_name }} --all-tags
40 changes: 40 additions & 0 deletions .github/workflows/test-naavre-cell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test cell base image

on:
workflow_call:
inputs:
image_name:
description: 'Docker image name'
type: string
required: true
image_repo:
description: 'Docker image repo'
type: string
required: true
tests_dir:
description: 'Directory containing test files'
type: string
required: true

jobs:
test:
name: Test ${{ inputs.image_name }}
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.image_name }}
path: /tmp

- name: Load image
run: |
docker load --input /tmp/${{ inputs.image_name }}.tar
docker image ls -a
- name: Checkout
uses: actions/checkout@v4

- name: Run tests
run: |
docker run -v ${{ inputs.tests_dir }}:/tests/ ${{ inputs.image_repo }}/${{ inputs.image_name }} /bin/sh /tests/tests.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/

.env
Loading

0 comments on commit efbc01a

Please sign in to comment.