ci(docker-build): build nightly image everyday (#3120)
* ci: build test image on master pushes * ci: split workflows for master test and release builds * test ci * test ci * Update docker-image.yml * test ci Updated README to enhance deployment instructions. * Make GHCR publishing optional in Docker workflow * chore: Update DockerHub password secret in workflow * Update .github/workflows/docker-image.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: rename job to build nightly image in workflow * feat: schedule the nightly build at 0:00 am everyday, if have new commits * fix: update build-nightly-image job to trigger only on schedule events * Update fetch-depth and enable fetch-tag in workflows --------- Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> Co-authored-by: LIghtJUNction <lightjunction.me@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Soulter <905617992@qq.com>
This commit is contained in:
143
.github/workflows/docker-image.yml
vendored
143
.github/workflows/docker-image.yml
vendored
@@ -3,18 +3,125 @@ name: Docker Image CI/CD
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- "v*"
|
||||||
|
schedule:
|
||||||
|
# Run at 00:00 UTC every day
|
||||||
|
- cron: "0 0 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-docker:
|
build-nightly-image:
|
||||||
|
if: github.event_name == 'schedule'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
GHCR_OWNER: ${{ github.repository_owner }}
|
||||||
|
HAS_GHCR_TOKEN: ${{ secrets.GHCR_GITHUB_TOKEN != '' }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Pull The Codes
|
- name: Checkout
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Must be 0 so we can fetch tags
|
fetch-depth: 1
|
||||||
|
fetch-tag: true
|
||||||
|
|
||||||
|
- name: Check for new commits today
|
||||||
|
if: github.event_name == 'schedule'
|
||||||
|
id: check-commits
|
||||||
|
run: |
|
||||||
|
# Get commits from the last 24 hours
|
||||||
|
commits=$(git log --since="24 hours ago" --oneline)
|
||||||
|
if [ -z "$commits" ]; then
|
||||||
|
echo "No commits in the last 24 hours, skipping build"
|
||||||
|
echo "has_commits=false" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "Found commits in the last 24 hours:"
|
||||||
|
echo "$commits"
|
||||||
|
echo "has_commits=true" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Exit if no commits
|
||||||
|
if: github.event_name == 'schedule' && steps.check-commits.outputs.has_commits == 'false'
|
||||||
|
run: exit 0
|
||||||
|
|
||||||
|
- name: Build Dashboard
|
||||||
|
run: |
|
||||||
|
cd dashboard
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
mkdir -p dist/assets
|
||||||
|
echo $(git rev-parse HEAD) > dist/assets/version
|
||||||
|
cd ..
|
||||||
|
mkdir -p data
|
||||||
|
cp -r dashboard/dist data/
|
||||||
|
|
||||||
|
- name: Determine test image tags
|
||||||
|
id: test-meta
|
||||||
|
run: |
|
||||||
|
short_sha=$(echo "${GITHUB_SHA}" | cut -c1-12)
|
||||||
|
build_date=$(date +%Y%m%d)
|
||||||
|
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
|
||||||
|
echo "build_date=$build_date" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Set QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to DockerHub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
if: env.HAS_GHCR_TOKEN == 'true'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ env.GHCR_OWNER }}
|
||||||
|
password: ${{ secrets.GHCR_GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build nightly image tags list
|
||||||
|
id: test-tags
|
||||||
|
run: |
|
||||||
|
TAGS="${{ env.DOCKER_HUB_USERNAME }}/astrbot:nightly-latest
|
||||||
|
${{ env.DOCKER_HUB_USERNAME }}/astrbot:nightly-${{ steps.test-meta.outputs.build_date }}-${{ steps.test-meta.outputs.short_sha }}"
|
||||||
|
if [ "${{ env.HAS_GHCR_TOKEN }}" = "true" ]; then
|
||||||
|
TAGS="$TAGS
|
||||||
|
ghcr.io/${{ env.GHCR_OWNER }}/astrbot:nightly-latest
|
||||||
|
ghcr.io/${{ env.GHCR_OWNER }}/astrbot:nightly-${{ steps.test-meta.outputs.build_date }}-${{ steps.test-meta.outputs.short_sha }}"
|
||||||
|
fi
|
||||||
|
echo "tags<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
echo "$TAGS" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and Push Nightly Image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.test-tags.outputs.tags }}
|
||||||
|
|
||||||
|
- name: Post build notifications
|
||||||
|
run: echo "Test Docker image has been built and pushed successfully"
|
||||||
|
|
||||||
|
build-release-image:
|
||||||
|
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
GHCR_OWNER: ${{ github.repository_owner }}
|
||||||
|
HAS_GHCR_TOKEN: ${{ secrets.GHCR_GITHUB_TOKEN != '' }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
fetch-tag: true
|
||||||
|
|
||||||
- name: Get latest tag (only on manual trigger)
|
- name: Get latest tag (only on manual trigger)
|
||||||
id: get-latest-tag
|
id: get-latest-tag
|
||||||
@@ -27,21 +134,22 @@ jobs:
|
|||||||
if: github.event_name == 'workflow_dispatch'
|
if: github.event_name == 'workflow_dispatch'
|
||||||
run: git checkout ${{ steps.get-latest-tag.outputs.latest_tag }}
|
run: git checkout ${{ steps.get-latest-tag.outputs.latest_tag }}
|
||||||
|
|
||||||
- name: Check if version is pre-release
|
- name: Compute release metadata
|
||||||
id: check-prerelease
|
id: release-meta
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
version="${{ steps.get-latest-tag.outputs.latest_tag }}"
|
version="${{ steps.get-latest-tag.outputs.latest_tag }}"
|
||||||
else
|
else
|
||||||
version="${{ github.ref_name }}"
|
version="${GITHUB_REF#refs/tags/}"
|
||||||
fi
|
fi
|
||||||
if [[ "$version" == *"beta"* ]] || [[ "$version" == *"alpha"* ]]; then
|
if [[ "$version" == *"beta"* ]] || [[ "$version" == *"alpha"* ]]; then
|
||||||
echo "is_prerelease=true" >> $GITHUB_OUTPUT
|
echo "is_prerelease=true" >> $GITHUB_OUTPUT
|
||||||
echo "Version $version is a pre-release, will not push latest tag"
|
echo "Version $version marked as pre-release"
|
||||||
else
|
else
|
||||||
echo "is_prerelease=false" >> $GITHUB_OUTPUT
|
echo "is_prerelease=false" >> $GITHUB_OUTPUT
|
||||||
echo "Version $version is a stable release, will push latest tag"
|
echo "Version $version marked as stable"
|
||||||
fi
|
fi
|
||||||
|
echo "version=$version" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Build Dashboard
|
- name: Build Dashboard
|
||||||
run: |
|
run: |
|
||||||
@@ -67,23 +175,24 @@ jobs:
|
|||||||
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
|
if: env.HAS_GHCR_TOKEN == 'true'
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: Soulter
|
username: ${{ env.GHCR_OWNER }}
|
||||||
password: ${{ secrets.GHCR_GITHUB_TOKEN }}
|
password: ${{ secrets.GHCR_GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and Push Docker to DockerHub and Github GHCR
|
- name: Build and Push Release Image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ steps.check-prerelease.outputs.is_prerelease == 'false' && format('{0}/astrbot:latest', secrets.DOCKER_HUB_USERNAME) || '' }}
|
${{ steps.release-meta.outputs.is_prerelease == 'false' && format('{0}/astrbot:latest', env.DOCKER_HUB_USERNAME) || '' }}
|
||||||
${{ secrets.DOCKER_HUB_USERNAME }}/astrbot:${{ github.event_name == 'workflow_dispatch' && steps.get-latest-tag.outputs.latest_tag || github.ref_name }}
|
${{ steps.release-meta.outputs.is_prerelease == 'false' && env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:latest', env.GHCR_OWNER) || '' }}
|
||||||
${{ steps.check-prerelease.outputs.is_prerelease == 'false' && 'ghcr.io/soulter/astrbot:latest' || '' }}
|
${{ format('{0}/astrbot:{1}', env.DOCKER_HUB_USERNAME, steps.release-meta.outputs.version) }}
|
||||||
ghcr.io/soulter/astrbot:${{ github.event_name == 'workflow_dispatch' && steps.get-latest-tag.outputs.latest_tag || github.ref_name }}
|
${{ env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:{1}', env.GHCR_OWNER, steps.release-meta.outputs.version) || '' }}
|
||||||
|
|
||||||
- name: Post build notifications
|
- name: Post build notifications
|
||||||
run: echo "Docker image has been built and pushed successfully"
|
run: echo "Release Docker image has been built and pushed successfully"
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ AstrBot 是一个开源的一站式 Agent 聊天机器人平台及开发框架
|
|||||||
4. **插件扩展**。深度优化的插件机制,支持[开发插件](https://astrbot.app/dev/plugin.html)扩展功能,社区插件生态丰富。
|
4. **插件扩展**。深度优化的插件机制,支持[开发插件](https://astrbot.app/dev/plugin.html)扩展功能,社区插件生态丰富。
|
||||||
5. **WebUI**。可视化配置和管理机器人,功能齐全。
|
5. **WebUI**。可视化配置和管理机器人,功能齐全。
|
||||||
|
|
||||||
## 部署方式
|
## 部署方式
|
||||||
|
|
||||||
#### Docker 部署(推荐 🥳)
|
#### Docker 部署(推荐 🥳)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user