Skip to content

Commit

Permalink
feature(ai-service): automatically create docker image when pr merged (
Browse files Browse the repository at this point in the history
…#59)

* support the workflow to build nightly image

* remove the testing branch

* remove the deprecated workflow

* release nightly image workflow

* remove the testing branch

* rename the workflows

* manual release image workflow

* remove the testing branch

* release stable image

* remove the testing code

---------

Co-authored-by: Chih-Yu Yeh <[email protected]>
  • Loading branch information
paopa and cyyeh authored Apr 2, 2024
1 parent e031235 commit 342f876
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
name: AI Service Build image
name: AI Service Release image

on:
workflow_dispatch:
inputs:
docker_image_tag_name:
tag_name:
description: Docker image tag name (Optional)
type: string
is_latest:
description: Is latest (Optional)
type: boolean
required: false
default: false

defaults:
run:
Expand All @@ -21,6 +16,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare tag name
id: tag-preparation
run: |
if [ -n "${{ github.event.inputs.docker_image_tag_name }}" ]; then
tag_name=${{ github.event.inputs.tag_name }}
else
tag_name=commit-$(git log -1 --pretty=%h)
fi
echo "TAG_NAME=$tag_name" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand All @@ -31,30 +35,12 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare tag name
id: tag-preparation
run: |
if [ -n "${{ github.event.inputs.docker_image_tag_name }}" ]; then
tag_name=${{ github.event.inputs.docker_image_tag_name }}
else
tag_name=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')-$(git log -1 --pretty=%h)
fi
echo "TAG_NAME=$tag_name" >> $GITHUB_OUTPUT
- name: Build and push image
env:
TAG_NAME: ${{ steps.tag-preparation.outputs.TAG_NAME }}
run: |
if [ ${{ github.event.inputs.is_latest }} == true ]; then
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-ai-service:$TAG_NAME \
--tag ghcr.io/canner/wren-ai-service:latest \
--file ./docker/Dockerfile \
--push .
else
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-ai-service:$TAG_NAME \
--file ./docker/Dockerfile \
--push .
fi
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-ai-service:$TAG_NAME \
--file ./docker/Dockerfile \
--push .
42 changes: 42 additions & 0 deletions .github/workflows/ai-service-release-nightly-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: AI Service Release nightly image

on:
push:
branches: [main]
paths:
- 'wren-ai-service/**'

defaults:
run:
working-directory: wren-ai-service

jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare tag name
id: tag-preparation
run: |
tag_name=main-$(git log -1 --pretty=%h)
echo "TAG_NAME=$tag_name" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
env:
TAG_NAME: ${{ steps.tag-preparation.outputs.TAG_NAME }}
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-ai-service:$TAG_NAME \
--tag ghcr.io/canner/wren-ai-service:nightly \
--file ./docker/Dockerfile \
--push .
61 changes: 61 additions & 0 deletions .github/workflows/ai-service-release-stable-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: AI Service Release stable image

on:
workflow_dispatch:
inputs:
version:
description: Give a version for this release
type: string
required: true

defaults:
run:
working-directory: wren-ai-service

jobs:
upgrade-ai-service-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "stable-release-bot"
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.7.1
- name: Upgrade AI Service version
run: |
version=${{ github.event.inputs.version }}
poetry version --next-phase $version
git add pyproject.toml
git commit -m "Upgrade AI Service version to $version"
git push
build-image:
needs: upgrade-ai-service-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/canner/wren-ai-service:${{ github.event.inputs.version }} \
--tag ghcr.io/canner/wren-ai-service:latest \
--file ./docker/Dockerfile \
--push .

0 comments on commit 342f876

Please sign in to comment.