-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable microservice docker images auto build and push (#202)
Signed-off-by: chensuyue <[email protected]>
- Loading branch information
Showing
6 changed files
with
197 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Test | ||
name: Build latest images on push event | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
paths: | ||
- comps/** | ||
- "!**.md" | ||
- "!**.txt" | ||
- .github/workflows/image-build-on-push.yml | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-on-push | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
job1: | ||
uses: ./.github/workflows/reuse-get-test-matrix.yml | ||
|
||
image-build: | ||
needs: job1 | ||
strategy: | ||
matrix: ${{ fromJSON(needs.job1.outputs.run_matrix) }} | ||
uses: ./.github/workflows/reuse-image-build.yml | ||
with: | ||
micro_service: "${{ matrix.service }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Support push and pull_request events | ||
name: Get Test Matrix | ||
permissions: read-all | ||
on: | ||
workflow_call: | ||
outputs: | ||
run_matrix: | ||
description: "The matrix string" | ||
value: ${{ jobs.job1.outputs.run_matrix }} | ||
|
||
jobs: | ||
job1: | ||
name: Get-test-matrix | ||
runs-on: ubuntu-latest | ||
outputs: | ||
run_matrix: ${{ steps.get-test-matrix.outputs.run_matrix }} | ||
steps: | ||
- name: Get checkout ref | ||
run: | | ||
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then | ||
echo "CHECKOUT_REF=refs/pull/${{ github.event.number }}/merge" >> $GITHUB_ENV | ||
else | ||
echo "CHECKOUT_REF=${{ github.ref }}" >> $GITHUB_ENV | ||
fi | ||
echo "checkout ref ${{ env.CHECKOUT_REF }}" | ||
- name: Checkout out Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ env.CHECKOUT_REF }} | ||
fetch-depth: 0 | ||
|
||
- name: Get test matrix | ||
id: get-test-matrix | ||
run: | | ||
set -xe | ||
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then | ||
base_commit=${{ github.event.pull_request.base.sha }} | ||
else | ||
base_commit=$(git rev-parse HEAD~1) # push event | ||
fi | ||
merged_commit=$(git log -1 --format='%H') | ||
changed_files="$(git diff --name-only ${base_commit} ${merged_commit} | \ | ||
grep 'comps/' | grep -vE '*.md|*.txt|comps/cores')" || true | ||
services=$(printf '%s\n' "${changed_files[@]}" | cut -d'/' -f2 | grep -vE '*.py' | sort -u) | ||
path_level_1=("asr" "tts") | ||
path_level_3=("llms/summarization" "llms/text-generation" "dataprep/redis" "retrievers/langchain/redis") | ||
run_matrix="{\"include\":[" | ||
for service in ${services}; do | ||
hardware="gaudi" # default hardware, set based on the changed files | ||
if [[ "${path_level_1[@]}" =~ "${service}" ]]; then | ||
run_matrix="${run_matrix}{\"service\":\"${service}\",\"hardware\":\"${hardware}\"}," | ||
else | ||
vendors=$(printf '%s\n' "${changed_files[@]}" | grep ${service} | cut -d'/' -f3 | grep -vE '*.py|Dockerfile|*.md' | sort -u) | ||
for vendor in ${vendors}; do | ||
if [[ "${path_level_3[@]}" =~ "${service}/${vendor}" ]]; then | ||
sub_vendors=$(printf '%s\n' "${changed_files[@]}" | grep ${service} | grep ${vendor} | cut -d'/' -f4 | grep -vE '*.py' | sort -u) | ||
for sub_vendor in ${sub_vendors}; do | ||
run_matrix="${run_matrix}{\"service\":\"${service}/${vendor}/${sub_vendor}\",\"hardware\":\"${hardware}\"}," | ||
done | ||
else | ||
run_matrix="${run_matrix}{\"service\":\"${service}/${vendor}\",\"hardware\":\"${hardware}\"}," | ||
fi | ||
done | ||
fi | ||
done | ||
run_matrix=$run_matrix"]}" | ||
echo "run_matrix=${run_matrix}" >> $GITHUB_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: Image Build | ||
permissions: read-all | ||
on: | ||
workflow_call: | ||
inputs: | ||
micro_service: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
micro-image-build: | ||
continue-on-error: true | ||
strategy: | ||
matrix: | ||
node: [docker-build-xeon, docker-build-gaudi] | ||
runs-on: ${{ matrix.node }} | ||
steps: | ||
- name: Checkout out Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Building MicroService Docker Image | ||
id: build-microservice-image | ||
env: | ||
micro_service: ${{ inputs.micro_service }} | ||
run: | | ||
bash .github/workflows/scripts/docker_images_build_push.sh ${micro_service} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -xe | ||
|
||
WORKSPACE=$PWD | ||
IMAGE_REPO=${IMAGE_REPO:-$OPEA_IMAGE_REPO} | ||
IMAGE_TAG=${IMAGE_TAG:-latest} | ||
|
||
function docker_build() { | ||
# docker_build <IMAGE_NAME> | ||
IMAGE_NAME=$1 | ||
micro_service=$2 | ||
dockerfile_path=${WORKSPACE}/comps/${micro_service} | ||
if [ -f "$dockerfile_path/Dockerfile" ]; then | ||
DOCKERFILE_PATH="$dockerfile_path/Dockerfile" | ||
elif [ -f "$dockerfile_path/docker/Dockerfile" ]; then | ||
DOCKERFILE_PATH="$dockerfile_path/docker/Dockerfile" | ||
else | ||
echo "Dockerfile not found" | ||
exit 1 | ||
fi | ||
echo "Building ${IMAGE_REPO}${IMAGE_NAME}:$IMAGE_TAG using Dockerfile $DOCKERFILE_PATH" | ||
|
||
docker build --no-cache -t ${IMAGE_REPO}${IMAGE_NAME}:$IMAGE_TAG -f $DOCKERFILE_PATH . | ||
docker push ${IMAGE_REPO}${IMAGE_NAME}:$IMAGE_TAG | ||
docker rmi ${IMAGE_REPO}${IMAGE_NAME}:$IMAGE_TAG | ||
} | ||
|
||
micro_service=$1 | ||
case ${micro_service} in | ||
"asr"|"tts") | ||
IMAGE_NAME="opea/${micro_service}" | ||
;; | ||
"embeddings/langchain") | ||
IMAGE_NAME="opea/embedding-tei" | ||
;; | ||
"retrievers/langchain") | ||
IMAGE_NAME="opea/retriever-redis" | ||
;; | ||
"reranks/langchain") | ||
IMAGE_NAME="opea/reranking-tei" | ||
;; | ||
"llms/text-generation/tgi") | ||
IMAGE_NAME="opea/llm-tgi" | ||
;; | ||
"dataprep/redis/langchain") | ||
IMAGE_NAME="opea/dataprep-redis" | ||
;; | ||
"llms/summarization/tgi") | ||
IMAGE_NAME="opea/llm-docsum-tgi" | ||
;; | ||
*) | ||
echo "Not supported yet" | ||
exit 0 | ||
;; | ||
esac | ||
docker_build "${IMAGE_NAME}" "${micro_service}" |
File renamed without changes.