-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce87651
commit 47cd01b
Showing
4 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,63 @@ | ||
name: Build Server | ||
name: Backend Server CI | ||
|
||
on: | ||
release: | ||
types: [created] | ||
types: [ created ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
PACKAGE_FILE: ${{ needs.create-nightly-release.outputs.package_prefix }}-${{ matrix.build_name }}.${{ startsWith(matrix.build_name, 'win') && 'zip' || 'tar.gz' }} | ||
CARGO_BUILD_DIR: target | ||
|
||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
rust: | ||
- beta | ||
include: | ||
- build_name: linux-x86_64 | ||
os: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- uses: actions-rs/toolchain@v1 | ||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
profile: minimal | ||
toolchain: ${{ matrix.rust }} | ||
override: true | ||
toolchain: nightly | ||
targets: ${{ matrix.target }} | ||
components: rustfmt, clippy | ||
|
||
- uses: actions-rs/cargo@v1 | ||
- name: Install Linux dependencies | ||
run: | | ||
sudo apt-get update | ||
- name: Cargo build | ||
run: cargo build --release | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
command: build | ||
args: --release --package rust_server --bin rust_server | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- uses: actions-rs/cargo@v1 | ||
- name: Build Image and Push to DockerHub | ||
id: docker_build | ||
uses: docker/build-push-action@v4 | ||
with: | ||
command: test | ||
context: ${{ env.CARGO_BUILD_DIR }} | ||
file: ./Dockerfile | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: | | ||
${{ secrets.DOCKERHUB_USERNAME }}/backend-server:${{ github.ref_name }} | ||
${{ secrets.DOCKERHUB_USERNAME }}/backend-server:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# .GitHub/workflows/release.yml | ||
|
||
name: Backend Docker Image CI | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM rust:latest as build | ||
|
||
# 设置工作路径 | ||
WORKDIR /app | ||
|
||
# 将你的 Rust 项目文件(Cargo.toml 和 src 目录)复制到镜像中 | ||
COPY ./Cargo.toml ./Cargo.toml | ||
COPY ./src ./src | ||
|
||
# 构建 Rust 项目 | ||
RUN cargo build --release | ||
|
||
# 创建最终的生产镜像 | ||
FROM ubuntu:22.04 | ||
|
||
USER root | ||
|
||
# 复制编译好的二进制文件到最终镜像中 | ||
COPY --from=build /app/target/release/BackendServer /home/BackendServer | ||
|
||
# 设置运行命令 | ||
CMD ["./BackendServer"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters