Compare commits

..
2 Commits
Author SHA1 Message Date
asepharyana 5f17748d88 ci: deploy via Attic binary cache (attic.asepharyana.my.id) instead of ssh copy
Deploy LLM API / build-and-deploy (push) Canceled after 0s
Push build result to attic cache directly from runner, then VPS
substitutes it via nix-store --realise. ssh copy retained only as fallback.
2026-08-27 20:38:41 +07:00
asepharyana 3be27c667e ci: add standalone Nix build + deploy workflow; remove parent notify
Deploy LLM API / build-and-deploy (push) Canceled after 0s
Repo is now self-contained: flake.nix (cargo + llama.cpp build) + deploy.yml
(nix build -> nix copy -> nix-env profile -> systemctl restart llm-api).
No longer dispatches submodule-updated to asepharyana-hub.
2026-08-27 19:48:19 +07:00
3 changed files with 186 additions and 25 deletions

No files matched your search

+126
View File
@@ -0,0 +1,126 @@
name: Deploy LLM API
on:
push:
branches: [master]
workflow_dispatch:
concurrency:
group: llm-api-deploy
cancel-in-progress: false
permissions:
contents: read
id-token: write
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
VPS_USER: ${{ secrets.VPS_USER }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v22
with:
determinate: false
extra-conf: |
sandbox = false
accept-flake-config = true
extra-substituters = https://attic.asepharyana.my.id/asepharyana https://attic.asepharyana.my.id/gmw
extra-trusted-public-keys = asepharyana:zBpY6vNI1nDJ4mU6W4q880BB0JB1qb3gRKkO/tGSMiQ= gmw:Fq2Anzuhkb+T/hftWnPcveHSi21/RzIgIOeG8pCJa88=
- name: Cache Nix
uses: DeterminateSystems/magic-nix-cache-action@v14
with:
use-flakehub: false
- name: Build llm-api
id: build
run: |
nix build .#llm-api --impure --option sandbox false --print-build-logs
STORE_PATH=$(readlink result)
echo "store-path=$STORE_PATH" >> "$GITHUB_OUTPUT"
echo "Build OK llm-api: $STORE_PATH"
- name: Push to Attic cache
env:
ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }}
run: |
if [ -z "$ATTIC_TOKEN" ]; then
echo "ATTIC_TOKEN not set; skipping attic push"
exit 0
fi
STORE_PATH="${{ steps.build.outputs.store-path }}"
ATTIC_DIR="/nix/store/fygyy3yk4rqdknxkiwkqambpnhyax0k4-attic-0.1.0"
ATTIC_BIN=""
if command -v attic >/dev/null 2>&1; then
ATTIC_BIN="$(command -v attic)"
elif nix-store --realise "$ATTIC_DIR" 2>/tmp/attic-bootstrap.err; then
echo "✅ Pulled attic client from attic cache (HTTPS substituter)"
ATTIC_BIN="$ATTIC_DIR/bin/attic"
else
echo "attic client unavailable on runner; skipping attic push"
tail -5 /tmp/attic-bootstrap.err 2>/dev/null || true
exit 0
fi
mkdir -p "$HOME/.config/attic"
cat > "$HOME/.config/attic/config.toml" <<EOF
default-server = "pub"
[servers.pub]
endpoint = "https://attic.asepharyana.my.id"
token = "$ATTIC_TOKEN"
EOF
push_ok=""
for attempt in 1 2 3; do
if "$ATTIC_BIN" push pub:asepharyana "$STORE_PATH" --jobs 4 --ignore-upstream-cache-filter; then
echo "✅ Pushed $STORE_PATH to attic directly from runner"
push_ok=1
break
fi
echo "⚠️ Direct attic push attempt $attempt/3 failed; retrying in 10s..."
sleep 10
done
if [ -z "$push_ok" ]; then
echo "Direct attic push failed after 3 attempts; deploy will fall back to ssh copy"
fi
- name: Setup SSH key
env:
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
sed -i 's/\r$//' ~/.ssh/id_ed25519
ssh-keygen -y -f ~/.ssh/id_ed25519 >/dev/null 2>&1 || { echo "SSH key invalid"; exit 1; }
ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts 2>/dev/null
- name: Deploy llm-api to VPS
run: |
STORE_PATH="${{ steps.build.outputs.store-path }}"
echo "=== Realising llm-api: $STORE_PATH (substitute from attic, fallback ssh copy) ==="
if ssh "$VPS_USER@$VPS_HOST" "sudo /nix/var/nix/profiles/default/bin/nix-store --realise '$STORE_PATH'" 2>/dev/null; then
echo "Substituted llm-api from Attic cache"
else
echo "Attic substitute failed; falling back to ssh copy"
nix copy --to "ssh://${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }}" "$STORE_PATH"
fi
echo "=== Updating profile ==="
ssh "$VPS_USER@$VPS_HOST" "sudo /nix/var/nix/profiles/default/bin/nix-env --profile /nix/var/nix/profiles/llm-api --set '$STORE_PATH'"
echo "=== Restarting service ==="
ssh "$VPS_USER@$VPS_HOST" "sudo systemctl restart llm-api && for i in \$(seq 1 15); do state=\$(systemctl is-active llm-api 2>/dev/null || echo inactive); [ \"\$state\" = \"active\" ] && break; sleep 2; done; echo \"final-state=\$state\"; [ \"\$state\" = \"active\" ]"
echo "✅ llm-api deployed"
-25
View File
@@ -1,25 +0,0 @@
name: Notify Parent Repo
on:
push:
branches:
- master
workflow_dispatch:
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: Trigger root monorepo build
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.DISPATCH_TOKEN }}
repository: asepharyana/asepharyana-hub
event-type: submodule-updated
client-payload: |
{
"service": "llm-api",
"ref": "${{ github.ref }}",
"sha": "${{ github.sha }}",
"actor": "${{ github.actor }}"
}
+60
View File
@@ -0,0 +1,60 @@
{
description = "Asepharyana LLM API — Rust llama.cpp model serving (OpenAI-compatible)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
llm-api = pkgs.stdenv.mkDerivation {
name = "llm-api-0.1.0";
src = ./.;
nativeBuildInputs = with pkgs; [
cacert curl gcc gnumake openssl pkg-config python3 libclang
rustc cargo clang cmake zlib
];
buildInputs = with pkgs; [ openssl stdenv.cc.cc.lib ];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
LD_LIBRARY_PATH = "${pkgs.libclang.lib}/lib:${pkgs.stdenv.cc.cc.lib}/lib";
NIX_ENFORCE_PURITY = "0";
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
phases = [ "unpackPhase" "buildPhase" "installPhase" ];
buildPhase = ''
export HOME="$TMPDIR" CARGO_HOME="$TMPDIR/.cargo-llm-api"
echo "=== Building llm-api ==="
cargo build --release 2>&1
'';
installPhase = ''
mkdir -p $out/bin
cp target/release/llm-api $out/bin/llm-api
'';
};
in
{
packages = {
inherit llm-api;
default = llm-api;
};
apps.llm-api = {
type = "app";
program = "${llm-api}/bin/llm-api";
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ rustc cargo clang cmake openssl pkg-config ];
};
});
}