]> git.ekhem.eu.org Git - metadata.git/commitdiff
[metadata] Configure automatic deployment.
authorJakub Czajka <jakub@ekhem.eu.org>
Sat, 29 Apr 2023 20:06:10 +0000 (22:06 +0200)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:45:06 +0000 (19:45 +0100)
90-git [new file with mode: 0644]
README
metadata.git/deploy.yaml [new file with mode: 0644]
metadata.git/hooks/post-receive [new file with mode: 0755]

diff --git a/90-git b/90-git
new file mode 100644 (file)
index 0000000..97a2054
--- /dev/null
+++ b/90-git
@@ -0,0 +1,4 @@
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+git     ALL=(ALL) NOPASSWD: /usr/bin/ansible-playbook
diff --git a/README b/README
index 7cf21493a77dcd73195dd4c3c2632e7b421524d7..691f2133463124da59e9596ffa2a5c8a7c9d762a 100644 (file)
--- a/README
+++ b/README
@@ -2,3 +2,10 @@ metadata
 ========
 
 Metadata files (descriptions, hooks etc.) for the other git repositories.
+
+Install
+-------
+
+Copy the `post-receive` hook to `metadata.git/hooks` in order for the repository
+to automatically update other repositories. It copies files from this repository
+to `/srv/git` after each commit.
diff --git a/metadata.git/deploy.yaml b/metadata.git/deploy.yaml
new file mode 100644 (file)
index 0000000..9182049
--- /dev/null
@@ -0,0 +1,42 @@
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+- hosts: servers
+  vars:
+    dest: "{{ ansible_local.env.vars.git_home_dir }}"
+    repo: "{{ ansible_local.env.vars.git_home_dir }}/metadata.git"
+  tasks:
+    - name: Checkout metadata's configuration files to the destination directory
+      command: /usr/bin/git --work-tree={{ dest }} --git-dir={{ repo }} \
+        checkout main --force
+      become: true
+    - name: Move 90-git to /etc/sudoers.d
+      command: /usr/bin/mv {{ dest }}/90-git /etc/sudoers.d
+      become: true
+    - name: Set ownership and permissions for /etc/sudoers.d/90-git
+      file:
+        path: /etc/sudoers.d/90-git
+        mode: 0440
+        owner: root
+        group: root
+      become: true
+
+    - name: Install ansible
+      package:
+        name:
+          - ansible
+        state: latest
+      become: true
+    - find:
+        paths: "{{ dest }}"
+        recurse: true
+        patterns: post-receive
+      register: post_receive_scripts
+    - name: Make all post-receive scripts executable and set ownership
+      file:
+        path: "{{ item.path }}"
+        mode: 0744
+        owner: git
+        group: git
+      become: true
+      with_items: "{{ post_receive_scripts.files }}"
diff --git a/metadata.git/hooks/post-receive b/metadata.git/hooks/post-receive
new file mode 100755 (executable)
index 0000000..ac81bdc
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+while read old_revision new_revision branch
+do
+    if [ "${branch}" != "refs/heads/main" ]
+    then
+       echo "${branch} is not the main branch so not deploying."
+       exit 0
+    fi
+    sudo /usr/bin/ansible-playbook --connection=local deploy.yaml
+done