From 656209ee6e49e3c6b49b7fd38709e9bbded27e96 Mon Sep 17 00:00:00 2001 From: "AB from home.homenet" Date: Sun, 26 Oct 2025 17:08:32 +0200 Subject: [PATCH] Drop bad ci --- .github/workflows/rust.yml | 59 ++++++++++++++++++-------------------- Cargo.toml | 2 +- Dockerfile | 41 +++++++++++--------------- 3 files changed, 46 insertions(+), 56 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 98757cd..1fa354b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -5,13 +5,24 @@ on: branches: - 'RUST' +env: + REGISTRY: docker.io + IMAGE_NAME: ultradesu/outfleet + jobs: - docker: - runs-on: self-hosted - needs: test-build + build: + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Extract version from Cargo.toml + id: extract_version + run: | + VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') + echo "cargo_version=$VERSION" >> $GITHUB_OUTPUT + echo "Extracted version: $VERSION" + - name: Set build variables id: vars run: | @@ -19,39 +30,25 @@ jobs: echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT echo "build_date=$(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_OUTPUT echo "branch_name=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT - - - name: Extract version from Cargo.toml - id: extract_version - run: | - VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') - echo "cargo_version=$VERSION" >> $GITHUB_OUTPUT - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Login to Docker Hub + + - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push + + - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . - platforms: linux/amd64,linux/arm64 + file: ./Dockerfile + platforms: linux/amd64 push: true - cache-from: | - type=registry,ref=ultradesu/outfleet:deps-cache - type=registry,ref=ultradesu/outfleet:builder-cache - type=registry,ref=ultradesu/outfleet:rust-buildcache - cache-to: | - type=registry,ref=ultradesu/outfleet:deps-cache,mode=max - type=registry,ref=ultradesu/outfleet:builder-cache,mode=max - type=registry,ref=ultradesu/outfleet:rust-buildcache,mode=max + cache-from: type=gha + cache-to: type=gha,mode=max build-args: | GIT_COMMIT=${{ steps.vars.outputs.sha_full }} GIT_COMMIT_SHORT=${{ steps.vars.outputs.sha_short }} @@ -59,6 +56,6 @@ jobs: BRANCH_NAME=${{ steps.vars.outputs.branch_name }} CARGO_VERSION=${{ steps.extract_version.outputs.cargo_version }} tags: | - ultradesu/outfleet:rs-${{ steps.extract_version.outputs.cargo_version }} - ultradesu/outfleet:rs-${{ steps.extract_version.outputs.cargo_version }}-${{ steps.vars.outputs.sha_short }} - ultradesu/outfleet:rust-latest + ${{ env.IMAGE_NAME }}:rs-${{ steps.extract_version.outputs.cargo_version }} + ${{ env.IMAGE_NAME }}:rs-${{ steps.extract_version.outputs.cargo_version }}-${{ steps.vars.outputs.sha_short }} + ${{ env.IMAGE_NAME }}:rust-latest \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 82d6505..005cbb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xray-admin" -version = "0.1.1" +version = "0.1.3" edition = "2021" [dependencies] diff --git a/Dockerfile b/Dockerfile index 21783a1..3ce6017 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ -# Cargo dependencies stage -FROM rust:1.90-slim AS deps - +# Use cargo-chef for dependency caching +FROM lukemathwalker/cargo-chef:0.1.68-rust-1.90-slim AS chef WORKDIR /app # Install system dependencies needed for building @@ -10,20 +9,13 @@ RUN apt-get update && apt-get install -y \ protobuf-compiler \ && rm -rf /var/lib/apt/lists/* -# Copy only dependency specification files -COPY Cargo.toml Cargo.lock ./ +# Recipe preparation stage +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json -# Create dummy source to build dependencies -RUN mkdir -p src && \ - echo "fn main() {}" > src/main.rs && \ - echo "pub fn lib() {}" > src/lib.rs - -# Build dependencies - this layer will be cached unless Cargo.toml changes -RUN cargo build --release && \ - rm -rf src target/release/deps/xray_admin* target/release/xray-admin* - -# Build stage -FROM deps AS builder +# Dependency building stage +FROM chef AS builder # Build arguments ARG GIT_COMMIT="development" @@ -39,15 +31,16 @@ ENV BUILD_DATE=${BUILD_DATE} ENV BRANCH_NAME=${BRANCH_NAME} ENV CARGO_VERSION=${CARGO_VERSION} -# Copy actual source code -COPY src ./src -COPY static ./static +# Copy recipe and build dependencies (cached layer) +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json -# Build the application (dependencies are already compiled) -RUN cargo build --release +# Copy source and build application +COPY . . +RUN cargo build --release --locked -# Runtime stage - minimal Debian image -FROM debian:bookworm-slim AS runtime +# Runtime stage - minimal Ubuntu image for glibc compatibility +FROM ubuntu:24.04 AS runtime # Build arguments (needed for runtime stage) ARG GIT_COMMIT="development" @@ -89,4 +82,4 @@ USER outfleet EXPOSE 8081 -CMD ["/app/xray-admin", "--host", "0.0.0.0"] +CMD ["/app/xray-admin", "--host", "0.0.0.0"] \ No newline at end of file