Refactor CI/CD workflow to utilize NixOS VM for testing
Some checks failed
Test Suite / test (push) Failing after 16s
Some checks failed
Test Suite / test (push) Failing after 16s
- Changed the CI workflow to run tests inside a NixOS virtual machine instead of directly on the runner. - Updated the NixOS VM configuration to include necessary dependencies and services for testing. - Added a script to handle test execution within the VM, including setup for Python and Node.js environments. - Implemented SSH access to the VM for remote operations and streamlined the process of starting and stopping the VM during tests. - Enhanced the workflow to build the VM and copy the codebase for testing, ensuring a more isolated and consistent testing environment.
This commit is contained in:
116
nix/test-vm.nix
116
nix/test-vm.nix
@@ -1,12 +1,20 @@
|
||||
# NixOS VM configuration for testing Movie Map
|
||||
# This VM includes PostgreSQL, Radarr, Sonarr, and Lidarr with test data
|
||||
# NixOS VM configuration for testing Movie Map in CI/CD
|
||||
# This VM includes all dependencies needed for testing
|
||||
# Usage: nixos-rebuild build-vm -I nixos-config=./nix/test-vm.nix
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
{
|
||||
# Enable QEMU guest agent for better VM management
|
||||
services.qemuGuest.enable = true;
|
||||
imports = [
|
||||
<nixpkgs/nixos/modules/virtualisation/qemu-vm.nix>
|
||||
];
|
||||
|
||||
# VM-specific configuration
|
||||
virtualisation = {
|
||||
memorySize = 2048; # 2GB RAM
|
||||
cores = 2;
|
||||
graphics = false; # Headless
|
||||
};
|
||||
|
||||
# Networking - allow external access
|
||||
networking = {
|
||||
hostName = "moviemap-test-vm";
|
||||
firewall = {
|
||||
@@ -14,13 +22,23 @@
|
||||
allowedTCPPorts = [
|
||||
8080 # Movie Map backend
|
||||
5432 # PostgreSQL
|
||||
7878 # Radarr
|
||||
8989 # Sonarr
|
||||
8686 # Lidarr
|
||||
22 # SSH
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# Enable SSH for remote access
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
settings = {
|
||||
PermitRootLogin = "yes";
|
||||
PasswordAuthentication = true;
|
||||
};
|
||||
};
|
||||
|
||||
# Set root password for SSH access
|
||||
users.users.root.password = "test";
|
||||
|
||||
# PostgreSQL configuration
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
@@ -40,63 +58,35 @@
|
||||
};
|
||||
};
|
||||
|
||||
# Radarr configuration
|
||||
services.radarr = {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
user = "radarr";
|
||||
group = "radarr";
|
||||
};
|
||||
|
||||
# Sonarr configuration
|
||||
services.sonarr = {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
user = "sonarr";
|
||||
group = "sonarr";
|
||||
};
|
||||
|
||||
# Lidarr configuration
|
||||
services.lidarr = {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
user = "lidarr";
|
||||
group = "lidarr";
|
||||
};
|
||||
|
||||
# Create test API keys for *arr services
|
||||
# These will be set via environment variables in the CI/CD
|
||||
# For now, we'll create a script that generates them
|
||||
systemd.services.setup-arr-services = {
|
||||
description = "Setup *arr services with test API keys";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "radarr.service" "sonarr.service" "lidarr.service" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
script = ''
|
||||
# Wait for services to be ready
|
||||
sleep 10
|
||||
|
||||
# Note: In a real setup, you would configure API keys via the *arr APIs
|
||||
# For testing, we'll use environment variables set by CI/CD
|
||||
echo "Test VM setup complete"
|
||||
'';
|
||||
};
|
||||
|
||||
# Environment variables for test configuration
|
||||
environment.variables = {
|
||||
TEST_RADARR_URL = "http://localhost:7878";
|
||||
TEST_SONARR_URL = "http://localhost:8989";
|
||||
TEST_LIDARR_URL = "http://localhost:8686";
|
||||
};
|
||||
|
||||
# System packages
|
||||
# Python and Node.js for testing
|
||||
environment.systemPackages = with pkgs; [
|
||||
python3
|
||||
python3Packages.pip
|
||||
nodejs_20
|
||||
nodePackages.npm
|
||||
postgresql
|
||||
curl
|
||||
jq
|
||||
postgresql
|
||||
git
|
||||
vim
|
||||
# Testing tools
|
||||
python3Packages.pytest
|
||||
python3Packages.pytest-asyncio
|
||||
python3Packages.pytest-cov
|
||||
python3Packages.httpx
|
||||
];
|
||||
}
|
||||
|
||||
# Create a test user
|
||||
users.users.test = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ "wheel" ];
|
||||
password = "test";
|
||||
openssh.authorizedKeys.keys = [];
|
||||
};
|
||||
|
||||
# Allow passwordless sudo for test user
|
||||
security.sudo.wheelNeedsPassword = false;
|
||||
|
||||
# System configuration
|
||||
system.stateVersion = "23.11";
|
||||
}
|
||||
|
||||
9
nix/vm-config.nix
Normal file
9
nix/vm-config.nix
Normal file
@@ -0,0 +1,9 @@
|
||||
# VM configuration entry point for CI/CD
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
./test-vm.nix
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user