Skip to content

Publish self-hosted image #4

Publish self-hosted image

Publish self-hosted image #4

Workflow file for this run

name: Publish self-hosted image
on:
workflow_dispatch:
inputs:
image_tag:
description: Image tag to publish, for example v0.1.0-beta.1 or v0.1.0
required: true
type: string
api_ref:
description: knowhere git ref to include in the image
required: true
default: staging
type: string
dashboard_ref:
description: knowhere-dashboard git ref to include in the image
required: true
default: staging
type: string
publish_latest:
description: Also publish the latest tag
required: true
default: false
type: boolean
create_github_release:
description: Create a matching GitHub tag and release
required: true
default: true
type: boolean
permissions:
contents: write
packages: write
env:
GHCR_IMAGE: ghcr.io/ontos-ai/knowhere
ALIYUN_ACR_REGISTRY: knowhere-registry.cn-shenzhen.cr.aliyuncs.com
ALIYUN_ACR_IMAGE: knowhere-registry.cn-shenzhen.cr.aliyuncs.com/knowhere/knowhere
concurrency:
group: publish-self-hosted-image-${{ github.ref }}
cancel-in-progress: false
jobs:
publish:
name: Build and publish combined image
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- name: Checkout self-hosted release repo
uses: actions/checkout@v4
- name: Checkout API source
uses: actions/checkout@v4
with:
repository: Ontos-AI/knowhere
ref: ${{ inputs.api_ref }}
token: ${{ secrets.KNOWHERE_RELEASE_SOURCE_TOKEN }}
path: .build/checkouts/knowhere
- name: Checkout dashboard source
uses: actions/checkout@v4
with:
repository: Ontos-AI/knowhere-dashboard
ref: ${{ inputs.dashboard_ref }}
token: ${{ secrets.KNOWHERE_RELEASE_SOURCE_TOKEN }}
path: .build/checkouts/knowhere-dashboard
- name: Resolve source revisions
id: revisions
shell: bash
run: |
set -euo pipefail
api_commit="$(git -C .build/checkouts/knowhere rev-parse HEAD)"
dashboard_commit="$(git -C .build/checkouts/knowhere-dashboard rev-parse HEAD)"
build_time="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
{
echo "api_commit=${api_commit}"
echo "dashboard_commit=${dashboard_commit}"
echo "build_time=${build_time}"
} >> "${GITHUB_OUTPUT}"
- name: Prepare build context sources
shell: bash
run: |
set -euo pipefail
KNOWHERE_API_SOURCE="${PWD}/.build/checkouts/knowhere" \
KNOWHERE_API_REF="HEAD" \
KNOWHERE_DASHBOARD_SOURCE="${PWD}/.build/checkouts/knowhere-dashboard" \
KNOWHERE_DASHBOARD_REF="HEAD" \
./scripts/prepare-sources.sh
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Aliyun ACR
uses: docker/login-action@v3
with:
registry: ${{ env.ALIYUN_ACR_REGISTRY }}
username: ${{ secrets.ALIYUN_ACR_USERNAME }}
password: ${{ secrets.ALIYUN_ACR_PASSWORD }}
- name: Generate image metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_IMAGE }}
${{ env.ALIYUN_ACR_IMAGE }}
tags: |
type=raw,value=${{ inputs.image_tag }}
type=raw,value=latest,enable=${{ inputs.publish_latest }}
labels: |
org.opencontainers.image.title=Knowhere Self-Hosted
org.opencontainers.image.description=Combined Knowhere API, worker, and dashboard image
org.opencontainers.image.source=https://github.com/Ontos-AI/knowhere
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ steps.revisions.outputs.build_time }}
ai.ontos.knowhere.api-ref=${{ inputs.api_ref }}
ai.ontos.knowhere.api-revision=${{ steps.revisions.outputs.api_commit }}
ai.ontos.knowhere.dashboard-ref=${{ inputs.dashboard_ref }}
ai.ontos.knowhere.dashboard-revision=${{ steps.revisions.outputs.dashboard_commit }}
- name: Build and publish combined image
id: build
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
build-args: |
APP_VERSION=${{ inputs.image_tag }}
BUILD_TIME=${{ steps.revisions.outputs.build_time }}
GIT_COMMIT=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create GitHub release
if: ${{ inputs.create_github_release }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE_TAG: ${{ inputs.image_tag }}
IMAGE_DIGEST: ${{ steps.build.outputs.digest }}
PUBLISH_LATEST: ${{ inputs.publish_latest }}
API_REF: ${{ inputs.api_ref }}
API_COMMIT: ${{ steps.revisions.outputs.api_commit }}
DASHBOARD_REF: ${{ inputs.dashboard_ref }}
DASHBOARD_COMMIT: ${{ steps.revisions.outputs.dashboard_commit }}
shell: bash
run: |
set -euo pipefail
mkdir -p release-assets
cp compose.yaml release-assets/compose.yaml
cp .env.defaults release-assets/env.defaults
ghcr_image_ref="${GHCR_IMAGE}:${IMAGE_TAG}"
ghcr_digest_ref="${GHCR_IMAGE}@${IMAGE_DIGEST}"
aliyun_image_ref="${ALIYUN_ACR_IMAGE}:${IMAGE_TAG}"
aliyun_digest_ref="${ALIYUN_ACR_IMAGE}@${IMAGE_DIGEST}"
{
echo "GHCR: ${ghcr_digest_ref}"
echo "Aliyun ACR: ${aliyun_digest_ref}"
} > release-assets/image-digest.txt
{
echo "self_hosted_repo=${GITHUB_REPOSITORY}"
echo "self_hosted_commit=${GITHUB_SHA}"
echo "api_ref=${API_REF}"
echo "api_commit=${API_COMMIT}"
echo "dashboard_ref=${DASHBOARD_REF}"
echo "dashboard_commit=${DASHBOARD_COMMIT}"
} > release-assets/source-revisions.txt
{
echo "Images:"
echo "- GHCR: \`${ghcr_image_ref}\`"
echo "- Aliyun ACR: \`${aliyun_image_ref}\`"
echo
echo "Digests:"
echo "- GHCR: \`${ghcr_digest_ref}\`"
echo "- Aliyun ACR: \`${aliyun_digest_ref}\`"
echo
echo "Source revisions:"
echo "- knowhere-self-hosted: \`${GITHUB_SHA}\`"
echo "- knowhere: \`${API_REF}\` / \`${API_COMMIT}\`"
echo "- knowhere-dashboard: \`${DASHBOARD_REF}\` / \`${DASHBOARD_COMMIT}\`"
echo
echo "Assets:"
echo "- \`compose.yaml\`: Docker Compose starter file"
echo "- \`env.defaults\`: default and reference environment variables"
echo "- \`image-digest.txt\`: immutable image digests"
echo "- \`source-revisions.txt\`: source refs included in this image"
} > release-notes.md
release_args=(
--repo "${GITHUB_REPOSITORY}"
--target "${GITHUB_SHA}"
--title "${IMAGE_TAG}"
--notes-file release-notes.md
)
if [[ "${IMAGE_TAG}" =~ -(alpha|beta|rc)(\\.|$) ]]; then
release_args+=(--prerelease --latest=false)
elif [ "${PUBLISH_LATEST}" != "true" ]; then
release_args+=(--latest=false)
fi
gh release create "${IMAGE_TAG}" \
release-assets/compose.yaml \
release-assets/env.defaults \
release-assets/image-digest.txt \
release-assets/source-revisions.txt \
"${release_args[@]}"