add dynamic node attribute for last apply
so we can check if something has changed in the repo since the last apply
This commit is contained in:
parent
43d26650b0
commit
59fd245a3f
2 changed files with 29 additions and 0 deletions
5
hooks/deploy_commit_hash_to_node.py
Normal file
5
hooks/deploy_commit_hash_to_node.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
def node_apply_end(repo, node, duration, interactive, result, **kwargs):
|
||||
if not node.os in node.OS_FAMILY_UNIX:
|
||||
return
|
||||
|
||||
node.run(f'echo "{repo.revision}" > /var/lib/bundlewrap/last_apply_commit_id')
|
24
nodes/attributes.py
Normal file
24
nodes/attributes.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from bundlewrap.utils.ui import io
|
||||
from bundlewrap.utils.scm import get_rev
|
||||
from bundlewrap.utils.text import red, bold
|
||||
|
||||
@node_attribute
|
||||
def needs_apply(node):
|
||||
if node.dummy:
|
||||
return False
|
||||
|
||||
if node.os not in node.OS_FAMILY_UNIX:
|
||||
return True
|
||||
|
||||
try:
|
||||
applied = node.run(
|
||||
'cat /var/lib/bundlewrap/last_apply_commit_id',
|
||||
may_fail=True,
|
||||
).stdout.decode().strip()
|
||||
|
||||
if not applied or applied != get_rev():
|
||||
return True
|
||||
except Exception as e:
|
||||
io.stderr(f'{red("!!!")} {bold(node.name)} {e!r}')
|
||||
|
||||
return False
|
Loading…
Reference in a new issue