Skip to content

Commit

Permalink
Merge pull request #1 from adamatics/feat/development-branch
Browse files Browse the repository at this point in the history
feat: add kernel publisher action
  • Loading branch information
valerabaca authored Jul 5, 2024
2 parents 32f1c3c + ad2b37a commit 6e26d58
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"scm.experimental.showHistoryGraph": true
}
113 changes: 111 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,111 @@
# publish-kernel
Repository for a GitHub actions to publish a kernel in an AdaLab installation.
# Publish Kernel Action

![GitHub release (latest by date)](https://img.shields.io/github/v/release/adamatics/publish-kernel)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/adamatics/publish-kernel/CI)

## Overview

`Publish Kernel Action` is a GitHub Action to automate the process of publishing Docker images as new kernels in AdaLab. This action encapsulates the necessary steps for logging into a Docker registry, pushing a Docker image, and registering the image with AdaLab.

## Features

- Log in to AdaLab Docker registry
- Push Docker image to the registry
- Install Python dependencies
- Register the Docker image as a new kernel in AdaLab

## Usage

To use this action in your workflow, add the following step:

```yaml
- name: Publish Kernel in AdaLab
uses: adamatics/publish-kernel@v1
with:
kernel_name: my-kernel
kernel_description: This is a kernel used in my group.
harbor_registry_url: ${{ env.ADALAB_HARBOR_REGISTRY }}
harbor_password: ${{ secrets.ADALAB_HARBOR_PASSWORD }}
harbor_robot_user: ${{ env.ADALAB_HARBOR_USER }}
image_name: ${{ github.repository }}
image_tag: ${{ env.IMAGE_TAG }}
adalab_user_token: ${{ secrets.ADALAB_USER_TOKEN }}
adalab_username: ${{ env.ADALAB_USERNAME }}
adalab_api_url: ${{ env.ADALAB_API_URL }}
```
## Inputs
* `kernel_name` (required): Name of your kernel
* `kernel_description` (required): Brief description of your kernel
* `harbor_registry_url` (required): AdaLab Harbor registry URL.
* `harbor_password` (required): Password for the AdaLab Harbor registry.
* `harbor_robot_user` (required): AdaLab Harbor registry robot user.
* `image_name` (required): Name of the Docker image.
* `image_tag` (required): Tag of the Docker image.
* `adalab_user_token` (required): User token for AdaLab API.
* `adalab_username` (required): Username for AdaLab API.
* `adalab_api_url` (required): AdaLab API URL.

## Example Workflow

```yaml
name: Build and Publish Kernel
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
ADALAB_CLIENT_SECRET: ${{ secrets.ADALAB_CLIENT_SECRET }}
ADALAB_API_URL: "https://[ADALAB_HOST].com/adaboard/api"
ADALAB_HARBOR_REGISTRY: "harbor.[ADALAB_HOST].com"
ADALAB_HARBOR_USER: "robot$github"
ADALAB_USERNAME: "[USERNAME]"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Determine image tag
id: image_tag
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
echo "IMAGE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${GITHUB_SHA}" >> $GITHUB_ENV
fi
- name: Build Docker image
run: |
IMAGE_NAME=${{ github.repository }}
docker build -t $IMAGE_NAME:${{ env.IMAGE_TAG }} -f Containerfile .
- name: Add AdaLab certificate to trusted certificates
run: |
echo "${{ secrets.ADALAB_CERT }}" > adalab.crt
sudo cp adalab.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
- name: Publish Kernel in AdaLab
uses: adamatics/publish-kernel@v1
with:
name: my-kernel
kernel_description: This is a kernel used in my group.
harbor_registry_url: ${{ env.ADALAB_HARBOR_REGISTRY }}
harbor_password: ${{ secrets.ADALAB_HARBOR_PASSWORD }}
harbor_robot_user: ${{ env.ADALAB_HARBOR_USER }}
image_name: ${{ github.repository }}
image_tag: ${{ env.IMAGE_TAG }}
adalab_user_token: ${{ secrets.ADALAB_USER_TOKEN }}
adalab_username: ${{ env.ADALAB_USERNAME }}
adalab_api_url: ${{ env.ADALAB_API_URL }}
```
80 changes: 80 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: 'Publish Kernel in AdaLab'
description: 'An action to publish a Docker image as a new kernel in AdaLab'
inputs:
kernel_name:
description: 'Name of the kernel'
required: true
kernel_description:
description: 'Description of the kernel'
required: true
harbor_registry_url:
description: 'AdaLab Harbor registry URL'
required: true
harbor_password:
description: 'Password for the AdaLab Harbor registry'
required: true
harbor_robot_user:
description: 'AdaLab Harbor registry robot user'
required: true
image_name:
description: 'Name of the Docker image'
required: true
image_tag:
description: 'Tag of the Docker image'
required: true
adalab_user_token:
description: 'User token for AdaLab API'
required: true
adalab_username:
description: 'Username for AdaLab API'
required: true
adalab_api_url:
description: 'AdaLab API URL'
required: true

runs:
using: 'composite'
steps:
- name: Log in to AdaLab Docker registry
shell: bash
run: |
echo "${{ inputs.harbor_password }}" | docker login -u '${{ inputs.harbor_robot_user }}' --password-stdin "${{ inputs.harbor_registry_url }}"
- name: Push Docker image
shell: bash
run: |
docker tag ${{ inputs.image_name }}:${{ inputs.image_tag }} ${{ inputs.harbor_registry_url }}/kernels_temp/${{ inputs.image_name }}:${{ inputs.image_tag }}
docker push ${{ inputs.harbor_registry_url }}/kernels_temp/${{ inputs.image_name }}:${{ inputs.image_tag }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install --extra-index-url https://staging-adalab.adamatics.io/devpi/admin/adalib-dev adalib
- name: Register image as new kernel
shell: bash
run: |
python <<EOF
from adalib_auth import config
adalib_config = config.get_config(adaboard_api_url="${{ inputs.adalab_api_url }}", token="${{ inputs.adalab_user_token }}")
import adalib.harbor as harbor
harbor.create_image_metadata(
source_type="registry",
source_repository="${{ inputs.image_name }}",
source_tag="${{ inputs.image_tag }}",
project_name="kernels",
repository_name="${{ inputs.image_name }}",
tag="${{ inputs.image_tag }}",
type_id="kernel",
name="${{ inputs.kernel_name }}",
description="${{ inputs.kernel_description }}",
username="${{ inputs.adalab_username }}",
)
EOF

0 comments on commit 6e26d58

Please sign in to comment.