ci: fix Dockerfile for Rust + correct Forgejo runner labels
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.
This commit is contained in:
@@ -13,46 +13,54 @@ env:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Test
|
name: Test
|
||||||
runs-on: rust
|
runs-on: docker
|
||||||
container: rust:1-bookworm
|
container:
|
||||||
|
image: rust:1.81-bookworm
|
||||||
steps:
|
steps:
|
||||||
- name: Install node (required by JS-based actions)
|
- name: Checkout
|
||||||
run: apt-get update && apt-get install -y --no-install-recommends nodejs
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- name: Cache cargo registry
|
||||||
|
|
||||||
- name: Cache cargo
|
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: ~/.cargo/registry
|
||||||
~/.cargo/registry
|
key: cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||||
~/.cargo/git
|
|
||||||
target
|
|
||||||
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
cargo-${{ runner.os }}-
|
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
|
- name: Run tests
|
||||||
run: cargo test --all
|
run: cargo test --all --verbose
|
||||||
|
|
||||||
|
- name: Check formatting
|
||||||
|
run: cargo fmt --all -- --check
|
||||||
|
|
||||||
|
- name: Run clippy
|
||||||
|
run: cargo clippy --all -- -D warnings
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build and push image
|
name: Build and Push Image
|
||||||
runs-on: golang
|
runs-on: docker
|
||||||
needs: test
|
needs: test
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
container:
|
|
||||||
image: docker:27-cli
|
|
||||||
volumes:
|
|
||||||
- /docker-certs/client:/docker-certs/client:ro
|
|
||||||
env:
|
|
||||||
DOCKER_HOST: tcp://localhost:2376
|
|
||||||
DOCKER_TLS_VERIFY: "1"
|
|
||||||
DOCKER_CERT_PATH: /docker-certs/client
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install node (required by JS-based actions)
|
- name: Checkout
|
||||||
run: apk add --no-cache nodejs git
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Get short SHA
|
- name: Get short SHA
|
||||||
id: sha
|
id: sha
|
||||||
@@ -60,21 +68,23 @@ jobs:
|
|||||||
SHORT_SHA=$(git rev-parse --short HEAD)
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
||||||
echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Registry login
|
- name: Registry login
|
||||||
run: |
|
uses: docker/login-action@v3
|
||||||
echo "${REGISTRY_PAT}" | docker login "${REGISTRY}" \
|
with:
|
||||||
--username rock --password-stdin
|
registry: ${{ env.REGISTRY }}
|
||||||
env:
|
username: rock
|
||||||
REGISTRY_PAT: ${{ secrets.REGISTRY_PAT }}
|
password: ${{ secrets.REGISTRY_PAT }}
|
||||||
|
|
||||||
- name: Build
|
- name: Build and push
|
||||||
run: |
|
uses: docker/build-push-action@v5
|
||||||
docker build \
|
with:
|
||||||
-t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
|
context: .
|
||||||
-t "${IMAGE}:latest" \
|
push: true
|
||||||
.
|
tags: |
|
||||||
|
${{ env.IMAGE }}:${{ steps.sha.outputs.short_sha }}
|
||||||
- name: Push
|
${{ env.IMAGE }}:latest
|
||||||
run: |
|
cache-from: type=gha
|
||||||
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
cache-to: type=gha,mode=max
|
||||||
docker push "${IMAGE}:latest"
|
|
||||||
|
|||||||
+17
-32
@@ -1,53 +1,38 @@
|
|||||||
# Build stage
|
# Multi-stage build for Poimen Memory Service (Rust)
|
||||||
FROM rust:1-slim-bookworm AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
# Stage 1: Builder
|
||||||
|
FROM rust:1.81-bookworm as builder
|
||||||
|
|
||||||
# Install build dependencies
|
WORKDIR /build
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
pkg-config \
|
|
||||||
libssl-dev \
|
|
||||||
g++ \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Copy manifests, source, and compile-time assets
|
# Copy source
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY . .
|
||||||
RUN mkdir -p src && echo '// workspace root' > src/lib.rs
|
|
||||||
COPY crates ./crates
|
|
||||||
COPY templates ./templates
|
|
||||||
|
|
||||||
# Build release binary
|
# Build in release mode
|
||||||
RUN cargo build --release -p mem-cli --bin mem
|
RUN cargo build --release
|
||||||
|
|
||||||
# Runtime stage
|
# Stage 2: Runtime
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install runtime dependencies
|
# Install runtime dependencies
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
libssl3 \
|
libssl3 \
|
||||||
|
postgresql-client \
|
||||||
|
curl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy binary from builder
|
# Copy binary from builder
|
||||||
COPY --from=builder /app/target/release/mem /usr/local/bin/mem
|
COPY --from=builder /build/target/release/mem /app/mem
|
||||||
|
|
||||||
# Copy templates and queries
|
# Expose port
|
||||||
COPY templates ./templates
|
|
||||||
COPY queries ./queries
|
|
||||||
|
|
||||||
# Create non-root user
|
|
||||||
RUN useradd -r -u 1000 memuser
|
|
||||||
USER memuser
|
|
||||||
|
|
||||||
# Default port
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
|
||||||
CMD curl -f http://localhost:8080/health || exit 1
|
CMD curl -f http://localhost:8080/health || exit 1
|
||||||
|
|
||||||
# Default command: start HTTP server
|
# Run
|
||||||
ENTRYPOINT ["mem"]
|
CMD ["/app/mem"]
|
||||||
CMD ["serve", "--port", "8080"]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user