mirror of
https://github.com/zeke-chin/cursor-api.git
synced 2025-10-05 23:46:51 +08:00
add: github workflow
This commit is contained in:
140
.github/workflows/build-rs-capi.yml
vendored
Normal file
140
.github/workflows/build-rs-capi.yml
vendored
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
name: Build and Push RS-CAPI Docker Images
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
tags: [ "v*" ]
|
||||||
|
paths:
|
||||||
|
- 'rs-capi/**'
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}/rs-capi
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- runner: ubuntu-latest
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
- runner: macos-latest
|
||||||
|
platforms: darwin/amd64
|
||||||
|
- runner: macos-14
|
||||||
|
platforms: darwin/arm64
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
permissions:
|
||||||
|
contents: write # 需要写入权限来创建 release
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # 获取完整的 git 历史用于生成 changelog
|
||||||
|
|
||||||
|
- name: Set up Docker
|
||||||
|
if: runner.os == 'macOS'
|
||||||
|
run: |
|
||||||
|
brew install docker docker-buildx
|
||||||
|
colima start
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=sha
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: ./rs-capi
|
||||||
|
file: ./rs-capi/Dockerfile
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
platforms: ${{ matrix.platforms }}
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
create-release:
|
||||||
|
needs: build-and-push
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Generate Changelog
|
||||||
|
id: changelog
|
||||||
|
uses: mikepenz/release-changelog-builder-action@v4
|
||||||
|
with:
|
||||||
|
configuration: |
|
||||||
|
{
|
||||||
|
"categories": [
|
||||||
|
{
|
||||||
|
"title": "## 🚀 Features",
|
||||||
|
"labels": ["feature"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## 🐛 Fixes",
|
||||||
|
"labels": ["fix"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## 📦 Dependencies",
|
||||||
|
"labels": ["dependencies"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
body: |
|
||||||
|
## Docker Images
|
||||||
|
You can pull the Docker images using:
|
||||||
|
```bash
|
||||||
|
docker pull ghcr.io/${{ github.repository }}/rs-capi:${{ github.ref_name }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Available platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
- darwin/amd64
|
||||||
|
- darwin/arm64
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
${{ steps.changelog.outputs.changelog }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ node_modules/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.idea/
|
.idea/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
rs-capi/target/
|
2
rs-capi/Cargo.lock
generated
2
rs-capi/Cargo.lock
generated
@@ -1083,7 +1083,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rs-api"
|
name = "rs-capi"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rs-api"
|
name = "rs-capi"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
26
rs-capi/Dockerfile
Normal file
26
rs-capi/Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
FROM rust:1.81.0 AS builder
|
||||||
|
|
||||||
|
RUN printf "\
|
||||||
|
[source.crates-io] \n\
|
||||||
|
replace-with = 'rsproxy-sparse'\n\
|
||||||
|
\n\
|
||||||
|
[source.rsproxy-sparse]\n\
|
||||||
|
registry = 'sparse+https://rsproxy.cn/index/'\n\
|
||||||
|
" > $CARGO_HOME/config.toml
|
||||||
|
# RUN cargo install crm && crm use rsproxy-sparse
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
|
ADD . /workspace
|
||||||
|
RUN cargo build --bin rs-capi --release
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FROM ubuntu:22.04
|
||||||
|
# RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
# ca-certificates \
|
||||||
|
# && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY --from=builder /workspace/target/release/rs-capi /workspace/rs-capi
|
||||||
|
|
||||||
|
WORKDIR /workspace
|
||||||
|
CMD ["./rs-capi"]
|
@@ -183,7 +183,8 @@ async fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 启动服务器
|
// 启动服务器
|
||||||
let addr = "0.0.0.0:3002";
|
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string());
|
||||||
|
let addr = format!("0.0.0.0:{}", port);
|
||||||
println!("Server running on {}", addr);
|
println!("Server running on {}", addr);
|
||||||
|
|
||||||
// 修改服务器启动代码
|
// 修改服务器启动代码
|
||||||
|
Reference in New Issue
Block a user