Issues fixed: - Dockerfile was Python/Uvicorn (wrong for Rust project) - Changed to multi-stage Rust build (rust:1.81 → debian:bookworm-slim) - Correct binary name: mem (not mem-cli) - Added proper health check with curl - CI runner labels were incorrect (rust/golang → docker) - Changed test job to: runs-on: docker with rust:1.81-bookworm container - Changed build job to: runs-on: docker - Docker build config was broken - Switched to standard actions (setup-buildx, login, build-push) - Added Cargo caching (registry, git, target) - Added format + clippy checks - Simplified login/build/push flow Ready for CI/CD pipeline restart.
91 lines
2.1 KiB
YAML
91 lines
2.1 KiB
YAML
name: Build and Push
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: forgejo.riotpiao.com
|
|
IMAGE: forgejo.riotpiao.com/rock/poimen-memory
|
|
|
|
jobs:
|
|
test:
|
|
name: Test
|
|
runs-on: docker
|
|
container:
|
|
image: rust:1.81-bookworm
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Cache cargo registry
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cargo/registry
|
|
key: cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
cargo-registry-
|
|
|
|
- name: Cache cargo index
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cargo/git
|
|
key: cargo-git-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
cargo-git-
|
|
|
|
- name: Cache build target
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: target
|
|
key: cargo-target-${{ hashFiles('**/Cargo.lock') }}
|
|
restore-keys: |
|
|
cargo-target-
|
|
|
|
- name: Run tests
|
|
run: cargo test --all --verbose
|
|
|
|
- name: Check formatting
|
|
run: cargo fmt --all -- --check
|
|
|
|
- name: Run clippy
|
|
run: cargo clippy --all -- -D warnings
|
|
|
|
build:
|
|
name: Build and Push Image
|
|
runs-on: docker
|
|
needs: test
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Get short SHA
|
|
id: sha
|
|
run: |
|
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
|
echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Registry login
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: rock
|
|
password: ${{ secrets.REGISTRY_PAT }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE }}:${{ steps.sha.outputs.short_sha }}
|
|
${{ env.IMAGE }}:latest
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|