Skip to content

Build and Push Eliza Docker Image #17

Build and Push Eliza Docker Image

Build and Push Eliza Docker Image #17

Workflow file for this run

name: Build and Push Eliza Docker Image
on:
# 手动触发时添加输入参数
workflow_dispatch:
inputs:
tag_version:
description: "Specific tag version to build (e.g. v0.1.9). Leave empty for latest tag"
required: false
type: string
# 也可以在发布新版本时自动触发
schedule:
- cron: "0 0 * * *" # 每天UTC 00:00运行
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Clone Eliza repository
id: clone
run: |
git clone https://github.com/elizaos/eliza.git
cd eliza
git fetch --tags
if [ -n "${{ inputs.tag_version }}" ]; then
# 使用用户指定的tag
if git rev-parse "${{ inputs.tag_version }}" >/dev/null 2>&1; then
LATEST_TAG="${{ inputs.tag_version }}"
else
echo "Specified tag ${{ inputs.tag_version }} does not exist"
exit 1
fi
else
# 获取最新的符合条件的tag
LATEST_TAG=$(git tag -l 'v*.*.*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1)
if [ -z "$LATEST_TAG" ]; then
echo "No matching v*.x.x tag found"
exit 1
fi
fi
git checkout $LATEST_TAG
echo "Using Eliza version: $LATEST_TAG"
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
echo "LATEST_TAG_WITHOUT_PLUS=${LATEST_TAG//+/}" >> $GITHUB_ENV
sed -i 's/[email protected]/[email protected]/' Dockerfile
- name: Check if image exists
id: check_image
run: |
TOKEN=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://ghcr.io/token\?scope\="repository:${{ github.repository_owner }}/eliza:pull")
TOKEN=$(echo $TOKEN | jq -r .token)
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer $TOKEN" \
"https://ghcr.io/v2/${{ github.repository_owner }}/eliza/manifests/${{ env.LATEST_TAG_WITHOUT_PLUS }}")
if [ "$HTTP_CODE" -eq "200" ]; then
echo "Image tag ${{ env.LATEST_TAG_WITHOUT_PLUS }} already exists, skipping build"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Image tag ${{ env.LATEST_TAG_WITHOUT_PLUS }} does not exist, proceeding with build"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
if: steps.check_image.outputs.exists != 'true'
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: steps.check_image.outputs.exists != 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
if: steps.check_image.outputs.exists != 'true'
uses: docker/build-push-action@v5
with:
context: ./eliza
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/eliza:latest
ghcr.io/${{ github.repository_owner }}/eliza:${{ env.LATEST_TAG_WITHOUT_PLUS }}
cache-from: type=gha
cache-to: type=gha,mode=max