feat(build): use Nix flake, go-task and lefthook
This commit is contained in:
parent
c8e984681d
commit
1c91865705
5 changed files with 154 additions and 60 deletions
60
Makefile
60
Makefile
|
@ -1,60 +0,0 @@
|
|||
# Ansible options
|
||||
ansible_user ?= ephase
|
||||
ansible_roles := deps
|
||||
ansible_options ?= --diff
|
||||
ansible_playbook ?= playbook.yml
|
||||
ansible_req ?= requirements.yml
|
||||
# venv options
|
||||
venv_source ?= .venv
|
||||
venv_cmd := . $(venv_source)/bin/activate
|
||||
|
||||
#Python
|
||||
python_bin ?= python
|
||||
pip_req ?= requirements.txt
|
||||
|
||||
.PHONY: inventory
|
||||
inventory:
|
||||
ansible-inventory --graph -i inventory.ini
|
||||
|
||||
deps: $(ansible_req) $(venv_source)/dep
|
||||
$(shell mkdir -p $(ansible_roles))
|
||||
ifeq ($(wildcard $(ansible_req)),)
|
||||
$(error there is not requirements.yml file in $(ansible_data)!)
|
||||
endif
|
||||
$(venv_cmd) && ansible-galaxy install \
|
||||
--ignore-errors \
|
||||
--roles-path="$(ansible_roles)" \
|
||||
--role-file="$(ansible_req)"
|
||||
|
||||
.PHONY: check-syntax
|
||||
check-syntax: deps
|
||||
$(venv_cmd) && ansible-playbook -i inventory.ini \
|
||||
--syntax-check $(ansible_playbook)
|
||||
|
||||
.PHONY: dry-run
|
||||
dry-run: deps
|
||||
$(venv_cmd) && ansible-playbook -i inventory.ini \
|
||||
--check $(ansible_options) $(ansible_playbook) \
|
||||
-u $(ansible_user)
|
||||
|
||||
.PHONY: run
|
||||
run: deps
|
||||
$(venv_cmd) && ansible-playbook -i inventory.ini \
|
||||
$(ansible_options) $(ansible_playbook) \
|
||||
-u $(ansible_user)
|
||||
|
||||
.PHONY: clean
|
||||
clean: clean-venv
|
||||
[ -d $(ansible_roles) ] && rm -rf $(ansible_roles)
|
||||
|
||||
# venv management
|
||||
$(venv_source):
|
||||
$(python_bin) -m venv $(venv_source)
|
||||
|
||||
$(venv_source)/dep: $(venv_source) $(pip_req)
|
||||
touch $(venv_source)/dep
|
||||
$(venv_cmd) && pip install -r $(pip_req)
|
||||
|
||||
.PHONY: clean-venv
|
||||
clean-venv:
|
||||
[ -d $(venv_source) ] && rm -rf $(venv_source)
|
41
Taskfile.dist.yaml
Normal file
41
Taskfile.dist.yaml
Normal file
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
version: "3"
|
||||
set: [errexit, pipefail, nounset]
|
||||
shopt: [globstar]
|
||||
env:
|
||||
ANSIBLE_OPTIONS: --diff --become-method=doas -K
|
||||
ANSIBLE_PLAYBOOK: playbook.yml
|
||||
ANSIBLE_USER: ephase
|
||||
|
||||
tasks:
|
||||
inventory:
|
||||
cmds:
|
||||
- ansible-inventory --graph -i inventory.ini
|
||||
|
||||
dryrun:
|
||||
deps:
|
||||
- install:deps
|
||||
cmds:
|
||||
- |
|
||||
ansible-playbook -i inventory.ini \
|
||||
--check {{.ANSIBLE_OPTIONS}} {{.ANSIBLE_PLAYBOOK}} \
|
||||
-u {{ .ANSIBLE_USER }}
|
||||
run:
|
||||
deps:
|
||||
- install:deps
|
||||
cmds:
|
||||
- |
|
||||
ansible-playbook -i inventory.ini \
|
||||
{{.ANSIBLE_OPTIONS}} {{.ANSIBLE_PLAYBOOK}} \
|
||||
-u {{.ANSIBLE_USER}}
|
||||
|
||||
install:deps:
|
||||
internal: true
|
||||
cmds:
|
||||
- |
|
||||
ansible-galaxy install \
|
||||
--ignore-errors \
|
||||
--roles-path="deps/" \
|
||||
--role-file="requirements.yml"
|
||||
sources:
|
||||
- requirements.yaml
|
60
flake.lock
generated
Normal file
60
flake.lock
generated
Normal file
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1725103162,
|
||||
"narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-unstable",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"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
|
||||
}
|
32
flake.nix
Normal file
32
flake.nix
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
description = "Devshel for Ansible";
|
||||
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
flake-utils = {
|
||||
url = "github:numtide/flake-utils";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { nixpkgs , flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
in {
|
||||
devShells = {
|
||||
default = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
lefthook
|
||||
go-task
|
||||
convco
|
||||
typos
|
||||
ansible
|
||||
];
|
||||
shellHook = ''
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
21
lefthook.yaml
Normal file
21
lefthook.yaml
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
skip_output: [meta, success]
|
||||
no_tty: true
|
||||
|
||||
commit-msg:
|
||||
commands:
|
||||
lint:convco:
|
||||
run: cat {1} | convco check --from-stdin
|
||||
lint:typos:
|
||||
run: cat {1} | typos -
|
||||
pre-commit:
|
||||
parallel: false
|
||||
commands:
|
||||
lint:typos:staged_files:
|
||||
run: typos {staged_files}
|
||||
pre-push:
|
||||
parallel: false
|
||||
commands:
|
||||
check:nix:
|
||||
tags: check
|
||||
run: nix flake check
|
Loading…
Add table
Add a link
Reference in a new issue