Skip to content

Commit ee87882

Browse files
committed
feat: add Docker support with build and push workflow
1 parent 62ff95c commit ee87882

3 files changed

Lines changed: 171 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Build and Push LLOneBot Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version tag for the Docker image'
10+
required: false
11+
type: string
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # Fetch all history and tags
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Login to Docker Hub
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKER_USERNAME }}
30+
password: ${{ secrets.DOCKER_PASSWORD }}
31+
32+
- name: Determine version
33+
id: version
34+
run: |
35+
if [ "${{ github.event_name }}" = "release" ]; then
36+
# Extract version from release tag (remove 'v' prefix if present)
37+
version="${{ github.event.release.tag_name }}"
38+
version=${version#v}
39+
echo "Version from release: $version"
40+
else
41+
# Manual trigger - check if version is provided
42+
input_version="${{ github.event.inputs.version }}"
43+
if [ -n "$input_version" ] && [ "$input_version" != "" ]; then
44+
# Use provided version
45+
version="$input_version"
46+
echo "Version from manual input: $version"
47+
else
48+
# Get latest tag if no version provided
49+
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
50+
if [ -n "$latest_tag" ]; then
51+
version=${latest_tag#v}
52+
echo "Version from latest tag: $version (tag: $latest_tag)"
53+
else
54+
# Fallback to default if no tags exist
55+
version="5.8.0"
56+
echo "No tags found, using fallback version: $version"
57+
fi
58+
fi
59+
fi
60+
echo "version=$version" >> $GITHUB_OUTPUT
61+
62+
- name: Build and push LLOneBot Docker image
63+
run: |
64+
version="${{ steps.version.outputs.version }}"
65+
username="${{ secrets.DOCKER_USERNAME }}"
66+
echo "Building LLOneBot with version: $version"
67+
docker buildx build \
68+
--progress=plain \
69+
--build-arg LLONEBOT_VERSION="$version" \
70+
--platform linux/amd64,linux/arm64 \
71+
-t "$username/llonebot:$version" \
72+
-t "$username/llonebot:latest" \
73+
-f docker/llonebot/Dockerfile \
74+
--push \
75+
.
76+
77+
- name: Output build summary
78+
run: |
79+
echo "✅ Successfully built and pushed LLOneBot Docker image"
80+
echo "📦 Image tags:"
81+
echo " - ${{ secrets.DOCKER_USERNAME }}/llonebot:${{ steps.version.outputs.version }}"
82+
echo " - ${{ secrets.DOCKER_USERNAME }}/llonebot:latest"

docker/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM node:lts-alpine
2+
3+
ARG LLONEBOT_VERSION
4+
5+
RUN set -eux; \
6+
# 获取当前系统 Alpine 主要版本 (如 3.19)
7+
ALPINE_VERSION=$(grep -oE '[0-9]+\.[0-9]+' /etc/alpine-release); \
8+
# 检查版本号是否有效
9+
[ -n "$ALPINE_VERSION" ] || { echo "Error: Failed to get Alpine version"; exit 1; }; \
10+
# 配置阿里云镜像源
11+
echo "https://mirrors.aliyun.com/alpine/v$ALPINE_VERSION/main" > /etc/apk/repositories; \
12+
echo "https://mirrors.aliyun.com/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories; \
13+
# 更新索引
14+
apk update; \
15+
# 安装时区工具
16+
apk add --no-cache tzdata ffmpeg; \
17+
# 设置时区为上海
18+
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime; \
19+
echo "Asia/Shanghai" > /etc/timezone; \
20+
# 清理缓存减少镜像体积
21+
rm -rf /var/cache/apk/*
22+
23+
RUN apk add unzip wget
24+
25+
WORKDIR /app/llonebot
26+
27+
COPY docker/llonebot/startup.sh /startup.sh
28+
29+
RUN chmod +x /startup.sh
30+
31+
RUN wget https://github.com/LLOneBot/LLOneBot/releases/download/v$LLONEBOT_VERSION/LLOneBot.zip -O /app/llonebot.zip
32+
33+
#COPY /dist/llonebot.zip /app/llonebot.zip
34+
35+
RUN unzip /app/llonebot.zip -d /app/llonebot \
36+
&& rm /app/llonebot.zip
37+
38+
ENTRYPOINT ["/startup.sh"]

docker/startup.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/ash
2+
3+
cd /app/llonebot
4+
5+
FILE="default_config.json"
6+
7+
sed -i "/\"webui\": {/,/}/ {
8+
s/\"enable\": true/\"enable\": ${ENABLE_WEBUI}/g
9+
}" "$FILE"
10+
sed -i "/\"webui\": {/,/}/ {
11+
s/\"port\":\s*3080/\"port\": ${WEBUI_PORT}/g
12+
}" "$FILE"
13+
14+
sed -i "s/\"enableWs\":\s*true/\"enableWs\": ${ENABLE_ONEBOT_WS}/g" "$FILE"
15+
sed -i "s/\"enableHttp\":\s*true/\"enableHttp\": ${ENABLE_ONEBOT_HTTP}/g" "$FILE"
16+
17+
sed -i "s/\"httpPort\":\s*3000/\"httpPort\": ${ONEBOT_HTTP_PORT}/g" "$FILE"
18+
sed -i "s/\"wsPort\":\s*3001/\"wsPort\": ${ONEBOT_WS_PORT}/g" "$FILE"
19+
20+
sed -i "s|\"httpPostUrls\":\s*\[\]|\"httpPostUrls\": ${ONEBOT_HTTP_URLS}|g" "$FILE"
21+
sed -i "s|\"wsReverseUrls\":\s*\[\]|\"wsReverseUrls\": ${ONEBOT_WS_URLS}|g" "$FILE"
22+
sed -i "/\"ob11\": {/,/}/ {
23+
s/\"token\":\s*\"\"/\"token\": \"${ONEBOT_TOKEN}\"/g
24+
}" "$FILE"
25+
26+
sed -i "s/\"httpSecret\":\s*\"\"/\"httpSecret\": \"${ONEBOT_SECRET}\"/g" "$FILE"
27+
28+
sed -i "/\"satori\": {/,/}/ {
29+
s/\"enable\": true/\"enable\": ${ENABLE_SATORI}/g
30+
}" "$FILE"
31+
32+
sed -i "/\"satori\": {/,/}/ {
33+
s/\"token\":\s*\"\"/\"token\": \"${SATORI_TOKEN}\"/g
34+
}" "$FILE"
35+
36+
sed -i "/\"satori\": {/,/}/ {
37+
s/\"port\":\s*5600/\"port\": ${SATORI_PORT}/g
38+
}" "$FILE"
39+
40+
sed -i "s/\"onlyLocalhost\":\s*true/\"onlyLocalhost\": false/g" "$FILE"
41+
sed -i "s|\"ffmpeg\":\s*\"\"|\"ffmpeg\": \"/usr/bin/ffmpeg\"|g" "$FILE"
42+
43+
port="13000"
44+
host="pmhq"
45+
if [ -n "$pmhq_port" ]; then
46+
port="$pmhq_port"
47+
fi
48+
if [ -n "$pmhq_host" ]; then
49+
port="$pmhq_host"
50+
fi
51+
node ./llonebot.js --pmhq-port=$port --pmhq-host=$host

0 commit comments

Comments
 (0)