Skip to content

Build and publish torchserve image #18

Build and publish torchserve image

Build and publish torchserve image #18

name: Build and publish torchserve image
on:
workflow_dispatch:
inputs:
version:
description: 'Version of the image to build and publish'
required: true
default: 'v1.0.0'
tags:
description: 'Test scenario tags'
env:
REGISTRY: ghcr.io
NAME: serve
VERSION: ${{ github.event.inputs.version }} #v1.0.0
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions: # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/moverseai/moai/${{ env.NAME }}
tags: | # https://github.com/docker/metadata-action#tags-input
type=raw,enable=true,priority=200,prefix=,suffix=,value=${{ env.VERSION }}-pt112-cu113
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: docker/serve/pt112-cu113/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
labels: | # strip down labels: https://stackoverflow.com/questions/76472989/how-to-access-a-subset-of-keys-among-the-labels-in-the-json-object-returned-by-d
org.opencontainers.image.created=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
org.opencontainers.image.revision=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
com.github.moverseai.moai.sha=${{ github.sha }}
com.github.moverseai.moai.branch=${{ github.ref_name }}