From 37e8cc0f28ca6cf3962bb0c48e29fc3d0000a2d1 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Tue, 8 Aug 2023 17:10:18 +0200 Subject: [PATCH] ci: add flake for local testing --- .gitignore | 3 + flake.lock | 256 ++++++++++++++++++++++++++++++++++ flake.nix | 101 ++++++++++++++ molecule/default/molecule.yml | 2 +- 4 files changed, 361 insertions(+), 1 deletion(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 9bb9649..3f20f38 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ __pycache__/ *.py[cod] *$py.class + +# ---> Flake +.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8b0850d --- /dev/null +++ b/flake.lock @@ -0,0 +1,256 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + }, + "locked": { + "lastModified": 1688380630, + "narHash": "sha256-8ilApWVb1mAi4439zS3iFeIT0ODlbrifm/fegWwgHjA=", + "owner": "numtide", + "repo": "devshell", + "rev": "f9238ec3d75cefbb2b42a44948c4e8fb1ae9a205", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1690933134, + "narHash": "sha256-ab989mN63fQZBFrkk4Q8bYxQCktuHmBIBqUG1jl6/FQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "59cf3f1447cfc75087e7273b04b31e689a8599fb", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "moleculepkgs": { + "locked": { + "lastModified": 1688462842, + "narHash": "sha256-3q/nEOWbS4Nkj0Oma5ORV49m+FWqLzSnrXUHqKiEWnA=", + "owner": "dawidd6", + "repo": "nixpkgs", + "rev": "be22ef957b64f7a6820d1abdc0aade4056c9f51f", + "type": "github" + }, + "original": { + "owner": "dawidd6", + "ref": "molecule", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1677383253, + "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9952d6bc395f5841262b006fbace8dd7e143b634", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1690881714, + "narHash": "sha256-h/nXluEqdiQHs1oSgkOOWF+j8gcJMWhwnZ9PFabN6q0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9e1960bc196baf6881340d53dccb203a951745a2", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1691368598, + "narHash": "sha256-ia7li22keBBbj02tEdqjVeLtc7ZlSBuhUk+7XTUFr14=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5a8e9243812ba528000995b294292d3b5e120947", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1689261696, + "narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "df1eee2aa65052a18121ed4971081576b25d6b5c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_3", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1691397944, + "narHash": "sha256-4fa4bX3kPYKpEssgrFRxRCPVXczidArDeSWaUMSzQAU=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e5588ddffd4c3578547a86ef40ec9a6fbdae2986", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-parts": "flake-parts", + "moleculepkgs": "moleculepkgs", + "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fd32a5b --- /dev/null +++ b/flake.nix @@ -0,0 +1,101 @@ +{ + description = "Description for the project"; + + inputs = { + nixpkgs = { + url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + }; + + devshell = { + url = "github:numtide/devshell"; + }; + + moleculepkgs = { + url = "github:dawidd6/nixpkgs/molecule"; + }; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.pre-commit-hooks.flakeModule + inputs.devshell.flakeModule + ]; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + perSystem = { config, self', inputs', pkgs, system, ... }: + let + molecule-plugins = inputs.moleculepkgs.legacyPackages.${system}.python3Packages.molecule-plugins; + molecule = inputs.moleculepkgs.legacyPackages.${system}.molecule; + + python310 = pkgs.python310.withPackages (p: with p; [ + pytest + pytest-testinfra + molecule + molecule-plugins + ]); + + in + { + pre-commit = { + check = { + enable = true; + }; + + settings = { + hooks = { + later = { + enable = true; + name = "ansible-later"; + description = "Run ansible-later on all files in the project"; + files = "\\.(yml|yaml)$"; + entry = "${pkgs.ansible-later}/bin/ansible-later"; + }; + }; + }; + }; + + devshells = { + default = { + commands = [ + { + name = "later"; + help = "execute later command"; + command = "${pkgs.ansible-later}/bin/ansible-later"; + } + { + name = "doctor"; + help = "execute doctor command"; + command = "${pkgs.ansible-doctor}/bin/ansible-doctor -fv"; + } + { + name = "testing"; + help = "execute molecule command"; + command = "${molecule}/bin/molecule test --scenario-name default"; + } + ]; + + packages = with pkgs; [ + ansible + ansible-doctor + ansible-lint + ansible-later + + molecule + python310 + ]; + }; + }; + }; + }; +} diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index cfd9182..6b71433 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -8,7 +8,7 @@ dependency: ANSIBLE_GALAXY_DISPLAY_PROGRESS: "false" driver: - name: docker + name: containers platforms: - name: mariadb-ubuntu-22