feat: build and docker image

This commit is contained in:
sunjuzhong 2025-03-09 15:31:54 +08:00
parent 2d75c7aa6f
commit df3dd3fb34
10 changed files with 111 additions and 43 deletions

View file

@ -2,24 +2,21 @@ name: Build Linux Artifacts
on:
workflow_dispatch:
inputs:
tags:
description: "Version tags"
env:
VERSION: 0.9.0
push:
tags:
- 'v*'
jobs:
build:
runs-on: "ubuntu-latest"
strategy:
matrix:
go: [1.23.4]
runs-on: "ubuntu-latest"
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- name: Install pnpm
run: npm install -g pnpm
@ -124,6 +121,8 @@ jobs:
- name: Make Artifacts Linux
run: |
make artifacts-linux
mv dist/release/yao-${{ env.VERSION }}-unstable-linux-arm64 dist/release/yao-${{ env.VERSION }}-linux-arm64
mv dist/release/yao-${{ env.VERSION }}-unstable-linux-amd64 dist/release/yao-${{ env.VERSION }}-linux-amd64
- name: Archive production artifacts
uses: actions/upload-artifact@v4

View file

@ -2,12 +2,9 @@ name: Build MacOS Artifacts
on:
workflow_dispatch:
inputs:
tags:
description: "Version tags"
env:
VERSION: 0.9.0
push:
tags:
- 'v*'
jobs:
build:
@ -19,7 +16,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- name: Install pnpm
run: npm install -g pnpm
@ -69,8 +66,6 @@ jobs:
done
- name: Checkout XGen v1.0
# ** XGEN will be renamed to DUI in the feature. and move to the new repository. **
# ** new repository: https://github.com/YaoApp/dui.git **
uses: actions/checkout@v4
with:
repository: sjzsdu/xgen
@ -116,8 +111,8 @@ jobs:
- name: Make Artifacts MacOS
run: |
make artifacts-macos
mv dist/release/yao-$VERSION-dev-darwin-arm64 dist/release/yao-$VERSION-unstable-darwin-arm64
mv dist/release/yao-$VERSION-dev-darwin-amd64 dist/release/yao-$VERSION-unstable-darwin-amd64
mv dist/release/yao-${{ env.VERSION }}-dev-darwin-arm64 dist/release/yao-${{ env.VERSION }}-darwin-arm64
mv dist/release/yao-${{ env.VERSION }}-dev-darwin-amd64 dist/release/yao-${{ env.VERSION }}-darwin-amd64
- name: Archive production artifacts
uses: actions/upload-artifact@v4

59
.github/workflows/publish-docker.yml vendored Normal file
View file

@ -0,0 +1,59 @@
name: Publish Docker Image
on:
workflow_dispatch:
inputs:
run_id:
description: "Build Linux Artifacts Run ID"
required: false
type: string
workflow_run:
workflows: ["Build Linux Artifacts"]
types:
- completed
env:
DOCKER_IMAGE: yaoapp/yao
PLATFORMS: linux/amd64,linux/arm64
jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: yao-linux
path: dist/release
run-id: ${{ github.event.workflow_run.id || inputs.run_id }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get Version
run: |
VERSION=$(ls dist/release/yao-*-linux-amd64 | sed 's/.*yao-\(.*\)-unstable-linux-amd64/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: docker/base/Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}
build-args: |
VERSION=${{ env.VERSION }}

1
.gitignore vendored
View file

@ -43,3 +43,4 @@ docker/build/test
db
*.sh
!get-yao.sh
__debug*

11
.vscode/launch.json vendored
View file

@ -16,17 +16,6 @@
"yao.app.menu",
],
},
{
"name": "Launch Yao Project",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"cwd": "/Users/juzhongsun/Works/yao-project",
"args": [
"start"
],
},
{
"name": "Launch Fabric Project",
"type": "go",

View file

@ -1,7 +1,7 @@
## Install Yao
```
curl -sSL https://github.com/sjzsdu/yao/raw/master/get-yao.sh | bash
curl -sSL https://raw.githubusercontent.com/sjzsdu/yao/refs/heads/main/get-yao.sh | bash
```
## What is Yao?

View file

@ -3,7 +3,7 @@
## 安装 Yao
```
curl -sSL https://github.com/sjzsdu/yao/raw/master/get-wn.sh | bash
curl -sSL https://raw.githubusercontent.com/sjzsdu/yao/refs/heads/main/get-yao.sh | bash
```
[![UnitTest](https://github.com/YaoApp/yao/actions/workflows/unit-test.yml/badge.svg)](https://github.com/YaoApp/yao/actions/workflows/unit-test.yml)

26
docker/base/Dockerfile Normal file
View file

@ -0,0 +1,26 @@
# ===========================================
# Yao Base Image
# A minimal base image for running Yao applications
#
# Build:
# docker build --platform linux/amd64 --build-arg VERSION=0.10.4 --build-arg ARCH=amd64 -t yaoapp/yao-base:0.10.4-amd64 .
# docker build --platform linux/arm64 --build-arg VERSION=0.10.4 --build-arg ARCH=arm64 -t yaoapp/yao-base:0.10.4-arm64 .
#
# Tests:
# docker run --rm yaoapp/yao-base:0.10.4-amd64 yao version
#
# ===========================================
FROM alpine:latest
ARG VERSION
ARG ARCH
# Install minimal dependencies
RUN apk --no-cache add curl
# Copy and install Yao binary from build artifacts
COPY dist/yao-${VERSION}-linux-${ARCH} /usr/local/bin/yao
RUN chmod +x /usr/local/bin/yao && \
addgroup -S yao && adduser -S -G yao yao
# Switch to non-root user
USER yao

View file

@ -2,12 +2,10 @@
# 定义 GitHub 仓库信息
REPO="sjzsdu/yao"
API_URL="https://api.github.com/repos/$REPO/releases/latest"
CONST_URL="https://raw.githubusercontent.com/$REPO/main/share/const.go"
# 获取最新版本号
VERSION=$(curl -s $API_URL | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# 获取最新版本号并移除 'v' 前缀(如果存在)
VERSION_NO=$(echo $VERSION | sed 's/^v//')
# 从 const.go 文件获取最新版本号
VERSION=$(curl -s $CONST_URL | grep 'const VERSION' | awk -F '"' '{print $2}')
# 检测操作系统类型和架构
OS="unknown"
@ -35,12 +33,13 @@ else
fi
# 构建下载 URL
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/yao-$VERSION_NO-unstable-$OS-$ARCH"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/v$VERSION/yao-$VERSION-$OS-$ARCH"
# 下载文件
echo "正在下载 yao-$OS-$ARCH ..."
echo "正在下载 yao-$OS-$ARCH 版本 $VERSION ..."
curl -L $DOWNLOAD_URL -o yao
echo $DOWNLOAD_URL
echo "下载 URL: $DOWNLOAD_URL"
# 使文件可执行
chmod +x yao

View file

@ -1,7 +1,7 @@
package share
// VERSION 版本号
const VERSION = "0.10.4"
const VERSION = "0.10.4.1"
// PRVERSION PreRelease Version
const PRVERSION = "DEV"