104 lines
3.2 KiB
YAML
104 lines
3.2 KiB
YAML
name: "Build & Upload NixOS Proxmox Image"
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*" # triggers on v1.0.0, v1.2.3, etc.
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
name: Build NixOS Base Image
|
|
runs-on: nixos-latest
|
|
env:
|
|
NIXOS_BUILER_HOST: nixos-builder.lab
|
|
NIXOS_BUILER_USER: runner
|
|
PROXMOX_HOST: 192.168.1.205
|
|
PROXMOX_USER: plasmagoat
|
|
TEMPLATE_VMID: 9001
|
|
LATEST_TEMPLATE_VMID: 9000
|
|
|
|
steps:
|
|
- name: Install nodejs
|
|
run: nix-env -iA nixpkgs.nodejs
|
|
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Enable experimental features
|
|
run: |
|
|
mkdir -p ~/.config/nix
|
|
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
|
|
|
|
- name: Prepare SSH
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.RUNNER_SSH_KEY }}" > ~/.ssh/id_rsa
|
|
chmod 600 ~/.ssh/id_rsa
|
|
ssh-keyscan -H $NIXOS_BUILER_HOST >> ~/.ssh/known_hosts
|
|
ssh-keyscan -H $PROXMOX_HOST >> ~/.ssh/known_hosts
|
|
|
|
- name: Test SSH connection
|
|
run: |
|
|
echo "Testing SSH connection to $NIXOS_BUILER_HOST..."
|
|
ssh -o StrictHostKeyChecking=yes $NIXOS_BUILER_USER@$NIXOS_BUILER_HOST "echo 'SSH success. Hostname:' && hostname"
|
|
echo "Testing SSH connection to $PROXMOX_HOST..."
|
|
ssh -o StrictHostKeyChecking=yes $PROXMOX_USER@$PROXMOX_HOST "echo 'SSH success. Hostname:' && hostname"
|
|
|
|
- name: Setup Cachix
|
|
run: |
|
|
nix-env -iA cachix -f https://cachix.org/api/v1/install
|
|
cachix use plasmagoat
|
|
cachix authtoken ${{ secrets.CACHIX_AUTH_TOKEN }}
|
|
|
|
- name: Build NixOS image
|
|
id: build
|
|
run: |
|
|
nix build .#base \
|
|
--builders "ssh://$NIXOS_BUILER_USER@$NIXOS_BUILER_HOST x86_64-linux ~/.ssh/id_rsa 1 1 kvm" \
|
|
--max-jobs 0 \
|
|
--print-out-paths \
|
|
| cachix push plasmagoat
|
|
|
|
echo "image=$(ls result/*.vma.zst | head -n 1)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set VERSION from tag or fallback
|
|
id: version
|
|
run: |
|
|
if [ -n "${CI_COMMIT_TAG}" ]; then
|
|
echo "tag=${CI_COMMIT_TAG}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "tag=dev-$(date +%s)" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Setup Ancible
|
|
run: |
|
|
nix-env -iA nixpkgs.ansible
|
|
|
|
- name: Run Upload Template Runbook
|
|
run: |
|
|
./sripts/run_ancible_ci.sh
|
|
|
|
release:
|
|
name: Release Image
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
if: success()
|
|
|
|
steps:
|
|
- name: Download Artifact
|
|
id: artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: nixos-base-image
|
|
|
|
- name: Create Forgejo Release
|
|
uses: https://code.forgejo.org/sheik/forgejo-release@v2.6.0
|
|
with:
|
|
title: "NixOS Base Image ${{ steps.version.outputs.tag }}"
|
|
prerelease: ${{ github.ref_type == 'tag' }}
|
|
tag: ${{ steps.version.outputs.tag }}
|
|
direction: upload
|
|
release-notes: |
|
|
This release contains the NixOS base image for Proxmox labeled `${{ steps.version.outputs.tag }}`.
|
|
release-dir: "${{ steps.artifact.outputs.download-path }}/nix-support"
|