Skip to content

Commit 25a40cc

Browse files
committed
feat: 添加Docker部署支持和自动化构建流程
- 新增Dockerfile用于容器化部署 - 添加GitHub Actions工作流实现Docker镜像自动构建和推送 - 支持多平台架构(linux/amd64, linux/arm64) - 添加docker-compose配置文件 - 实现DockerHub和GHCR双平台镜像推送 - 添加一键安装脚本install.sh - 配置Redis和Node.js运行环境
1 parent 2632cf0 commit 25a40cc

6 files changed

Lines changed: 221 additions & 0 deletions

File tree

.github/workflows/build.yaml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Build Docker
2+
3+
on:
4+
workflow_call:
5+
6+
env:
7+
DOCKERHUB_REPO: karinjs/karin
8+
GHCR_REPO: ghcr.io/karinjs/karin
9+
10+
jobs:
11+
build:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
include:
16+
- platform: linux/amd64
17+
os: ubuntu-latest
18+
- platform: linux/arm64
19+
os: ubuntu-24.04-arm
20+
steps:
21+
- name: 检出代码
22+
uses: actions/checkout@v6
23+
24+
- name: 设置 Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: 登录DockerHub
28+
uses: docker/login-action@v3
29+
with:
30+
username: ${{ secrets.DOCKERHUB_USERNAME }}
31+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
32+
33+
- name: 登录GHCR
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.repository_owner }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- uses: docker/build-push-action@v6
41+
with:
42+
push: true
43+
platforms: ${{ matrix.platform }}
44+
tags: |
45+
${{ env.DOCKERHUB_REPO }}:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
46+
${{ env.GHCR_REPO }}:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
47+
48+
push:
49+
needs: [build]
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: 设置 Buildx
53+
uses: docker/setup-buildx-action@v3
54+
55+
- name: 登录DockerHub
56+
uses: docker/login-action@v3
57+
with:
58+
username: ${{ secrets.DOCKERHUB_USERNAME }}
59+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
60+
61+
- name: 登录GHCR
62+
uses: docker/login-action@v3
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.repository_owner }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: 创建并推送多平台清单
69+
run: |
70+
docker buildx imagetools create \
71+
-t ${{ env.DOCKERHUB_REPO }}:latest \
72+
${{ env.DOCKERHUB_REPO }}:amd64 \
73+
${{ env.DOCKERHUB_REPO }}:arm64
74+
75+
docker buildx imagetools create \
76+
-t ${{ env.GHCR_REPO }}:latest \
77+
${{ env.GHCR_REPO }}:amd64 \
78+
${{ env.GHCR_REPO }}:arm64
79+
80+
- name: 检查镜像
81+
run: |
82+
docker buildx imagetools inspect ${{ env.DOCKERHUB_REPO }}:latest
83+
docker buildx imagetools inspect ${{ env.GHCR_REPO }}:latest

.github/workflows/docker.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
build-docker:
14+
uses: ./.github/workflows/build.yaml

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM debian:bookworm-slim
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
ca-certificates \
5+
ffmpeg \
6+
curl \
7+
openssl \
8+
git \
9+
redis-server \
10+
fontconfig \
11+
&& apt-get clean \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
15+
&& apt-get install -y nodejs
16+
17+
ENV PATH=/usr/local/bin:$PATH
18+
19+
RUN npm i -g pnpm@9
20+
21+
COPY entrypoint.sh /app/entrypoint.sh
22+
RUN chmod +x /app/entrypoint.sh
23+
24+
WORKDIR /app
25+
RUN pnpm init && pnpm install node-karin && npx karin init
26+
27+
EXPOSE 7777
28+
CMD ["bash", "./entrypoint.sh"]

docker-compose.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: "3.8"
2+
3+
services:
4+
karin:
5+
image: karinjs/karin:main
6+
container_name: karin
7+
restart: unless-stopped
8+
network_mode: "bridge"
9+
ports:
10+
- "7777:7777"
11+
volumes:
12+
- /opt/karin:/app
13+
environment:
14+
HTTP_PORT: 7777

entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# 启动应用
4+
cd /app
5+
pnpm install
6+
exec pnpm app

install.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
DOCKER_IMAGE="karinjs/karin:latest"
3+
PORT=7777
4+
INSTALL_PATH="/opt/karin"
5+
6+
while getopts "p:d:" opt; do
7+
case $opt in
8+
p)
9+
PORT=$OPTARG
10+
;;
11+
d)
12+
INSTALL_PATH=$OPTARG
13+
;;
14+
*)
15+
echo "Usage: $0 [-p port] [-d install_path]"
16+
exit 1
17+
;;
18+
esac
19+
done
20+
21+
# 检查curl是否安装
22+
check_curl() {
23+
if command -v curl >/dev/null 2>&1; then
24+
echo "curl 已安装"
25+
return 0
26+
else
27+
echo "正在安装 curl..."
28+
if command -v apt-get >/dev/null 2>&1; then
29+
apt-get update && apt-get install -y curl
30+
elif command -v yum >/dev/null 2>&1; then
31+
yum install -y curl
32+
elif command -v pacman >/dev/null 2>&1; then
33+
pacman -Sy --noconfirm curl
34+
else
35+
echo "无法安装 curl:未找到包管理器"
36+
exit 1
37+
fi
38+
echo "curl 安装完成"
39+
fi
40+
}
41+
42+
# 检查docker是否安装
43+
check_docker() {
44+
if command -v docker >/dev/null 2>&1; then
45+
echo "Docker 已安装"
46+
return 0
47+
else
48+
echo "正在安装 Docker..."
49+
if command -v pacman >/dev/null 2>&1; then
50+
pacman -Sy --noconfirm docker
51+
else
52+
curl -fsSL https://get.docker.com | bash
53+
fi
54+
echo "Docker 安装完成"
55+
fi
56+
}
57+
58+
# 安装Karin
59+
install_karin(){
60+
echo "正在安装 Karin..."
61+
docker pull $DOCKER_IMAGE
62+
docker run -d --name karin --restart=always \
63+
-e TZ=Asia/Shanghai \
64+
-p $PORT:7777 \
65+
-v $INSTALL_PATH:/app \
66+
$DOCKER_IMAGE
67+
source ~/.bashrc
68+
echo "Karin 安装完成, 安装目录为 $INSTALL_PATH"
69+
}
70+
71+
# 主程序
72+
echo '欢迎使用 Karin 安装脚本'
73+
check_curl
74+
check_docker
75+
install_karin
76+
echo '安装完成, 可使用karin命令'

0 commit comments

Comments
 (0)