From 0ae4dabe18c2ff0f3775bff31f8ea6a9e471fc3a Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Tue, 2 Jan 2024 13:02:30 +0100 Subject: [PATCH] [metrics] Configure automatic deployment, describe the repository and make it public. --- COPYING | 4 +-- metrics.git/deploy.yaml | 59 ++++++++++++++++++++++++++++++++ metrics.git/description | 1 + metrics.git/git-daemon-export-ok | 0 metrics.git/hooks/post-receive | 13 +++++++ 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 metrics.git/deploy.yaml create mode 100644 metrics.git/description create mode 100644 metrics.git/git-daemon-export-ok create mode 100755 metrics.git/hooks/post-receive diff --git a/COPYING b/COPYING index 123b029..2092834 100644 --- a/COPYING +++ b/COPYING @@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - Copyright (C) 2023 Jakub Czajka + Copyright (C) 2023-2024 Jakub Czajka This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -651,7 +651,7 @@ Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - metadata Copyright (C) 2023 Jakub Czajka + metadata Copyright (C) 2023-2024 Jakub Czajka This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff --git a/metrics.git/deploy.yaml b/metrics.git/deploy.yaml new file mode 100644 index 0000000..082ffbb --- /dev/null +++ b/metrics.git/deploy.yaml @@ -0,0 +1,59 @@ +# Copyright (c) 2024 Jakub Czajka +# License: GPL-3.0 or later. + +- hosts: servers + vars: + dest: "{{ ansible_local.env.vars.prod_dir }}/metrics" + repo: "{{ ansible_local.env.vars.git_home_dir }}/metrics.git" + site: metrics.conf + tasks: + - name: Create destination directory + file: + path: "{{ dest }}" + state: directory + mode: 0775 + owner: git + group: www-data + become: true + - name: Checkout scripts to the destination directory + command: git --work-tree={{ dest }} --git-dir={{ repo }} checkout main \ + --force *.sh + become: true + - find: + paths: "{{ dest }}" + file_type: file + patterns: "*.sh" + register: scripts + - name: Make metrics scripts executable + file: + path: "{{ item.path }}" + mode: 0744 + owner: www-data + group: www-data + become: true + with_items: "{{ scripts.files }}" + + - name: Install fcgiwrap and nginx + package: + name: + - fcgiwrap + - nginx + state: latest + become: true + - name: Checkout site to /etc/nginx/sites-available + command: git --work-tree=/etc/nginx/sites-available --git-dir={{ repo }} \ + checkout main --force {{ site }} + become: true + - name: Enable site in nginx + shell: envsubst < /etc/nginx/sites-available/{{ site }} \ + > /etc/nginx/sites-enabled/{{ site }} + environment: "{{ ansible_local.env.vars }}" + become: true + - name: Restart fcgiwrap and nginx + service: + name: "{{ item }}" + state: restarted + become: true + with_items: + - fcgiwrap + - nginx diff --git a/metrics.git/description b/metrics.git/description new file mode 100644 index 0000000..271b945 --- /dev/null +++ b/metrics.git/description @@ -0,0 +1 @@ +HTTP interface for a database tracking different life metrics. diff --git a/metrics.git/git-daemon-export-ok b/metrics.git/git-daemon-export-ok new file mode 100644 index 0000000..e69de29 diff --git a/metrics.git/hooks/post-receive b/metrics.git/hooks/post-receive new file mode 100755 index 0000000..4b8ca5e --- /dev/null +++ b/metrics.git/hooks/post-receive @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (c) 2024 Jakub Czajka +# 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 ansible-playbook --connection=local deploy.yaml +done -- 2.39.5